From d6d7f3cb3cde9c485e70832978fafed0cb5e7d3d Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Tue, 5 Apr 2022 22:44:04 +0200 Subject: [PATCH] Bump pydeconz to v88 (#69369) --- .../components/deconz/alarm_control_panel.py | 10 +++++----- homeassistant/components/deconz/binary_sensor.py | 12 ++++++------ homeassistant/components/deconz/button.py | 9 ++++----- homeassistant/components/deconz/climate.py | 11 +++++------ homeassistant/components/deconz/config_flow.py | 3 +-- homeassistant/components/deconz/cover.py | 8 ++++---- homeassistant/components/deconz/deconz_device.py | 4 ++-- homeassistant/components/deconz/deconz_event.py | 7 +++++-- homeassistant/components/deconz/fan.py | 8 ++++---- homeassistant/components/deconz/gateway.py | 4 ++-- homeassistant/components/deconz/light.py | 15 ++++++++------- homeassistant/components/deconz/lock.py | 15 ++++++++------- homeassistant/components/deconz/manifest.json | 2 +- homeassistant/components/deconz/number.py | 11 ++++++----- homeassistant/components/deconz/scene.py | 9 ++++----- homeassistant/components/deconz/sensor.py | 14 +++++++------- homeassistant/components/deconz/siren.py | 8 ++++---- homeassistant/components/deconz/switch.py | 10 +++++----- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/deconz/test_binary_sensor.py | 2 +- tests/components/deconz/test_services.py | 2 ++ 22 files changed, 86 insertions(+), 82 deletions(-) diff --git a/homeassistant/components/deconz/alarm_control_panel.py b/homeassistant/components/deconz/alarm_control_panel.py index e16e4bcc327..86d36d3179d 100644 --- a/homeassistant/components/deconz/alarm_control_panel.py +++ b/homeassistant/components/deconz/alarm_control_panel.py @@ -1,8 +1,6 @@ """Support for deCONZ alarm control panel devices.""" from __future__ import annotations -from collections.abc import ValuesView - from pydeconz.alarm_system import AlarmSystem from pydeconz.sensor import ( ANCILLARY_CONTROL_ARMED_AWAY, @@ -81,12 +79,14 @@ async def async_setup_entry( @callback def async_add_alarm_control_panel( - sensors: list[AncillaryControl] - | ValuesView[AncillaryControl] = gateway.api.sensors.values(), + sensors: list[AncillaryControl] | None = None, ) -> None: """Add alarm control panel devices from deCONZ.""" entities = [] + if sensors is None: + sensors = list(gateway.api.sensors.ancillary_control.values()) + for sensor in sensors: if ( @@ -143,7 +143,7 @@ class DeconzAlarmControlPanel(DeconzDevice, AlarmControlPanelEntity): keys = {"panel", "reachable"} if ( self._device.changed_keys.intersection(keys) - and self._device.state in DECONZ_TO_ALARM_STATE + and self._device.panel in DECONZ_TO_ALARM_STATE ): super().async_update_callback() diff --git a/homeassistant/components/deconz/binary_sensor.py b/homeassistant/components/deconz/binary_sensor.py index 1a37236fae4..0e8a73bbc36 100644 --- a/homeassistant/components/deconz/binary_sensor.py +++ b/homeassistant/components/deconz/binary_sensor.py @@ -1,17 +1,17 @@ """Support for deCONZ binary sensors.""" from __future__ import annotations -from collections.abc import Callable, ValuesView +from collections.abc import Callable from dataclasses import dataclass from pydeconz.sensor import ( Alarm, CarbonMonoxide, - DeconzSensor as PydeconzSensor, Fire, GenericFlag, OpenClose, Presence, + SensorBase as PydeconzSensor, Vibration, Water, ) @@ -178,13 +178,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_sensor( - sensors: list[PydeconzSensor] - | ValuesView[PydeconzSensor] = gateway.api.sensors.values(), - ) -> None: + def async_add_sensor(sensors: list[PydeconzSensor] | None = None) -> None: """Add binary sensor from deCONZ.""" entities: list[DeconzBinarySensor] = [] + if sensors is None: + sensors = gateway.api.sensors.values() + for sensor in sensors: if not gateway.option_allow_clip_sensor and sensor.type.startswith("CLIP"): diff --git a/homeassistant/components/deconz/button.py b/homeassistant/components/deconz/button.py index 2ad53d8ad63..cbc64abd5a4 100644 --- a/homeassistant/components/deconz/button.py +++ b/homeassistant/components/deconz/button.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from dataclasses import dataclass from pydeconz.group import Scene as PydeconzScene @@ -58,13 +57,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_scene( - scenes: list[PydeconzScene] - | ValuesView[PydeconzScene] = gateway.api.scenes.values(), - ) -> None: + def async_add_scene(scenes: list[PydeconzScene] | None = None) -> None: """Add scene button from deCONZ.""" entities = [] + if scenes is None: + scenes = list(gateway.api.scenes.values()) + for scene in scenes: known_entities = set(gateway.entities[DOMAIN]) diff --git a/homeassistant/components/deconz/climate.py b/homeassistant/components/deconz/climate.py index 85ab4b17a1e..b706dc5e0b3 100644 --- a/homeassistant/components/deconz/climate.py +++ b/homeassistant/components/deconz/climate.py @@ -1,7 +1,6 @@ """Support for deCONZ climate devices.""" from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.sensor import ( @@ -107,13 +106,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_climate( - sensors: list[Thermostat] - | ValuesView[Thermostat] = gateway.api.sensors.values(), - ) -> None: + def async_add_climate(sensors: list[Thermostat] | None = None) -> None: """Add climate devices from deCONZ.""" entities: list[DeconzThermostat] = [] + if sensors is None: + sensors = list(gateway.api.sensors.thermostat.values()) + for sensor in sensors: if not gateway.option_allow_clip_sensor and sensor.type.startswith("CLIP"): @@ -245,7 +244,7 @@ class DeconzThermostat(DeconzDevice, ClimateEntity): @property def current_temperature(self) -> float: """Return the current temperature.""" - return self._device.temperature # type: ignore[no-any-return] + return self._device.scaled_temperature # type: ignore[no-any-return] @property def target_temperature(self) -> float | None: diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index 109afb6190f..559d9672625 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -30,7 +30,6 @@ from .const import ( CONF_ALLOW_CLIP_SENSOR, CONF_ALLOW_DECONZ_GROUPS, CONF_ALLOW_NEW_DEVICES, - CONF_BRIDGE_ID, DEFAULT_PORT, DOMAIN, HASSIO_CONFIGURATION_URL, @@ -86,7 +85,7 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN): for bridge in self.bridges: if bridge[CONF_HOST] == user_input[CONF_HOST]: - self.bridge_id = cast(str, bridge[CONF_BRIDGE_ID]) + self.bridge_id = cast(str, bridge["id"]) self.deconz_config = { CONF_HOST: bridge[CONF_HOST], CONF_PORT: bridge[CONF_PORT], diff --git a/homeassistant/components/deconz/cover.py b/homeassistant/components/deconz/cover.py index d3696783933..22530cd12d8 100644 --- a/homeassistant/components/deconz/cover.py +++ b/homeassistant/components/deconz/cover.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from typing import Any, cast from pydeconz.light import Cover @@ -47,12 +46,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_cover( - lights: list[Cover] | ValuesView[Cover] = gateway.api.lights.values(), - ) -> None: + def async_add_cover(lights: list[Cover] | None = None) -> None: """Add cover from deCONZ.""" entities = [] + if lights is None: + lights = list(gateway.api.lights.covers.values()) + for light in lights: if ( isinstance(light, Cover) diff --git a/homeassistant/components/deconz/deconz_device.py b/homeassistant/components/deconz/deconz_device.py index f429faf54ad..676116374ec 100644 --- a/homeassistant/components/deconz/deconz_device.py +++ b/homeassistant/components/deconz/deconz_device.py @@ -3,8 +3,8 @@ from __future__ import annotations from pydeconz.group import Group as DeconzGroup, Scene as PydeconzScene -from pydeconz.light import DeconzLight -from pydeconz.sensor import DeconzSensor +from pydeconz.light import LightBase as DeconzLight +from pydeconz.sensor import SensorBase as DeconzSensor from homeassistant.core import callback from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE diff --git a/homeassistant/components/deconz/deconz_event.py b/homeassistant/components/deconz/deconz_event.py index c0b4f763c37..bc6d2b75d51 100644 --- a/homeassistant/components/deconz/deconz_event.py +++ b/homeassistant/components/deconz/deconz_event.py @@ -43,12 +43,15 @@ async def async_setup_events(gateway: DeconzGateway) -> None: @callback def async_add_sensor( - sensors: AncillaryControl | Switch = gateway.api.sensors.values(), + sensors: AncillaryControl | Switch | None = None, ) -> None: """Create DeconzEvent.""" new_events = [] known_events = {event.unique_id for event in gateway.events} + if sensors is None: + sensors = gateway.api.sensors.values() + for sensor in sensors: if not gateway.option_allow_clip_sensor and sensor.type.startswith("CLIP"): @@ -130,7 +133,7 @@ class DeconzEvent(DeconzBase): data = { CONF_ID: self.event_id, CONF_UNIQUE_ID: self.serial, - CONF_EVENT: self._device.state, + CONF_EVENT: self._device.button_event, } if self.device_id: diff --git a/homeassistant/components/deconz/fan.py b/homeassistant/components/deconz/fan.py index 222bf51470f..706ceee73b5 100644 --- a/homeassistant/components/deconz/fan.py +++ b/homeassistant/components/deconz/fan.py @@ -1,7 +1,6 @@ """Support for deCONZ fans.""" from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.light import ( @@ -44,12 +43,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_fan( - lights: list[Fan] | ValuesView[Fan] = gateway.api.lights.values(), - ) -> None: + def async_add_fan(lights: list[Fan] | None = None) -> None: """Add fan from deCONZ.""" entities = [] + if lights is None: + lights = list(gateway.api.lights.fans.values()) + for light in lights: if ( diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 821f3f477ab..aba5c4b4a6d 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -10,8 +10,8 @@ import async_timeout from pydeconz import DeconzSession, errors, group, light, sensor from pydeconz.alarm_system import AlarmSystem as DeconzAlarmSystem from pydeconz.group import Group as DeconzGroup -from pydeconz.light import DeconzLight -from pydeconz.sensor import DeconzSensor +from pydeconz.light import LightBase as DeconzLight +from pydeconz.sensor import SensorBase as DeconzSensor from homeassistant.config_entries import SOURCE_HASSIO, ConfigEntry from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index d9aeec37fb2..513f390ee8d 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.group import Group @@ -62,12 +61,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_light( - lights: list[Light] | ValuesView[Light] = gateway.api.lights.values(), - ) -> None: + def async_add_light(lights: list[Light] | None = None) -> None: """Add light from deCONZ.""" entities = [] + if lights is None: + lights = gateway.api.lights.values() + for light in lights: if ( isinstance(light, Light) @@ -88,15 +88,16 @@ async def async_setup_entry( ) @callback - def async_add_group( - groups: list[Group] | ValuesView[Group] = gateway.api.groups.values(), - ) -> None: + def async_add_group(groups: list[Group] | None = None) -> None: """Add group from deCONZ.""" if not gateway.option_allow_deconz_groups: return entities = [] + if groups is None: + groups = list(gateway.api.groups.values()) + for group in groups: if not group.lights: continue diff --git a/homeassistant/components/deconz/lock.py b/homeassistant/components/deconz/lock.py index 7bdae3e36ed..397a600032f 100644 --- a/homeassistant/components/deconz/lock.py +++ b/homeassistant/components/deconz/lock.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.light import Lock @@ -28,12 +27,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_lock_from_light( - lights: list[Lock] | ValuesView[Lock] = gateway.api.lights.values(), - ) -> None: + def async_add_lock_from_light(lights: list[Lock] | None = None) -> None: """Add lock from deCONZ.""" entities = [] + if lights is None: + lights = list(gateway.api.lights.locks.values()) + for light in lights: if ( @@ -54,12 +54,13 @@ async def async_setup_entry( ) @callback - def async_add_lock_from_sensor( - sensors: list[DoorLock] | ValuesView[DoorLock] = gateway.api.sensors.values(), - ) -> None: + def async_add_lock_from_sensor(sensors: list[DoorLock] | None = None) -> None: """Add lock from deCONZ.""" entities = [] + if sensors is None: + sensors = list(gateway.api.sensors.door_lock.values()) + for sensor in sensors: if ( diff --git a/homeassistant/components/deconz/manifest.json b/homeassistant/components/deconz/manifest.json index 8ca9b93dbe8..6f5d8e369b5 100644 --- a/homeassistant/components/deconz/manifest.json +++ b/homeassistant/components/deconz/manifest.json @@ -3,7 +3,7 @@ "name": "deCONZ", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/deconz", - "requirements": ["pydeconz==87"], + "requirements": ["pydeconz==88"], "ssdp": [ { "manufacturer": "Royal Philips Electronics" diff --git a/homeassistant/components/deconz/number.py b/homeassistant/components/deconz/number.py index 532cb92ebdf..692622b8768 100644 --- a/homeassistant/components/deconz/number.py +++ b/homeassistant/components/deconz/number.py @@ -2,10 +2,10 @@ from __future__ import annotations -from collections.abc import Callable, ValuesView +from collections.abc import Callable from dataclasses import dataclass -from pydeconz.sensor import PRESENCE_DELAY, DeconzSensor as PydeconzSensor, Presence +from pydeconz.sensor import PRESENCE_DELAY, Presence, SensorBase as PydeconzSensor from homeassistant.components.number import ( DOMAIN, @@ -62,12 +62,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_sensor( - sensors: list[Presence] | ValuesView[Presence] = gateway.api.sensors.values(), - ) -> None: + def async_add_sensor(sensors: list[Presence] | None = None) -> None: """Add number config sensor from deCONZ.""" entities = [] + if sensors is None: + sensors = list(gateway.api.sensors.presence.values()) + for sensor in sensors: if sensor.type.startswith("CLIP"): diff --git a/homeassistant/components/deconz/scene.py b/homeassistant/components/deconz/scene.py index c188d7faffa..2ad579cef7d 100644 --- a/homeassistant/components/deconz/scene.py +++ b/homeassistant/components/deconz/scene.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.group import Scene as PydeconzScene @@ -27,13 +26,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_scene( - scenes: list[PydeconzScene] - | ValuesView[PydeconzScene] = gateway.api.scenes.values(), - ) -> None: + def async_add_scene(scenes: list[PydeconzScene] | None = None) -> None: """Add scene from deCONZ.""" entities = [] + if scenes is None: + scenes = list(gateway.api.scenes.values()) + for scene in scenes: known_entities = set(gateway.entities[DOMAIN]) diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index 95db9625139..e9e71429c22 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -1,7 +1,7 @@ """Support for deCONZ sensors.""" from __future__ import annotations -from collections.abc import Callable, ValuesView +from collections.abc import Callable from dataclasses import dataclass from datetime import datetime @@ -9,12 +9,12 @@ from pydeconz.sensor import ( AirQuality, Consumption, Daylight, - DeconzSensor as PydeconzSensor, GenericStatus, Humidity, LightLevel, Power, Pressure, + SensorBase as PydeconzSensor, Switch, Temperature, Time, @@ -174,7 +174,7 @@ ENTITY_DESCRIPTIONS = { Temperature: [ DeconzSensorDescription( key="temperature", - value_fn=lambda device: device.temperature, # type: ignore[no-any-return] + value_fn=lambda device: device.scaled_temperature, # type: ignore[no-any-return] update_key="temperature", device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, @@ -227,10 +227,7 @@ async def async_setup_entry( battery_handler = DeconzBatteryHandler(gateway) @callback - def async_add_sensor( - sensors: list[PydeconzSensor] - | ValuesView[PydeconzSensor] = gateway.api.sensors.values(), - ) -> None: + def async_add_sensor(sensors: list[PydeconzSensor] | None = None) -> None: """Add sensors from deCONZ. Create DeconzBattery if sensor has a battery attribute. @@ -238,6 +235,9 @@ async def async_setup_entry( """ entities: list[DeconzSensor] = [] + if sensors is None: + sensors = gateway.api.sensors.values() + for sensor in sensors: if not gateway.option_allow_clip_sensor and sensor.type.startswith("CLIP"): diff --git a/homeassistant/components/deconz/siren.py b/homeassistant/components/deconz/siren.py index 7f0f6cc39ed..17ce8528f18 100644 --- a/homeassistant/components/deconz/siren.py +++ b/homeassistant/components/deconz/siren.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.light import Siren @@ -34,12 +33,13 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @callback - def async_add_siren( - lights: list[Siren] | ValuesView[Siren] = gateway.api.lights.values(), - ) -> None: + def async_add_siren(lights: list[Siren] | None = None) -> None: """Add siren from deCONZ.""" entities = [] + if lights is None: + lights = list(gateway.api.lights.sirens.values()) + for light in lights: if ( diff --git a/homeassistant/components/deconz/switch.py b/homeassistant/components/deconz/switch.py index ab4577a427c..ad8621f762d 100644 --- a/homeassistant/components/deconz/switch.py +++ b/homeassistant/components/deconz/switch.py @@ -2,7 +2,6 @@ from __future__ import annotations -from collections.abc import ValuesView from typing import Any from pydeconz.light import Light, Siren @@ -34,7 +33,7 @@ async def async_setup_entry( entity_registry = er.async_get(hass) # Siren platform replacing sirens in switch platform added in 2021.10 - for light in gateway.api.lights.values(): + for light in gateway.api.lights.sirens.values(): if isinstance(light, Siren) and ( entity_id := entity_registry.async_get_entity_id( DOMAIN, DECONZ_DOMAIN, light.unique_id @@ -43,12 +42,13 @@ async def async_setup_entry( entity_registry.async_remove(entity_id) @callback - def async_add_switch( - lights: list[Light] | ValuesView[Light] = gateway.api.lights.values(), - ) -> None: + def async_add_switch(lights: list[Light] | None = None) -> None: """Add switch from deCONZ.""" entities = [] + if lights is None: + lights = list(gateway.api.lights.lights.values()) + for light in lights: if ( diff --git a/requirements_all.txt b/requirements_all.txt index a438e64da11..65b43070921 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1423,7 +1423,7 @@ pydaikin==2.7.0 pydanfossair==0.1.0 # homeassistant.components.deconz -pydeconz==87 +pydeconz==88 # homeassistant.components.delijn pydelijn==1.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index aeeeb5dab36..8486ad98325 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -944,7 +944,7 @@ pycoolmasternet-async==0.1.2 pydaikin==2.7.0 # homeassistant.components.deconz -pydeconz==87 +pydeconz==88 # homeassistant.components.dexcom pydexcom==0.2.3 diff --git a/tests/components/deconz/test_binary_sensor.py b/tests/components/deconz/test_binary_sensor.py index 0bd308caeed..8d3eb105896 100644 --- a/tests/components/deconz/test_binary_sensor.py +++ b/tests/components/deconz/test_binary_sensor.py @@ -675,7 +675,7 @@ async def test_add_new_binary_sensor_ignored( ) aioclient_mock.clear_requests() - data = {"groups": {}, "lights": {}, "sensors": {"1": sensor}} + data = {"config": {}, "groups": {}, "lights": {}, "sensors": {"1": sensor}} mock_deconz_request(aioclient_mock, config_entry.data, data) await hass.services.async_call(DECONZ_DOMAIN, SERVICE_DEVICE_REFRESH) diff --git a/tests/components/deconz/test_services.py b/tests/components/deconz/test_services.py index 086da5e24c4..bf7897c0e96 100644 --- a/tests/components/deconz/test_services.py +++ b/tests/components/deconz/test_services.py @@ -217,6 +217,7 @@ async def test_service_refresh_devices(hass, aioclient_mock): aioclient_mock.clear_requests() data = { + "config": {}, "groups": { "1": { "id": "Group 1 id", @@ -280,6 +281,7 @@ async def test_service_refresh_devices_trigger_no_state_update(hass, aioclient_m aioclient_mock.clear_requests() data = { + "config": {}, "groups": { "1": { "id": "Group 1 id",