core/homeassistant/components/alarmdecoder/sensor.py

48 lines
1.5 KiB
Python
Raw Normal View History

"""Support for AlarmDecoder sensors (Shows Panel Display)."""
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AlarmDecoderConfigEntry
from .const import SIGNAL_PANEL_MESSAGE
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>
2024-05-18 06:59:44 +00:00
from .entity import AlarmDecoderEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: AlarmDecoderConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up for AlarmDecoder sensor."""
entity = AlarmDecoderSensor(client=entry.runtime_data.client)
async_add_entities([entity])
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>
2024-05-18 06:59:44 +00:00
class AlarmDecoderSensor(AlarmDecoderEntity, SensorEntity):
"""Representation of an AlarmDecoder keypad."""
_attr_translation_key = "alarm_panel_display"
_attr_name = "Alarm Panel Display"
_attr_should_poll = False
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>
2024-05-18 06:59:44 +00:00
def __init__(self, client):
"""Initialize the alarm decoder sensor."""
super().__init__(client)
self._attr_unique_id = f"{client.serial_number}-display"
2022-08-18 13:56:52 +00:00
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
)
2019-07-31 19:25:30 +00:00
)
def _message_callback(self, message):
if self._attr_native_value != message.text:
self._attr_native_value = message.text
self.schedule_update_ha_state()