Skip to content

Commit

Permalink
Add support for siren water detector fix icon (#3)
Browse files Browse the repository at this point in the history
* Add support for siren water detector fix icon

* Remove unused import
  • Loading branch information
jbouwh authored Jun 15, 2022
1 parent d855d69 commit 9ce94c5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
3 changes: 3 additions & 0 deletions custom_components/elro_connects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/elro_connects/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
46 changes: 36 additions & 10 deletions custom_components/elro_connects/siren.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
),
}

Expand Down Expand Up @@ -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
)
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/elro_connects/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@
},
"name": "Corner",
},
6: {
"name": "Device with unknown state",
},
}

0 comments on commit 9ce94c5

Please sign in to comment.