Add AlarmDecoder device info (#117357)

* Update AlarmDecoder component to newer model

This commit makes AlarmDecoder operate as a proper device entity following the new model introduced a few years ago.

Code also has an internal dependency on a newer version of adext (>= 0.4.3) which has been updated correspondingly.

* Created AlarmDecoder entity

Added an alarmdecoder entity so the device_info can be re-used across the integration

* Move _attr_has_entity_name to base entity

As per code review suggestion, clean up the object model.

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Missed one suggestion with the prior commit

Moves _attr_has_entity_name to base entity

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Address some ruff issues

* Apply additional ruff cleanups

Ran ruff again to clean up a few files tat weren't picked up last time

* Apply suggestions from code review

Some additional cleanup of style & removal of unnecessary code

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Properly generated the integration file

generation had to happen twice for this to work.  Now that it's generated, I'm including the missing update.

* Apply suggestions from code review

Use local client variable instead of self._client

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Sort the manifest

documentation was added, but it wasn't sorted properly in the key/value pairs

* Add alarmdecoder entity file to coverage ignore file

Added the alarmdecoder entity file so it is ignored for coverage

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Christopher Tremblay 2024-05-17 23:59:44 -07:00 committed by GitHub
parent 2b195cab72
commit b015dbfccb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 57 additions and 8 deletions

View file

@ -16,13 +16,16 @@ from .const import (
CONF_ZONE_NUMBER,
CONF_ZONE_RFID,
CONF_ZONE_TYPE,
DATA_AD,
DEFAULT_ZONE_OPTIONS,
DOMAIN,
OPTIONS_ZONES,
SIGNAL_REL_MESSAGE,
SIGNAL_RFX_MESSAGE,
SIGNAL_ZONE_FAULT,
SIGNAL_ZONE_RESTORE,
)
from .entity import AlarmDecoderEntity
_LOGGER = logging.getLogger(__name__)
@ -41,6 +44,7 @@ async def async_setup_entry(
) -> None:
"""Set up for AlarmDecoder sensor."""
client = hass.data[DOMAIN][entry.entry_id][DATA_AD]
zones = entry.options.get(OPTIONS_ZONES, DEFAULT_ZONE_OPTIONS)
entities = []
@ -53,20 +57,28 @@ async def async_setup_entry(
relay_addr = zone_info.get(CONF_RELAY_ADDR)
relay_chan = zone_info.get(CONF_RELAY_CHAN)
entity = AlarmDecoderBinarySensor(
zone_num, zone_name, zone_type, zone_rfid, zone_loop, relay_addr, relay_chan
client,
zone_num,
zone_name,
zone_type,
zone_rfid,
zone_loop,
relay_addr,
relay_chan,
)
entities.append(entity)
async_add_entities(entities)
class AlarmDecoderBinarySensor(BinarySensorEntity):
class AlarmDecoderBinarySensor(AlarmDecoderEntity, BinarySensorEntity):
"""Representation of an AlarmDecoder binary sensor."""
_attr_should_poll = False
def __init__(
self,
client,
zone_number,
zone_name,
zone_type,
@ -76,6 +88,8 @@ class AlarmDecoderBinarySensor(BinarySensorEntity):
relay_chan,
):
"""Initialize the binary_sensor."""
super().__init__(client)
self._attr_unique_id = f"{client.serial_number}-zone-{zone_number}"
self._zone_number = int(zone_number)
self._zone_type = zone_type
self._attr_name = zone_name