Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup both platforms in one call #184

Closed
wants to merge 1 commit into from
Closed

Conversation

Olen
Copy link
Owner

@Olen Olen commented Jul 15, 2024

Just a small optimization to set up both platforms with one call

@ChristophCaina
Copy link
Contributor

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])

@ChristophCaina
Copy link
Contributor

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:

grafik

grafik

grafik

So the error message itself would be gone :)

#180

@ChristophCaina
Copy link
Contributor

I'Ve applied the changes in my own PR, if you prefer.

@Olen
Copy link
Owner Author

Olen commented Jul 19, 2024

Replaced by #185

@Olen Olen closed this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants