From aef69f87f4b46545054d7ea023eb1e5324921670 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Wed, 22 Jun 2022 23:02:34 +0200 Subject: [PATCH] More enums in deCONZ Alarm Control Panel (#73800) --- .../components/deconz/alarm_control_panel.py | 41 ++++++++----------- .../components/deconz/deconz_event.py | 15 +++---- homeassistant/components/deconz/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../deconz/test_alarm_control_panel.py | 37 +++++++---------- tests/components/deconz/test_deconz_event.py | 29 ++++++------- 7 files changed, 52 insertions(+), 76 deletions(-) diff --git a/homeassistant/components/deconz/alarm_control_panel.py b/homeassistant/components/deconz/alarm_control_panel.py index 90c34da0f12..bf0f39b75d0 100644 --- a/homeassistant/components/deconz/alarm_control_panel.py +++ b/homeassistant/components/deconz/alarm_control_panel.py @@ -1,20 +1,11 @@ """Support for deCONZ alarm control panel devices.""" from __future__ import annotations -from pydeconz.interfaces.alarm_systems import ArmAction +from pydeconz.models.alarm_system import AlarmSystemArmAction from pydeconz.models.event import EventType from pydeconz.models.sensor.ancillary_control import ( - ANCILLARY_CONTROL_ARMED_AWAY, - ANCILLARY_CONTROL_ARMED_NIGHT, - ANCILLARY_CONTROL_ARMED_STAY, - ANCILLARY_CONTROL_ARMING_AWAY, - ANCILLARY_CONTROL_ARMING_NIGHT, - ANCILLARY_CONTROL_ARMING_STAY, - ANCILLARY_CONTROL_DISARMED, - ANCILLARY_CONTROL_ENTRY_DELAY, - ANCILLARY_CONTROL_EXIT_DELAY, - ANCILLARY_CONTROL_IN_ALARM, AncillaryControl, + AncillaryControlPanel, ) from homeassistant.components.alarm_control_panel import ( @@ -40,16 +31,16 @@ from .deconz_device import DeconzDevice from .gateway import DeconzGateway, get_gateway_from_config_entry DECONZ_TO_ALARM_STATE = { - ANCILLARY_CONTROL_ARMED_AWAY: STATE_ALARM_ARMED_AWAY, - ANCILLARY_CONTROL_ARMED_NIGHT: STATE_ALARM_ARMED_NIGHT, - ANCILLARY_CONTROL_ARMED_STAY: STATE_ALARM_ARMED_HOME, - ANCILLARY_CONTROL_ARMING_AWAY: STATE_ALARM_ARMING, - ANCILLARY_CONTROL_ARMING_NIGHT: STATE_ALARM_ARMING, - ANCILLARY_CONTROL_ARMING_STAY: STATE_ALARM_ARMING, - ANCILLARY_CONTROL_DISARMED: STATE_ALARM_DISARMED, - ANCILLARY_CONTROL_ENTRY_DELAY: STATE_ALARM_PENDING, - ANCILLARY_CONTROL_EXIT_DELAY: STATE_ALARM_PENDING, - ANCILLARY_CONTROL_IN_ALARM: STATE_ALARM_TRIGGERED, + AncillaryControlPanel.ARMED_AWAY: STATE_ALARM_ARMED_AWAY, + AncillaryControlPanel.ARMED_NIGHT: STATE_ALARM_ARMED_NIGHT, + AncillaryControlPanel.ARMED_STAY: STATE_ALARM_ARMED_HOME, + AncillaryControlPanel.ARMING_AWAY: STATE_ALARM_ARMING, + AncillaryControlPanel.ARMING_NIGHT: STATE_ALARM_ARMING, + AncillaryControlPanel.ARMING_STAY: STATE_ALARM_ARMING, + AncillaryControlPanel.DISARMED: STATE_ALARM_DISARMED, + AncillaryControlPanel.ENTRY_DELAY: STATE_ALARM_PENDING, + AncillaryControlPanel.EXIT_DELAY: STATE_ALARM_PENDING, + AncillaryControlPanel.IN_ALARM: STATE_ALARM_TRIGGERED, } @@ -133,26 +124,26 @@ class DeconzAlarmControlPanel(DeconzDevice, AlarmControlPanelEntity): """Send arm away command.""" if code: await self.gateway.api.alarmsystems.arm( - self.alarm_system_id, ArmAction.AWAY, code + self.alarm_system_id, AlarmSystemArmAction.AWAY, code ) async def async_alarm_arm_home(self, code: str | None = None) -> None: """Send arm home command.""" if code: await self.gateway.api.alarmsystems.arm( - self.alarm_system_id, ArmAction.STAY, code + self.alarm_system_id, AlarmSystemArmAction.STAY, code ) async def async_alarm_arm_night(self, code: str | None = None) -> None: """Send arm night command.""" if code: await self.gateway.api.alarmsystems.arm( - self.alarm_system_id, ArmAction.NIGHT, code + self.alarm_system_id, AlarmSystemArmAction.NIGHT, code ) async def async_alarm_disarm(self, code: str | None = None) -> None: """Send disarm command.""" if code: await self.gateway.api.alarmsystems.arm( - self.alarm_system_id, ArmAction.DISARM, code + self.alarm_system_id, AlarmSystemArmAction.DISARM, code ) diff --git a/homeassistant/components/deconz/deconz_event.py b/homeassistant/components/deconz/deconz_event.py index fa53ef1b5bc..270e66bf91d 100644 --- a/homeassistant/components/deconz/deconz_event.py +++ b/homeassistant/components/deconz/deconz_event.py @@ -6,11 +6,8 @@ from typing import Any from pydeconz.models.event import EventType from pydeconz.models.sensor.ancillary_control import ( - ANCILLARY_CONTROL_EMERGENCY, - ANCILLARY_CONTROL_FIRE, - ANCILLARY_CONTROL_INVALID_CODE, - ANCILLARY_CONTROL_PANIC, AncillaryControl, + AncillaryControlAction, ) from pydeconz.models.sensor.switch import Switch @@ -33,10 +30,10 @@ CONF_DECONZ_EVENT = "deconz_event" CONF_DECONZ_ALARM_EVENT = "deconz_alarm_event" SUPPORTED_DECONZ_ALARM_EVENTS = { - ANCILLARY_CONTROL_EMERGENCY, - ANCILLARY_CONTROL_FIRE, - ANCILLARY_CONTROL_INVALID_CODE, - ANCILLARY_CONTROL_PANIC, + AncillaryControlAction.EMERGENCY, + AncillaryControlAction.FIRE, + AncillaryControlAction.INVALID_CODE, + AncillaryControlAction.PANIC, } @@ -183,7 +180,7 @@ class DeconzAlarmEvent(DeconzEventBase): CONF_ID: self.event_id, CONF_UNIQUE_ID: self.serial, CONF_DEVICE_ID: self.device_id, - CONF_EVENT: self._device.action, + CONF_EVENT: self._device.action.value, } self.gateway.hass.bus.async_fire(CONF_DECONZ_ALARM_EVENT, data) diff --git a/homeassistant/components/deconz/manifest.json b/homeassistant/components/deconz/manifest.json index 2306d088c48..ce10845a5b1 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==93"], + "requirements": ["pydeconz==94"], "ssdp": [ { "manufacturer": "Royal Philips Electronics", diff --git a/requirements_all.txt b/requirements_all.txt index b15f6c885ef..75dd9dfad8a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1441,7 +1441,7 @@ pydaikin==2.7.0 pydanfossair==0.1.0 # homeassistant.components.deconz -pydeconz==93 +pydeconz==94 # homeassistant.components.delijn pydelijn==1.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 9c37efee222..8f523f9e9b7 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -968,7 +968,7 @@ pycoolmasternet-async==0.1.2 pydaikin==2.7.0 # homeassistant.components.deconz -pydeconz==93 +pydeconz==94 # homeassistant.components.dexcom pydexcom==0.2.3 diff --git a/tests/components/deconz/test_alarm_control_panel.py b/tests/components/deconz/test_alarm_control_panel.py index 5c9c192a0aa..213ce3b2e08 100644 --- a/tests/components/deconz/test_alarm_control_panel.py +++ b/tests/components/deconz/test_alarm_control_panel.py @@ -2,19 +2,7 @@ from unittest.mock import patch -from pydeconz.models.sensor.ancillary_control import ( - ANCILLARY_CONTROL_ARMED_AWAY, - ANCILLARY_CONTROL_ARMED_NIGHT, - ANCILLARY_CONTROL_ARMED_STAY, - ANCILLARY_CONTROL_ARMING_AWAY, - ANCILLARY_CONTROL_ARMING_NIGHT, - ANCILLARY_CONTROL_ARMING_STAY, - ANCILLARY_CONTROL_DISARMED, - ANCILLARY_CONTROL_ENTRY_DELAY, - ANCILLARY_CONTROL_EXIT_DELAY, - ANCILLARY_CONTROL_IN_ALARM, - ANCILLARY_CONTROL_NOT_READY, -) +from pydeconz.models.sensor.ancillary_control import AncillaryControlPanel from homeassistant.components.alarm_control_panel import ( DOMAIN as ALARM_CONTROL_PANEL_DOMAIN, @@ -123,7 +111,7 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "0", - "state": {"panel": ANCILLARY_CONTROL_ARMED_AWAY}, + "state": {"panel": AncillaryControlPanel.ARMED_AWAY}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -137,7 +125,7 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "0", - "state": {"panel": ANCILLARY_CONTROL_ARMED_NIGHT}, + "state": {"panel": AncillaryControlPanel.ARMED_NIGHT}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -153,7 +141,7 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "0", - "state": {"panel": ANCILLARY_CONTROL_ARMED_STAY}, + "state": {"panel": AncillaryControlPanel.ARMED_STAY}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -167,7 +155,7 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "0", - "state": {"panel": ANCILLARY_CONTROL_DISARMED}, + "state": {"panel": AncillaryControlPanel.DISARMED}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -177,9 +165,9 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): # Event signals alarm control panel arming for arming_event in { - ANCILLARY_CONTROL_ARMING_AWAY, - ANCILLARY_CONTROL_ARMING_NIGHT, - ANCILLARY_CONTROL_ARMING_STAY, + AncillaryControlPanel.ARMING_AWAY, + AncillaryControlPanel.ARMING_NIGHT, + AncillaryControlPanel.ARMING_STAY, }: event_changed_sensor = { @@ -196,7 +184,10 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): # Event signals alarm control panel pending - for pending_event in {ANCILLARY_CONTROL_ENTRY_DELAY, ANCILLARY_CONTROL_EXIT_DELAY}: + for pending_event in { + AncillaryControlPanel.ENTRY_DELAY, + AncillaryControlPanel.EXIT_DELAY, + }: event_changed_sensor = { "t": "event", @@ -219,7 +210,7 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "0", - "state": {"panel": ANCILLARY_CONTROL_IN_ALARM}, + "state": {"panel": AncillaryControlPanel.IN_ALARM}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -233,7 +224,7 @@ async def test_alarm_control_panel(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "0", - "state": {"panel": ANCILLARY_CONTROL_NOT_READY}, + "state": {"panel": AncillaryControlPanel.NOT_READY}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() diff --git a/tests/components/deconz/test_deconz_event.py b/tests/components/deconz/test_deconz_event.py index e697edd5a9a..c326892aef2 100644 --- a/tests/components/deconz/test_deconz_event.py +++ b/tests/components/deconz/test_deconz_event.py @@ -3,11 +3,8 @@ from unittest.mock import patch from pydeconz.models.sensor.ancillary_control import ( - ANCILLARY_CONTROL_ARMED_AWAY, - ANCILLARY_CONTROL_EMERGENCY, - ANCILLARY_CONTROL_FIRE, - ANCILLARY_CONTROL_INVALID_CODE, - ANCILLARY_CONTROL_PANIC, + AncillaryControlAction, + AncillaryControlPanel, ) from homeassistant.components.deconz.const import DOMAIN as DECONZ_DOMAIN @@ -286,7 +283,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "1", - "state": {"action": ANCILLARY_CONTROL_EMERGENCY}, + "state": {"action": AncillaryControlAction.EMERGENCY}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -300,7 +297,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): CONF_ID: "keypad", CONF_UNIQUE_ID: "00:00:00:00:00:00:00:01", CONF_DEVICE_ID: device.id, - CONF_EVENT: ANCILLARY_CONTROL_EMERGENCY, + CONF_EVENT: AncillaryControlAction.EMERGENCY.value, } # Fire event @@ -310,7 +307,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "1", - "state": {"action": ANCILLARY_CONTROL_FIRE}, + "state": {"action": AncillaryControlAction.FIRE}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -324,7 +321,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): CONF_ID: "keypad", CONF_UNIQUE_ID: "00:00:00:00:00:00:00:01", CONF_DEVICE_ID: device.id, - CONF_EVENT: ANCILLARY_CONTROL_FIRE, + CONF_EVENT: AncillaryControlAction.FIRE.value, } # Invalid code event @@ -334,7 +331,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "1", - "state": {"action": ANCILLARY_CONTROL_INVALID_CODE}, + "state": {"action": AncillaryControlAction.INVALID_CODE}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -348,7 +345,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): CONF_ID: "keypad", CONF_UNIQUE_ID: "00:00:00:00:00:00:00:01", CONF_DEVICE_ID: device.id, - CONF_EVENT: ANCILLARY_CONTROL_INVALID_CODE, + CONF_EVENT: AncillaryControlAction.INVALID_CODE.value, } # Panic event @@ -358,7 +355,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "1", - "state": {"action": ANCILLARY_CONTROL_PANIC}, + "state": {"action": AncillaryControlAction.PANIC}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -372,7 +369,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): CONF_ID: "keypad", CONF_UNIQUE_ID: "00:00:00:00:00:00:00:01", CONF_DEVICE_ID: device.id, - CONF_EVENT: ANCILLARY_CONTROL_PANIC, + CONF_EVENT: AncillaryControlAction.PANIC.value, } # Only care for changes to specific action events @@ -382,7 +379,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "1", - "state": {"action": ANCILLARY_CONTROL_ARMED_AWAY}, + "state": {"action": AncillaryControlAction.ARMED_AWAY}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -396,7 +393,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): "e": "changed", "r": "sensors", "id": "1", - "state": {"panel": ANCILLARY_CONTROL_ARMED_AWAY}, + "state": {"panel": AncillaryControlPanel.ARMED_AWAY}, } await mock_deconz_websocket(data=event_changed_sensor) await hass.async_block_till_done() @@ -415,7 +412,7 @@ async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket): assert len(hass.states.async_all()) == 0 -async def test_deconz_events_bad_unique_id(hass, aioclient_mock, mock_deconz_websocket): +async def test_deconz_events_bad_unique_id(hass, aioclient_mock): """Verify no devices are created if unique id is bad or missing.""" data = { "sensors": {