From efa7240ac50f1aa1967cc31fd32eb6367a022631 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Fri, 14 Jun 2024 04:27:40 +0300 Subject: [PATCH] Use single list for Shelly non-sleeping platforms (#119540) --- homeassistant/components/shelly/__init__.py | 33 +++++++-------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/shelly/__init__.py b/homeassistant/components/shelly/__init__.py index cc1ea5e81a6..aae0d560810 100644 --- a/homeassistant/components/shelly/__init__.py +++ b/homeassistant/components/shelly/__init__.py @@ -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: