mirror of
https://github.com/home-assistant/core.git
synced 2026-07-07 06:46:17 +01:00
b015dbfccb
* 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>
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Support for AlarmDecoder sensors (Shows Panel Display)."""
|
|
|
|
from homeassistant.components.sensor import SensorEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .const import DATA_AD, DOMAIN, SIGNAL_PANEL_MESSAGE
|
|
from .entity import AlarmDecoderEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
) -> None:
|
|
"""Set up for AlarmDecoder sensor."""
|
|
|
|
client = hass.data[DOMAIN][entry.entry_id][DATA_AD]
|
|
entity = AlarmDecoderSensor(client=client)
|
|
async_add_entities([entity])
|
|
|
|
|
|
class AlarmDecoderSensor(AlarmDecoderEntity, SensorEntity):
|
|
"""Representation of an AlarmDecoder keypad."""
|
|
|
|
_attr_translation_key = "alarm_panel_display"
|
|
_attr_name = "Alarm Panel Display"
|
|
_attr_should_poll = False
|
|
|
|
def __init__(self, client):
|
|
"""Initialize the alarm decoder sensor."""
|
|
super().__init__(client)
|
|
self._attr_unique_id = f"{client.serial_number}-display"
|
|
|
|
async def async_added_to_hass(self) -> None:
|
|
"""Register callbacks."""
|
|
self.async_on_remove(
|
|
async_dispatcher_connect(
|
|
self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback
|
|
)
|
|
)
|
|
|
|
def _message_callback(self, message):
|
|
if self._attr_native_value != message.text:
|
|
self._attr_native_value = message.text
|
|
self.schedule_update_ha_state()
|