Bump switchbot-api to 1.2.1 (#101664)

SwitchBot Cloud: Dependency version up
This commit is contained in:
Ravaka Razafimanantsoa 2023-10-09 18:15:59 +09:00 committed by GitHub
parent 1f122eb688
commit 7b78cfc090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 12 deletions

View file

@ -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

View file

@ -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"]
}

View file

@ -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

View file

@ -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