diff --git a/custom_components/elmo_iess_alarm/binary_sensor.py b/custom_components/elmo_iess_alarm/binary_sensor.py index e2ce5dd..13a2775 100644 --- a/custom_components/elmo_iess_alarm/binary_sensor.py +++ b/custom_components/elmo_iess_alarm/binary_sensor.py @@ -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 @@ -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.""" diff --git a/custom_components/elmo_iess_alarm/manifest.json b/custom_components/elmo_iess_alarm/manifest.json index 487a48d..a012bd8 100644 --- a/custom_components/elmo_iess_alarm/manifest.json +++ b/custom_components/elmo_iess_alarm/manifest.json @@ -15,7 +15,7 @@ "custom_components.elmo_iess_alarm" ], "requirements": [ - "econnect-python==0.6.0" + "econnect-python==0.7.0" ], "version": "1.0.0" } \ No newline at end of file