Skip to content

Commit

Permalink
use 'async_forward_entry_setups' & 'async_unload_platforms'
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jul 4, 2024
1 parent 309fbf8 commit 83ce98e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
14 changes: 2 additions & 12 deletions custom_components/senec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
service = SenecService.SenecService(hass, config_entry, coordinator)
hass.services.async_register(DOMAIN, SERVICE_SET_PEAKSHAVING, service.set_peakshaving)

for platform in PLATFORMS:
hass.async_create_task(hass.config_entries.async_forward_entry_setup(config_entry, platform))
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)

if config_entry.state != ConfigEntryState.LOADED:
config_entry.add_update_listener(async_reload_entry)
Expand Down Expand Up @@ -422,16 +421,7 @@ async def _async_set_string_value(self, set_str_key, value: str):

async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Unload Senec config entry."""
# unload_ok = True
# for platform in PLATFORMS:
# _LOGGER.warning(f"unloading... {platform}")
# ret_val = await hass.config_entries.async_forward_entry_unload(config_entry, platform)
# _LOGGER.warning(f"unload {platform} DONE! {ret_val}")

unload_ok = all(await asyncio.gather(*[
hass.config_entries.async_forward_entry_unload(config_entry, platform)
for platform in PLATFORMS
]))
unload_ok = await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)

if unload_ok:
if DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN]:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/senec/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-senec-v3/issues",
"requirements": ["xmltodict>=0.12.0", "packaging>=21.0", "python-dateutil>=2.8.0"],
"version": "2024.6.2"
"version": "2024.7.0"
}
7 changes: 7 additions & 0 deletions custom_components/senec/pysenec_ha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,13 @@ async def app_get_master_plant_id(self, retry: bool = True):
if self._master_plant_number == -1:
self._master_plant_number = 0
idx = int(self._master_plant_number)

# when SENEC API only return a single system in the 'v1/senec/anlagen' request (even if
# there are multiple systems)...
if len(data) == 1 and idx > 0:
_LOGGER.debug(f"APP-API IGNORE requested 'master_plant_number' {idx} will use 0 instead!")
idx = 0

if len(data) > idx:
if "id" in data[idx]:
self._app_master_plant_id = data[idx]["id"]
Expand Down

0 comments on commit 83ce98e

Please sign in to comment.