diff --git a/custom_components/elro_connects/__init__.py b/custom_components/elro_connects/__init__.py index a052d85..bf05d74 100644 --- a/custom_components/elro_connects/__init__.py +++ b/custom_components/elro_connects/__init__.py @@ -38,6 +38,9 @@ async def _async_update_data() -> dict[int, dict]: await elro_connects_api.async_update() device_update = copy.deepcopy(elro_connects_api.data) for device_id, device_data in device_update.items(): + if ATTR_DEVICE_STATE not in device_data: + # Skip entries without device state + continue if device_id not in coordinator_update: # new device, or known state coordinator_update[device_id] = device_data diff --git a/custom_components/elro_connects/manifest.json b/custom_components/elro_connects/manifest.json index db361d7..b003af8 100644 --- a/custom_components/elro_connects/manifest.json +++ b/custom_components/elro_connects/manifest.json @@ -4,8 +4,8 @@ "config_flow": true, "documentation": "https://github.com/jbouwh/ha-elro-connects", "issue_tracker": "https://github.com/jbouwh/ha-elro-connects/issues", - "requirements": ["lib-elro-connects==0.4.2"], + "requirements": ["lib-elro-connects==0.4.4"], "codeowners": ["@jbouwh"], "iot_class": "local_polling", - "version": "0.1.3" + "version": "0.1.4" } diff --git a/custom_components/elro_connects/siren.py b/custom_components/elro_connects/siren.py index 86bc04d..f7aaa8a 100644 --- a/custom_components/elro_connects/siren.py +++ b/custom_components/elro_connects/siren.py @@ -1,9 +1,15 @@ """The Elro Connects siren platform.""" from __future__ import annotations +from dataclasses import dataclass import logging -from elro.command import SILENCE_ALARM, TEST_ALARM +from elro.command import ( + SILENCE_ALARM, + TEST_ALARM, + TEST_ALARM_WATER, + CommandAttributes, +) from elro.device import ( ALARM_CO, ALARM_FIRE, @@ -27,38 +33,57 @@ from .const import DOMAIN from .device import ElroConnectsEntity, ElroConnectsK1 + +@dataclass +class ElroSirenEntityDescription(SirenEntityDescription): + """A class that describes elro siren entities.""" + + test_alarm: CommandAttributes | None = None + silence_alarm: CommandAttributes | None = None + + _LOGGER = logging.getLogger(__name__) SIREN_DEVICE_TYPES = { - ALARM_CO: SirenEntityDescription( + ALARM_CO: ElroSirenEntityDescription( key=ALARM_CO, device_class="carbon_monoxide", name="CO Alarm", icon="mdi:molecule-co", + test_alarm=TEST_ALARM, + silence_alarm=SILENCE_ALARM, ), - ALARM_FIRE: SirenEntityDescription( + ALARM_FIRE: ElroSirenEntityDescription( key=ALARM_FIRE, device_class="smoke", name="Fire Alarm", icon="mdi:fire-alert", + test_alarm=TEST_ALARM, + silence_alarm=SILENCE_ALARM, ), - ALARM_HEAT: SirenEntityDescription( + ALARM_HEAT: ElroSirenEntityDescription( key=ALARM_HEAT, device_class="heat", name="Heat Alarm", icon="mdi:fire-alert", + test_alarm=TEST_ALARM, + silence_alarm=SILENCE_ALARM, ), - ALARM_SMOKE: SirenEntityDescription( + ALARM_SMOKE: ElroSirenEntityDescription( key=ALARM_SMOKE, device_class="smoke", name="Smoke Alarm", icon="mdi:smoke", + test_alarm=TEST_ALARM, + silence_alarm=SILENCE_ALARM, ), - ALARM_WATER: SirenEntityDescription( + ALARM_WATER: ElroSirenEntityDescription( key=ALARM_WATER, device_class="moisture", name="Water Alarm", - icon="mid:water-alert", + icon="mdi:water-alert", + test_alarm=TEST_ALARM_WATER, + silence_alarm=SILENCE_ALARM, ), } @@ -94,11 +119,12 @@ def __init__( elro_connects_api: ElroConnectsK1, entry: ConfigEntry, device_id: int, - description: SirenEntityDescription, + description: ElroSirenEntityDescription, ) -> None: """Initialize a Fire Alarm Entity.""" self._device_id = device_id self._elro_connects_api = elro_connects_api + self._description = description self._attr_supported_features = ( SirenEntityFeature.TURN_ON | SirenEntityFeature.TURN_OFF ) @@ -122,7 +148,7 @@ async def async_turn_on(self, **kwargs) -> None: _LOGGER.debug("Sending test alarm request for entity %s", self.entity_id) await self._elro_connects_api.async_connect() await self._elro_connects_api.async_process_command( - TEST_ALARM, device_ID=self._device_id + self._description.test_alarm, device_ID=self._device_id ) self.data[ATTR_DEVICE_STATE] = STATE_TEST_ALARM @@ -133,7 +159,7 @@ async def async_turn_off(self, **kwargs) -> None: _LOGGER.debug("Sending silence alarm request for entity %s", self.entity_id) await self._elro_connects_api.async_connect() await self._elro_connects_api.async_process_command( - SILENCE_ALARM, device_ID=self._device_id + self._description.silence_alarm, device_ID=self._device_id ) self.data[ATTR_DEVICE_STATE] = STATE_SILENCE diff --git a/tests/elro_connects/test_common.py b/tests/elro_connects/test_common.py index 866e441..e32fa80 100644 --- a/tests/elro_connects/test_common.py +++ b/tests/elro_connects/test_common.py @@ -53,4 +53,7 @@ }, "name": "Corner", }, + 6: { + "name": "Device with unknown state", + }, }