Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AlarmDecoder device info #117357

Merged
merged 16 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ omit =
homeassistant/components/alarmdecoder/__init__.py
homeassistant/components/alarmdecoder/alarm_control_panel.py
homeassistant/components/alarmdecoder/binary_sensor.py
homeassistant/components/alarmdecoder/entity.py
homeassistant/components/alarmdecoder/sensor.py
homeassistant/components/alpha_vantage/sensor.py
homeassistant/components/amazon_polly/*
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/alarmdecoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def handle_rel_message(sender, message):

await open_connection()

await controller.is_init()

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/alarmdecoder/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
OPTIONS_ARM,
SIGNAL_PANEL_MESSAGE,
)
from .entity import AlarmDecoderEntity

SERVICE_ALARM_TOGGLE_CHIME = "alarm_toggle_chime"

Expand Down Expand Up @@ -75,7 +76,7 @@ async def async_setup_entry(
)


class AlarmDecoderAlarmPanel(AlarmControlPanelEntity):
class AlarmDecoderAlarmPanel(AlarmDecoderEntity, AlarmControlPanelEntity):
"""Representation of an AlarmDecoder-based alarm panel."""

_attr_name = "Alarm Panel"
Expand All @@ -89,7 +90,8 @@ class AlarmDecoderAlarmPanel(AlarmControlPanelEntity):

def __init__(self, client, auto_bypass, code_arm_required, alt_night_mode):
"""Initialize the alarm panel."""
self._client = client
super().__init__(client)
self._attr_unique_id = f"{client.serial_number}-panel"
self._auto_bypass = auto_bypass
self._attr_code_arm_required = code_arm_required
self._alt_night_mode = alt_night_mode
Expand Down
18 changes: 16 additions & 2 deletions homeassistant/components/alarmdecoder/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
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__)

Expand All @@ -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 = []
Expand All @@ -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,
Expand All @@ -76,6 +88,8 @@ def __init__(
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
Expand Down
22 changes: 22 additions & 0 deletions homeassistant/components/alarmdecoder/entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Support for AlarmDecoder-based alarm control panels entity."""

from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import Entity

from .const import DOMAIN


class AlarmDecoderEntity(Entity):
"""Define a base AlarmDecoder entity."""

_attr_has_entity_name = True

def __init__(self, client):
"""Initialize the alarm decoder entity."""
self._client = client
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, client.serial_number)},
manufacturer="NuTech",
serial_number=client.serial_number,
sw_version=client.version_number,
)
1 change: 1 addition & 0 deletions homeassistant/components/alarmdecoder/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"codeowners": [],
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/alarmdecoder",
"integration_type": "device",
"iot_class": "local_push",
"loggers": ["adext", "alarmdecoder"],
"requirements": ["adext==0.4.3"]
epenet marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
13 changes: 10 additions & 3 deletions homeassistant/components/alarmdecoder/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import SIGNAL_PANEL_MESSAGE
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."""

entity = AlarmDecoderSensor()
client = hass.data[DOMAIN][entry.entry_id][DATA_AD]
entity = AlarmDecoderSensor(client=client)
async_add_entities([entity])


class AlarmDecoderSensor(SensorEntity):
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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/generated/integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
},
"alarmdecoder": {
"name": "AlarmDecoder",
"integration_type": "hub",
"integration_type": "device",
"config_flow": true,
"iot_class": "local_push"
},
Expand Down