Skip to content

Commit

Permalink
Spring clean setup routine
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jan 16, 2024
1 parent f3ee3b9 commit d0df837
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions custom_components/ohme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
return True


async def async_setup_dependencies(hass, config):
async def async_setup_dependencies(hass, entry):
"""Instantiate client and refresh session"""
client = OhmeApiClient(config['email'], config['password'])
client = OhmeApiClient(entry.data['email'], entry.data['password'])
hass.data[DOMAIN][DATA_CLIENT] = client

await client.async_create_session()
Expand All @@ -24,7 +24,7 @@ async def async_setup_dependencies(hass, config):
async def async_update_listener(hass, entry):
"""Handle options flow credentials update."""
# Re-instantiate the API client
await async_setup_dependencies(hass, dict(entry.data))
await async_setup_dependencies(hass, entry)

# Refresh all coordinators for good measure
for coordinator in hass.data[DOMAIN][DATA_COORDINATORS]:
Expand All @@ -34,15 +34,8 @@ async def async_update_listener(hass, entry):
async def async_setup_entry(hass, entry):
"""This is called from the config flow."""
hass.data.setdefault(DOMAIN, {})
config = dict(entry.data)

if entry.options:
config.update(entry.options)

if "email" not in config:
return False

await async_setup_dependencies(hass, config)
await async_setup_dependencies(hass, entry)

coordinators = [
OhmeChargeSessionsCoordinator(hass=hass), # COORDINATOR_CHARGESESSIONS
Expand Down

0 comments on commit d0df837

Please sign in to comment.