mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Use attributes in ialarm alarm (#74099)
This commit is contained in:
parent
03d2d50393
commit
79b3865b60
@ -1,4 +1,6 @@
|
|||||||
"""iAlarm integration."""
|
"""iAlarm integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -20,8 +22,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up iAlarm config."""
|
"""Set up iAlarm config."""
|
||||||
host = entry.data[CONF_HOST]
|
host: str = entry.data[CONF_HOST]
|
||||||
port = entry.data[CONF_PORT]
|
port: int = entry.data[CONF_PORT]
|
||||||
ialarm = IAlarm(host, port)
|
ialarm = IAlarm(host, port)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -55,11 +57,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
class IAlarmDataUpdateCoordinator(DataUpdateCoordinator):
|
class IAlarmDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
"""Class to manage fetching iAlarm data."""
|
"""Class to manage fetching iAlarm data."""
|
||||||
|
|
||||||
def __init__(self, hass, ialarm, mac):
|
def __init__(self, hass: HomeAssistant, ialarm: IAlarm, mac: str) -> None:
|
||||||
"""Initialize global iAlarm data updater."""
|
"""Initialize global iAlarm data updater."""
|
||||||
self.ialarm = ialarm
|
self.ialarm = ialarm
|
||||||
self.state = None
|
self.state: str | None = None
|
||||||
self.host = ialarm.host
|
self.host: str = ialarm.host
|
||||||
self.mac = mac
|
self.mac = mac
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
|
@ -11,6 +11,7 @@ from homeassistant.helpers.entity import DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from . import IAlarmDataUpdateCoordinator
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .const import DATA_COORDINATOR, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -18,39 +19,35 @@ async def async_setup_entry(
|
|||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a iAlarm alarm control panel based on a config entry."""
|
"""Set up a iAlarm alarm control panel based on a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR]
|
coordinator: IAlarmDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||||
|
DATA_COORDINATOR
|
||||||
|
]
|
||||||
async_add_entities([IAlarmPanel(coordinator)], False)
|
async_add_entities([IAlarmPanel(coordinator)], False)
|
||||||
|
|
||||||
|
|
||||||
class IAlarmPanel(CoordinatorEntity, AlarmControlPanelEntity):
|
class IAlarmPanel(
|
||||||
|
CoordinatorEntity[IAlarmDataUpdateCoordinator], AlarmControlPanelEntity
|
||||||
|
):
|
||||||
"""Representation of an iAlarm device."""
|
"""Representation of an iAlarm device."""
|
||||||
|
|
||||||
|
_attr_name = "iAlarm"
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
AlarmControlPanelEntityFeature.ARM_HOME
|
AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
def __init__(self, coordinator: IAlarmDataUpdateCoordinator) -> None:
|
||||||
def device_info(self) -> DeviceInfo:
|
"""Create the entity with a DataUpdateCoordinator."""
|
||||||
"""Return device info for this device."""
|
super().__init__(coordinator)
|
||||||
return DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, self.unique_id)},
|
identifiers={(DOMAIN, coordinator.mac)},
|
||||||
manufacturer="Antifurto365 - Meian",
|
manufacturer="Antifurto365 - Meian",
|
||||||
name=self.name,
|
name="iAlarm",
|
||||||
)
|
)
|
||||||
|
self._attr_unique_id = coordinator.mac
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def state(self) -> str | None:
|
||||||
"""Return a unique id."""
|
|
||||||
return self.coordinator.mac
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name."""
|
|
||||||
return "iAlarm"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self.coordinator.state
|
return self.coordinator.state
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user