Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from jacokok/requirements
Browse files Browse the repository at this point in the history
New add_update_listener to update config. Cleaned up more code
  • Loading branch information
jacokok committed May 24, 2021
2 parents 3f7c7e8 + 2d19198 commit 3de9748
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
19 changes: 10 additions & 9 deletions custom_components/warzone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
import logging
from .const import CONF_PASSWORD, CONF_USERNAME, DOMAIN
from .lib import Login

_LOGGER = logging.getLogger(__name__)
from .const import DOMAIN

PLATFORMS = ["sensor"]

Expand All @@ -17,13 +13,18 @@ async def async_setup(hass: HomeAssistant, config: dict):

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up warzone from a config entry."""
hass.data.setdefault(DOMAIN, {})
if hass.data.get(DOMAIN) is None:
hass.data.setdefault(DOMAIN, {})
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
if not entry.update_listeners:
entry.add_update_listener(async_reload_entry)
return True

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok
return unload_ok

async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Reload config entry."""
await hass.config_entries.async_reload(entry.entry_id)
5 changes: 1 addition & 4 deletions custom_components/warzone/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

_LOGGER = logging.getLogger(__name__)

# STEP_USER_DATA_SCHEMA = vol.Schema({CONF_USER: str, CONF_PASSWORD: str, vol.Required(CONF_PLATFORM): vol.In([CONF_PLATFORM_XBOX, CONF_PLATFORM_PLAYSTATION]), CONF_PROFILE: str})
STEP_USER_DATA_SCHEMA = vol.Schema({
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
Expand Down Expand Up @@ -101,9 +100,7 @@ def __init__(self, config_entry):
async def async_step_init(self, user_input=None):
"""Handle the initial step."""
if user_input is not None:
options = {**self._config_entry.options}
options.update(user_input)
return self.async_create_entry(title="", data=options)
return self.async_create_entry(title="", data=user_input)

polling = self._config_entry.options.get(CONF_POLLING_INTERVAL, POLLING_INTERVAL)

Expand Down
1 change: 1 addition & 0 deletions custom_components/warzone/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def async_update_data():
finalResults["level"] = profileResults["level"]
return finalResults
except Exception as exception:
_LOGGER.error("Failed to update warzone", exc_info=1)
raise UpdateFailed(exception)

polling = entry.options.get(CONF_POLLING_INTERVAL, POLLING_INTERVAL)
Expand Down

0 comments on commit 3de9748

Please sign in to comment.