mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use attributes in risco alarm (#74117)
This commit is contained in:
parent
0063274f83
commit
670af6fde3
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||||||
STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -65,44 +66,46 @@ async def async_setup_entry(
|
|||||||
class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
|
class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
|
||||||
"""Representation of a Risco partition."""
|
"""Representation of a Risco partition."""
|
||||||
|
|
||||||
|
_attr_code_format = CodeFormat.NUMBER
|
||||||
|
|
||||||
def __init__(self, coordinator, partition_id, code, options):
|
def __init__(self, coordinator, partition_id, code, options):
|
||||||
"""Init the partition."""
|
"""Init the partition."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._partition_id = partition_id
|
self._partition_id = partition_id
|
||||||
self._partition = self.coordinator.data.partitions[self._partition_id]
|
self._partition = self.coordinator.data.partitions[self._partition_id]
|
||||||
self._code = code
|
self._code = code
|
||||||
self._code_arm_required = options[CONF_CODE_ARM_REQUIRED]
|
self._attr_code_arm_required = options[CONF_CODE_ARM_REQUIRED]
|
||||||
self._code_disarm_required = options[CONF_CODE_DISARM_REQUIRED]
|
self._code_disarm_required = options[CONF_CODE_DISARM_REQUIRED]
|
||||||
self._risco_to_ha = options[CONF_RISCO_STATES_TO_HA]
|
self._risco_to_ha = options[CONF_RISCO_STATES_TO_HA]
|
||||||
self._ha_to_risco = options[CONF_HA_STATES_TO_RISCO]
|
self._ha_to_risco = options[CONF_HA_STATES_TO_RISCO]
|
||||||
self._supported_states = 0
|
self._attr_supported_features = 0
|
||||||
for state in self._ha_to_risco:
|
for state in self._ha_to_risco:
|
||||||
self._supported_states |= STATES_TO_SUPPORTED_FEATURES[state]
|
self._attr_supported_features |= STATES_TO_SUPPORTED_FEATURES[state]
|
||||||
|
|
||||||
def _get_data_from_coordinator(self):
|
def _get_data_from_coordinator(self):
|
||||||
self._partition = self.coordinator.data.partitions[self._partition_id]
|
self._partition = self.coordinator.data.partitions[self._partition_id]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return device info for this device."""
|
"""Return device info for this device."""
|
||||||
return {
|
return DeviceInfo(
|
||||||
"identifiers": {(DOMAIN, self.unique_id)},
|
identifiers={(DOMAIN, self.unique_id)},
|
||||||
"name": self.name,
|
name=self.name,
|
||||||
"manufacturer": "Risco",
|
manufacturer="Risco",
|
||||||
}
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str:
|
||||||
"""Return the name of the partition."""
|
"""Return the name of the partition."""
|
||||||
return f"Risco {self._risco.site_name} Partition {self._partition_id}"
|
return f"Risco {self._risco.site_name} Partition {self._partition_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self) -> str:
|
||||||
"""Return a unique id for that partition."""
|
"""Return a unique id for that partition."""
|
||||||
return f"{self._risco.site_uuid}_{self._partition_id}"
|
return f"{self._risco.site_uuid}_{self._partition_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self) -> str | None:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
if self._partition.triggered:
|
if self._partition.triggered:
|
||||||
return STATE_ALARM_TRIGGERED
|
return STATE_ALARM_TRIGGERED
|
||||||
@ -121,21 +124,6 @@ class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return the list of supported features."""
|
|
||||||
return self._supported_states
|
|
||||||
|
|
||||||
@property
|
|
||||||
def code_arm_required(self):
|
|
||||||
"""Whether the code is required for arm actions."""
|
|
||||||
return self._code_arm_required
|
|
||||||
|
|
||||||
@property
|
|
||||||
def code_format(self):
|
|
||||||
"""Return one or more digits/characters."""
|
|
||||||
return CodeFormat.NUMBER
|
|
||||||
|
|
||||||
def _validate_code(self, code):
|
def _validate_code(self, code):
|
||||||
"""Validate given code."""
|
"""Validate given code."""
|
||||||
return code == self._code
|
return code == self._code
|
||||||
@ -164,7 +152,7 @@ class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
|
|||||||
await self._arm(STATE_ALARM_ARMED_CUSTOM_BYPASS, code)
|
await self._arm(STATE_ALARM_ARMED_CUSTOM_BYPASS, code)
|
||||||
|
|
||||||
async def _arm(self, mode, code):
|
async def _arm(self, mode, code):
|
||||||
if self._code_arm_required and not self._validate_code(code):
|
if self.code_arm_required and not self._validate_code(code):
|
||||||
_LOGGER.warning("Wrong code entered for %s", mode)
|
_LOGGER.warning("Wrong code entered for %s", mode)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user