Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
Fix bug where setup fails if there are only GUI batteries and no config entries
  • Loading branch information
hif2k1 authored Apr 18, 2022
1 parent beb6756 commit 69780ae
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions custom_components/battery_sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@
async def async_setup(hass, config):
hass.data[DATA_UTILITY] = {}

for battery, conf in config.get(DOMAIN).items():
_LOGGER.debug("Setup %s.%s", DOMAIN, battery)
if config.get(DOMAIN)!= None:
for battery, conf in config.get(DOMAIN).items():
_LOGGER.debug("Setup %s.%s", DOMAIN, battery)

hass.data[DATA_UTILITY][battery] = conf
hass.data[DATA_UTILITY][battery] = conf

hass.async_create_task(
discovery.async_load_platform(
hass,
SENSOR_DOMAIN,
DOMAIN,
[{CONF_BATTERY: battery, CONF_NAME: conf.get(CONF_NAME, battery)}],
config,
hass.async_create_task(
discovery.async_load_platform(
hass,
SENSOR_DOMAIN,
DOMAIN,
[{CONF_BATTERY: battery, CONF_NAME: conf.get(CONF_NAME, battery)}],
config,
)
)
)
return True

async def async_setup_entry(hass, entry) -> bool:
Expand All @@ -70,4 +71,4 @@ async def async_setup_entry(hass, entry) -> bool:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
return True
return True

0 comments on commit 69780ae

Please sign in to comment.