Skip to content

Commit

Permalink
feat: add system global states to monitor the central unit (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem authored Oct 1, 2023
2 parents 12dac17 + 268dcf7 commit 64531ef
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 43 deletions.
58 changes: 57 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 @@ -36,9 +39,62 @@ async def async_setup_entry(
unique_id = f"{entry.entry_id}_{DOMAIN}_{query.INPUTS}_{sensor_id}"
sensors.append(EconnectDoorWindowSensor(unique_id, sensor_id, entry, name, coordinator, device, query.INPUTS))

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

async_add_entities(sensors)


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

_attr_has_entity_name = True

def __init__(
self,
unique_id: str,
alert_id: str,
config: ConfigEntry,
coordinator: DataUpdateCoordinator,
device: AlarmDevice,
) -> None:
"""Construct."""
super().__init__(coordinator)
self.entity_id = generate_entity_id(config, alert_id)
self._unique_id = unique_id
self._alert_id = alert_id
self._device = device

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

@property
def translation_key(self) -> str:
"""Return the translation key to translate the entity's name and states."""
return self._alert_id

@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)."""
state = self._device.alerts.get(self._alert_id)
return state > 1 if self._alert_id == "anomalies_led" else state > 0


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

Expand Down
5 changes: 5 additions & 0 deletions custom_components/elmo_iess_alarm/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, connection, config=None):

# Alarm state
self.state = STATE_UNAVAILABLE
self.alerts = {}
self.sectors_armed = {}
self.sectors_disarmed = {}
self.inputs_alerted = {}
Expand Down Expand Up @@ -148,6 +149,7 @@ def update(self):
try:
sectors = self._connection.query(q.SECTORS)
inputs = self._connection.query(q.INPUTS)
alerts = self._connection.get_status()
except (HTTPError, ParseError) as err:
_LOGGER.error(f"Device | Error while checking if there are updates: {err}")
raise
Expand All @@ -161,6 +163,9 @@ def update(self):
self._lastIds[q.SECTORS] = sectors.get("last_id", 0)
self._lastIds[q.INPUTS] = inputs.get("last_id", 0)

# Update system alerts
self.alerts = alerts

# Update the internal state machine (mapping state)
self.state = self.get_state()

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"
}
253 changes: 216 additions & 37 deletions custom_components/elmo_iess_alarm/strings.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,222 @@
{
"config": {
"step": {
"user": {
"data": {
"domain": "Domain name (optional)",
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]",
"system_name": "[%key:common::config_flow::data::system_name%]"
"config": {
"step": {
"user": {
"data": {
"domain": "Domain name (optional)",
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]",
"system_name": "[%key:common::config_flow::data::system_name%]"
},
"description": "Provide your credentials and the domain used to access your login page via web.\n\nFor instance, if you access to `https://connect.elmospa.com/vendor/`, you must set the domain to `vendor`. In case you don't have a vendor defined, set it to `default`.\n\nYou can configure the system selecting \"Options\" after installing the integration.",
"title": "Configure your Elmo/IESS system"
}
},
"description": "Provide your credentials and the domain used to access your login page via web.\n\nFor instance, if you access to `https://connect.elmospa.com/vendor/`, you must set the domain to `vendor`. In case you don't have a vendor defined, set it to `default`.\n\nYou can configure the system selecting \"Options\" after installing the integration.",
"title": "Configure your Elmo/IESS system"
}
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"invalid_areas": "Digited areas (home or night) are invalid",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"invalid_areas": "Digited areas (home or night) are invalid",
"unknown": "[%key:common::config_flow::error::unknown%]"
"options": {
"error": {
"invalid_areas": "Selected sectors are invalid",
"unknown": "Unexpected error: check your logs"
},
"step": {
"init": {
"data": {
"areas_arm_home": "Armed areas while at home (e.g 3,4 - optional)",
"areas_arm_night": "Armed areas at night (e.g. 3,4 - optional)",
"areas_arm_vacation": "Armed areas when you are on vacation (e.g. 3,4 - optional)",
"scan_interval": "Scan interval (e.g. 120 - optional)"
},
"description": "Define sectors you want to arm in different modes.\n\nSet 'Scan Interval' value only if you want to reduce data usage, in case the system is connected through a mobile network. Leave it empty for real time updates, or set it to a value in seconds (e.g. 120 for one update every 2 minutes)",
"title": "Configure your Elmo/IESS system"
}
}
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
"entity": {
"binary_sensor": {
"anomalies_led": {
"name": "General Anomaly",
"state": {
"on": "On",
"off": "Off"
}
},
"inputs_led": {
"name": "Zones Ready Status",
"state": {
"on": "On",
"off": "Off"
}
},
"alarm_led": {
"name": "General Alarm",
"state": {
"on": "On",
"off": "Off"
}
},
"tamper_led": {
"name": "General Tamper",
"state": {
"on": "On",
"off": "Off"
}
},
"has_anomaly": {
"name": "Anomalies",
"state": {
"on": "Detected",
"off": "No"
}
},
"panel_tamper": {
"name": "Panel Tamper",
"state": {
"on": "Tampered",
"off": "Secure"
}
},
"panel_no_power": {
"name": "System Main Power",
"state": {
"on": "No Power",
"off": "Powered"
}
},
"panel_low_battery": {
"name": "System Battery",
"state": {
"on": "Low Battery",
"off": "OK"
}
},
"gsm_anomaly": {
"name": "GSM Status",
"state": {
"on": "Anomaly",
"off": "OK"
}
},
"gsm_low_balance": {
"name": "GSM Plafond Balance",
"state": {
"on": "Low",
"off": "OK"
}
},
"pstn_anomaly": {
"name": "PSTN Anomaly",
"state": {
"on": "Detected",
"off": "No"
}
},
"system_test": {
"name": "System Test",
"state": {
"on": "Required",
"off": "OK"
}
},
"module_registration": {
"name": "Module Registration",
"state": {
"on": "Registering",
"off": "Not Registering"
}
},
"rf_interference": {
"name": "RF Interference",
"state": {
"on": "Detected",
"off": "No"
}
},
"input_failure": {
"name": "Input Failure",
"state": {
"on": "Detected",
"off": "No"
}
},
"input_alarm": {
"name": "Input Alarm",
"state": {
"on": "Triggered",
"off": "No"
}
},
"input_bypass": {
"name": "Input Bypass",
"state": {
"on": "Bypassed",
"off": "No"
}
},
"input_low_battery": {
"name": "Input Battery",
"state": {
"on": "Low Battery",
"off": "OK"
}
},
"input_no_supervision": {
"name": "Input No Supervision",
"state": {
"on": "Not Supervised",
"off": "Supervised"
}
},
"device_tamper": {
"name": "Device Protection",
"state": {
"on": "Tampered",
"off": "Secure"
}
},
"device_failure": {
"name": "Device Failure",
"state": {
"on": "Detected",
"off": "No"
}
},
"device_no_power": {
"name": "Device Power",
"state": {
"on": "No Power",
"off": "Powered"
}
},
"device_low_battery": {
"name": "Device Battery",
"state": {
"on": "Low Battery",
"off": "OK"
}
},
"device_no_supervision": {
"name": "Device No Supervision",
"state": {
"on": "Not Supervised",
"off": "Supervised"
}
},
"device_system_block": {
"name": "Device System Block",
"state": {
"on": "Blocked",
"off": "Not Blocked"
}
}
}
}
},
"options": {
"error": {
"invalid_areas": "Selected sectors are invalid",
"unknown": "Unexpected error: check your logs"
},
"step": {
"init": {
"data": {
"areas_arm_home": "Armed areas while at home (e.g 3,4 - optional)",
"areas_arm_night": "Armed areas at night (e.g. 3,4 - optional)",
"areas_arm_vacation": "Armed areas when you are on vacation (e.g. 3,4 - optional)",
"scan_interval": "Scan interval (e.g. 120 - optional)"
},
"description": "Define sectors you want to arm in different modes.\n\nSet 'Scan Interval' value only if you want to reduce data usage, in case the system is connected through a mobile network. Leave it empty for real time updates, or set it to a value in seconds (e.g. 120 for one update every 2 minutes)",
"title": "Configure your Elmo/IESS system"
}
}
}
}
Loading

0 comments on commit 64531ef

Please sign in to comment.