From d84890bc5995708b0eb5a9758607becf0cc29dfd Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Sun, 19 May 2024 20:25:12 +0300 Subject: [PATCH] Bump aioshelly to 10.0.0 (#117728) --- homeassistant/components/shelly/__init__.py | 2 +- .../components/shelly/config_flow.py | 2 +- .../components/shelly/coordinator.py | 41 ++++++++----------- homeassistant/components/shelly/manifest.json | 2 +- homeassistant/components/shelly/utils.py | 8 ---- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 7 files changed, 21 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/shelly/__init__.py b/homeassistant/components/shelly/__init__.py index 5c5b97bcbe0..ad03414e0ca 100644 --- a/homeassistant/components/shelly/__init__.py +++ b/homeassistant/components/shelly/__init__.py @@ -328,6 +328,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ShellyConfigEntry) -> b if unload_ok := await hass.config_entries.async_unload_platforms(entry, platforms): if shelly_entry_data.block: - shelly_entry_data.block.shutdown() + await shelly_entry_data.block.shutdown() return unload_ok diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index 912b050a6b7..d8f455562dd 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -122,7 +122,7 @@ async def validate_input( options, ) await block_device.initialize() - block_device.shutdown() + await block_device.shutdown() return { "title": block_device.name, CONF_SLEEP_PERIOD: get_block_device_sleep_period(block_device.settings), diff --git a/homeassistant/components/shelly/coordinator.py b/homeassistant/components/shelly/coordinator.py index 4403817cf12..3f5900b61db 100644 --- a/homeassistant/components/shelly/coordinator.py +++ b/homeassistant/components/shelly/coordinator.py @@ -63,7 +63,6 @@ from .const import ( ) from .utils import ( async_create_issue_unsupported_firmware, - async_shutdown_device, get_block_device_sleep_period, get_device_entry_gen, get_http_port, @@ -115,6 +114,10 @@ class ShellyCoordinatorBase(DataUpdateCoordinator[None], Generic[_DeviceT]): ) entry.async_on_unload(self._debounced_reload.async_shutdown) + entry.async_on_unload( + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop) + ) + @property def model(self) -> str: """Model of the device.""" @@ -151,6 +154,15 @@ class ShellyCoordinatorBase(DataUpdateCoordinator[None], Generic[_DeviceT]): ) self.device_id = device_entry.id + async def shutdown(self) -> None: + """Shutdown the coordinator.""" + await self.device.shutdown() + + async def _handle_ha_stop(self, _event: Event) -> None: + """Handle Home Assistant stopping.""" + LOGGER.debug("Stopping RPC device coordinator for %s", self.name) + await self.shutdown() + async def _async_device_connect_task(self) -> bool: """Connect to a Shelly device task.""" LOGGER.debug("Connecting to Shelly Device - %s", self.name) @@ -206,7 +218,7 @@ class ShellyCoordinatorBase(DataUpdateCoordinator[None], Generic[_DeviceT]): # not running disconnect events since we have auth error # and won't be able to send commands to the device self.last_update_success = False - await async_shutdown_device(self.device) + await self.shutdown() self.entry.async_start_reauth(self.hass) @@ -237,9 +249,6 @@ class ShellyBlockCoordinator(ShellyCoordinatorBase[BlockDevice]): entry.async_on_unload( self.async_add_listener(self._async_device_updates_handler) ) - entry.async_on_unload( - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop) - ) @callback def async_subscribe_input_events( @@ -407,16 +416,6 @@ class ShellyBlockCoordinator(ShellyCoordinatorBase[BlockDevice]): super().async_setup(pending_platforms) self.device.subscribe_updates(self._async_handle_update) - def shutdown(self) -> None: - """Shutdown the coordinator.""" - self.device.shutdown() - - @callback - def _handle_ha_stop(self, _event: Event) -> None: - """Handle Home Assistant stopping.""" - LOGGER.debug("Stopping block device coordinator for %s", self.name) - self.shutdown() - class ShellyRestCoordinator(ShellyCoordinatorBase[BlockDevice]): """Coordinator for a Shelly REST device.""" @@ -473,9 +472,6 @@ class ShellyRpcCoordinator(ShellyCoordinatorBase[RpcDevice]): self._ota_event_listeners: list[Callable[[dict[str, Any]], None]] = [] self._input_event_listeners: list[Callable[[dict[str, Any]], None]] = [] - entry.async_on_unload( - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop) - ) entry.async_on_unload(entry.add_update_listener(self._async_update_listener)) def update_sleep_period(self) -> bool: @@ -705,16 +701,11 @@ class ShellyRpcCoordinator(ShellyCoordinatorBase[RpcDevice]): try: await async_stop_scanner(self.device) except InvalidAuthError: - await self.async_shutdown_device_and_start_reauth() + self.entry.async_start_reauth(self.hass) return - await self.device.shutdown() + await super().shutdown() await self._async_disconnected(False) - async def _handle_ha_stop(self, _event: Event) -> None: - """Handle Home Assistant stopping.""" - LOGGER.debug("Stopping RPC device coordinator for %s", self.name) - await self.shutdown() - class ShellyRpcPollingCoordinator(ShellyCoordinatorBase[RpcDevice]): """Polling coordinator for a Shelly RPC based device.""" diff --git a/homeassistant/components/shelly/manifest.json b/homeassistant/components/shelly/manifest.json index 08971713ced..2e8c2d59c1e 100644 --- a/homeassistant/components/shelly/manifest.json +++ b/homeassistant/components/shelly/manifest.json @@ -9,7 +9,7 @@ "iot_class": "local_push", "loggers": ["aioshelly"], "quality_scale": "platinum", - "requirements": ["aioshelly==9.0.0"], + "requirements": ["aioshelly==10.0.0"], "zeroconf": [ { "type": "_http._tcp.local.", diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index b7cb2f1476a..87c5acc7898 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -482,14 +482,6 @@ def get_http_port(data: MappingProxyType[str, Any]) -> int: return cast(int, data.get(CONF_PORT, DEFAULT_HTTP_PORT)) -async def async_shutdown_device(device: BlockDevice | RpcDevice) -> None: - """Shutdown a Shelly device.""" - if isinstance(device, RpcDevice): - await device.shutdown() - if isinstance(device, BlockDevice): - device.shutdown() - - @callback def async_remove_shelly_rpc_entities( hass: HomeAssistant, domain: str, mac: str, keys: list[str] diff --git a/requirements_all.txt b/requirements_all.txt index 3e48cce9bf9..f0e1e3ee9ab 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -356,7 +356,7 @@ aioruuvigateway==0.1.0 aiosenz==1.0.0 # homeassistant.components.shelly -aioshelly==9.0.0 +aioshelly==10.0.0 # homeassistant.components.skybell aioskybell==22.7.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 92a04761929..68ae1ae38c3 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -329,7 +329,7 @@ aioruuvigateway==0.1.0 aiosenz==1.0.0 # homeassistant.components.shelly -aioshelly==9.0.0 +aioshelly==10.0.0 # homeassistant.components.skybell aioskybell==22.7.0