Skip to content

Commit

Permalink
draft: first implementation of alarm system alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem committed Sep 12, 2023
1 parent 9f7fea2 commit 48fbafb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion custom_components/elmo_iess_alarm/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Module for e-connect binary sensors (sectors and inputs)."""
from elmo import query
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -35,9 +38,60 @@ async def async_setup_entry(
unique_id = f"{entry.entry_id}_{DOMAIN}_{query.INPUTS}_{sensor_id}"
sensors.append(EconnectDoorWindowSensor(coordinator, device, unique_id, sensor_id, query.INPUTS, name))

# Retrieve alarm system global status
alerts = await hass.async_add_executor_job(device._connection.get_status)
for name, value in alerts.items():
unique_id = f"{entry.entry_id}_{name}"
sensors.append(EconnectAlertSensor(coordinator, unique_id, name, value))

async_add_entities(sensors)


class EconnectAlertSensor(CoordinatorEntity, BinarySensorEntity):
"""Representation of a e-Connect alerts."""

def __init__(
self,
coordinator: DataUpdateCoordinator,
unique_id: str,
name: str,
value: int,
) -> None:
"""Construct."""
super().__init__(coordinator)
self._unique_id = unique_id
self._name = name
self._value = value

@property
def unique_id(self) -> str:
"""Return the unique identifier."""
return self._unique_id

@property
def name(self) -> str:
"""Return the name of this entity."""
return self._name

@property
def icon(self) -> str:
"""Return the icon used by this entity."""
return "hass:alarm-light"

@property
def device_class(self) -> str:
"""Return the device class."""
return BinarySensorDeviceClass.PROBLEM

@property
def is_on(self) -> bool:
"""Return the sensor status (on/off)."""
if self._name == "anomalies_led":
return self._value > 1

return self._value > 0


class EconnectDoorWindowSensor(CoordinatorEntity, BinarySensorEntity):
"""Representation of a e-connect door window sensor."""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/elmo_iess_alarm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"custom_components.elmo_iess_alarm"
],
"requirements": [
"econnect-python==0.6.0"
"econnect-python==0.7.0"
],
"version": "1.0.0"
}

0 comments on commit 48fbafb

Please sign in to comment.