Use single list for Shelly non-sleeping platforms (#119540)

This commit is contained in:
Shay Levy 2024-06-14 04:27:40 +03:00 committed by GitHub
parent 87ddb02828
commit efa7240ac5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,9 +54,10 @@ from .utils import (
get_ws_context,
)
BLOCK_PLATFORMS: Final = [
PLATFORMS: Final = [
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.CLIMATE,
Platform.COVER,
Platform.EVENT,
Platform.LIGHT,
@ -72,17 +73,6 @@ BLOCK_SLEEPING_PLATFORMS: Final = [
Platform.SENSOR,
Platform.SWITCH,
]
RPC_PLATFORMS: Final = [
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.CLIMATE,
Platform.COVER,
Platform.EVENT,
Platform.LIGHT,
Platform.SENSOR,
Platform.SWITCH,
Platform.UPDATE,
]
RPC_SLEEPING_PLATFORMS: Final = [
Platform.BINARY_SENSOR,
Platform.SENSOR,
@ -194,7 +184,7 @@ async def _async_setup_block_entry(
shelly_entry_data.block = ShellyBlockCoordinator(hass, entry, device)
shelly_entry_data.block.async_setup()
shelly_entry_data.rest = ShellyRestCoordinator(hass, device, entry)
await hass.config_entries.async_forward_entry_setups(entry, BLOCK_PLATFORMS)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
elif sleep_period is None or device_entry is None:
# Need to get sleep info or first time sleeping device setup, wait for device
LOGGER.debug(
@ -264,7 +254,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ShellyConfigEntry)
shelly_entry_data.rpc = ShellyRpcCoordinator(hass, entry, device)
shelly_entry_data.rpc.async_setup()
shelly_entry_data.rpc_poll = ShellyRpcPollingCoordinator(hass, entry, device)
await hass.config_entries.async_forward_entry_setups(entry, RPC_PLATFORMS)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
elif sleep_period is None or device_entry is None:
# Need to get sleep info or first time sleeping device setup, wait for device
LOGGER.debug(
@ -290,12 +280,12 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ShellyConfigEntry)
async def async_unload_entry(hass: HomeAssistant, entry: ShellyConfigEntry) -> bool:
"""Unload a config entry."""
shelly_entry_data = entry.runtime_data
platforms = RPC_SLEEPING_PLATFORMS
if not entry.data.get(CONF_SLEEP_PERIOD):
platforms = RPC_PLATFORMS
platforms = PLATFORMS
if get_device_entry_gen(entry) in RPC_GENERATIONS:
if entry.data.get(CONF_SLEEP_PERIOD):
platforms = RPC_SLEEPING_PLATFORMS
if unload_ok := await hass.config_entries.async_unload_platforms(
entry, platforms
):
@ -312,11 +302,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ShellyConfigEntry) -> b
hass, DOMAIN, PUSH_UPDATE_ISSUE_ID.format(unique=entry.unique_id)
)
platforms = BLOCK_SLEEPING_PLATFORMS
if not entry.data.get(CONF_SLEEP_PERIOD):
shelly_entry_data.rest = None
platforms = BLOCK_PLATFORMS
if entry.data.get(CONF_SLEEP_PERIOD):
platforms = BLOCK_SLEEPING_PLATFORMS
if unload_ok := await hass.config_entries.async_unload_platforms(entry, platforms):
if shelly_entry_data.block: