Skip to content

Commit

Permalink
Merge pull request #185 from ChristophCaina/master
Browse files Browse the repository at this point in the history
Fix reload-error and load both platforms in one go
  • Loading branch information
Olen authored Jul 19, 2024
2 parents c61e90e + 6150c6a commit 4ce1c88
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions custom_components/plant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
Platform,
ATTR_ENTITY_PICTURE,
ATTR_ICON,
ATTR_NAME,
Expand Down Expand Up @@ -72,7 +73,7 @@
from .plant_helpers import PlantHelper

_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.NUMBER, Platform.SENSOR]

# Use this during testing to generate some dummy-sensors
# to provide random readings for temperature, moisture etc.
Expand Down Expand Up @@ -139,8 +140,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
plant = PlantDevice(hass, entry)
hass.data[DOMAIN][entry.entry_id][ATTR_PLANT] = plant

await hass.config_entries.async_forward_entry_setups(entry, ["number"])
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"])
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

plant_entities = [
plant,
Expand Down Expand Up @@ -258,21 +258,21 @@ async def _plant_add_to_device_registry(

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
await hass.config_entries.async_forward_entry_unload(entry, "sensor")
await hass.config_entries.async_forward_entry_unload(entry, "number")

hass.data[DOMAIN].pop(entry.entry_id)
hass.data[DATA_UTILITY].pop(entry.entry_id)
_LOGGER.info(hass.data[DOMAIN])
for entry_id in list(hass.data[DOMAIN].keys()):
if len(hass.data[DOMAIN][entry_id]) == 0:
_LOGGER.info("Removing entry %s", entry_id)
del hass.data[DOMAIN][entry_id]
if len(hass.data[DOMAIN]) == 0:
_LOGGER.info("Removing domain %s", DOMAIN)
hass.services.async_remove(DOMAIN, SERVICE_REPLACE_SENSOR)
del hass.data[DOMAIN]
return True
unload_ok = await hass.config_entries.async_forward_entry_unload(entry, PLATFORMS)

if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
hass.data[DATA_UTILITY].pop(entry.entry_id)
_LOGGER.info(hass.data[DOMAIN])
for entry_id in list(hass.data[DOMAIN].keys()):
if len(hass.data[DOMAIN][entry_id]) == 0:
_LOGGER.info("Removing entry %s", entry_id)
del hass.data[DOMAIN][entry_id]
if len(hass.data[DOMAIN]) == 0:
_LOGGER.info("Removing domain %s", DOMAIN)
hass.services.async_remove(DOMAIN, SERVICE_REPLACE_SENSOR)
del hass.data[DOMAIN]
return unload_ok


@websocket_api.websocket_command(
Expand Down

0 comments on commit 4ce1c88

Please sign in to comment.