Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jun 23, 2024
1 parent 66b048f commit 7ef5718
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions custom_components/tibber_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,22 @@ async def async_setup(hass: HomeAssistant, config: dict):


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
if DOMAIN not in hass.data:
value = "UNKOWN"
hass.data.setdefault(DOMAIN, {"manifest_version": value})

global SCAN_INTERVAL
SCAN_INTERVAL = timedelta(seconds=config_entry.options.get(CONF_SCAN_INTERVAL,
config_entry.data.get(CONF_SCAN_INTERVAL,
DEFAULT_SCAN_INTERVAL)))

_LOGGER.info(f"Starting TibberLocal with interval: {SCAN_INTERVAL} - ConfigEntry: {mask_map(dict(config_entry.as_dict()))}")
session = async_get_clientsession(hass)

coordinator = TibberLocalDataUpdateCoordinator(hass, session, config_entry)
await coordinator.init_on_load()
if DOMAIN not in hass.data:
value = "UNKOWN"
hass.data.setdefault(DOMAIN, {"manifest_version": value})

coordinator = TibberLocalDataUpdateCoordinator(hass, config_entry)
if not coordinator.last_update_success:
raise ConfigEntryNotReady
else:
await coordinator.init_on_load()

hass.data[DOMAIN][config_entry.entry_id] = coordinator

Expand All @@ -87,7 +86,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):


class TibberLocalDataUpdateCoordinator(DataUpdateCoordinator):
def __init__(self, hass: HomeAssistant, session, config_entry):
def __init__(self, hass: HomeAssistant, config_entry):
self._host = config_entry.options.get(CONF_HOST, config_entry.data[CONF_HOST])
the_pwd = config_entry.options.get(CONF_PASSWORD, config_entry.data[CONF_PASSWORD])

Expand All @@ -101,7 +100,7 @@ def __init__(self, hass: HomeAssistant, session, config_entry):
# initial configuration phase - so we read it from the config_entry.data ONLY!
com_mode = int(config_entry.data.get(CONF_MODE, MODE_3_SML_1_04))

self.bridge = TibberLocalBridge(host=self._host, pwd=the_pwd, websession=session, node_num=node_num,
self.bridge = TibberLocalBridge(host=self._host, pwd=the_pwd, websession=async_get_clientsession(hass), node_num=node_num,
com_mode=com_mode, options={"ignore_parse_errors": ignore_parse_errors})
self.name = config_entry.title
self._config_entry = config_entry
Expand Down

0 comments on commit 7ef5718

Please sign in to comment.