diff --git a/homeassistant/components/switchbot_cloud/__init__.py b/homeassistant/components/switchbot_cloud/__init__.py index cf711fcc431..c34348137e7 100644 --- a/homeassistant/components/switchbot_cloud/__init__.py +++ b/homeassistant/components/switchbot_cloud/__init__.py @@ -32,6 +32,18 @@ class SwitchbotCloudData: devices: SwitchbotDevices +def prepare_device( + hass: HomeAssistant, + api: SwitchBotAPI, + device: Device | Remote, + coordinators: list[SwitchBotCoordinator], +) -> tuple[Device | Remote, SwitchBotCoordinator]: + """Instantiate coordinator and adds to list for gathering.""" + coordinator = SwitchBotCoordinator(hass, api, device) + coordinators.append(coordinator) + return (device, coordinator) + + async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: """Set up SwitchBot via API from a config entry.""" token = config.data[CONF_API_TOKEN] @@ -48,16 +60,14 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: except CannotConnect as ex: raise ConfigEntryNotReady from ex _LOGGER.debug("Devices: %s", devices) - devices_and_coordinators = [ - (device, SwitchBotCoordinator(hass, api, device)) for device in devices - ] + coordinators: list[SwitchBotCoordinator] = [] hass.data.setdefault(DOMAIN, {}) data = SwitchbotCloudData( api=api, devices=SwitchbotDevices( switches=[ - (device, coordinator) - for device, coordinator in devices_and_coordinators + prepare_device(hass, api, device, coordinators) + for device in devices if isinstance(device, Device) and device.device_type.startswith("Plug") or isinstance(device, Remote) @@ -65,11 +75,10 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: ), ) hass.data[DOMAIN][config.entry_id] = data - _LOGGER.debug("Switches: %s", data.devices.switches) + for device_type, devices in vars(data.devices).items(): + _LOGGER.debug("%s: %s", device_type, devices) await hass.config_entries.async_forward_entry_setups(config, PLATFORMS) - await gather( - *[coordinator.async_refresh() for _, coordinator in devices_and_coordinators] - ) + await gather(*[coordinator.async_refresh() for coordinator in coordinators]) return True diff --git a/homeassistant/components/switchbot_cloud/manifest.json b/homeassistant/components/switchbot_cloud/manifest.json index 0451217ca5f..9a4e4fbe196 100644 --- a/homeassistant/components/switchbot_cloud/manifest.json +++ b/homeassistant/components/switchbot_cloud/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/switchbot_cloud", "iot_class": "cloud_polling", "loggers": ["switchbot-api"], - "requirements": ["switchbot-api==1.1.0"] + "requirements": ["switchbot-api==1.2.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index a47eec01b86..e130adfe58d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2517,7 +2517,7 @@ surepy==0.8.0 swisshydrodata==0.1.0 # homeassistant.components.switchbot_cloud -switchbot-api==1.1.0 +switchbot-api==1.2.1 # homeassistant.components.synology_srm synology-srm==0.2.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d99e6c2d8f2..3ed5cec5beb 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1874,7 +1874,7 @@ sunwatcher==0.2.1 surepy==0.8.0 # homeassistant.components.switchbot_cloud -switchbot-api==1.1.0 +switchbot-api==1.2.1 # homeassistant.components.system_bridge systembridgeconnector==3.8.4