Closed Olen closed 4 months ago
Hi, I would consider to implement the following:
from homeassistant.const import (
Platform,
ATTR_ENTITY_PICTURE,
ATTR_ICON,
ATTR_NAME,
ATTR_UNIT_OF_MEASUREMENT,
STATE_OK,
STATE_PROBLEM,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
then
_LOGGER = logging.getLogger(__name__)
PLATFORMS = [Platform.SENSOR, Platform.NUMBER]
and
await hass.config_entries.async_forward_entry_setups(entry, [PLATFORMS])
for the Unload, maybe something like this:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
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
This would result in the following, when the Unload will be tried:
So the error message itself would be gone :)
I'Ve applied the changes in my own PR, if you prefer.
Replaced by #185
Just a small optimization to set up both platforms with one call