mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use attributes in xiaomi_miio alarm (#74125)
This commit is contained in:
parent
670af6fde3
commit
f3a24d5a45
@ -51,6 +51,7 @@ async def async_setup_entry(
|
||||
class XiaomiGatewayAlarm(AlarmControlPanelEntity):
|
||||
"""Representation of the XiaomiGatewayAlarm."""
|
||||
|
||||
_attr_icon = "mdi:shield-home"
|
||||
_attr_supported_features = AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
|
||||
def __init__(
|
||||
@ -58,50 +59,13 @@ class XiaomiGatewayAlarm(AlarmControlPanelEntity):
|
||||
):
|
||||
"""Initialize the entity."""
|
||||
self._gateway = gateway_device
|
||||
self._name = gateway_name
|
||||
self._gateway_device_id = gateway_device_id
|
||||
self._unique_id = f"{model}-{mac_address}"
|
||||
self._icon = "mdi:shield-home"
|
||||
self._available = None
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return an unique ID."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_id(self):
|
||||
"""Return the device id of the gateway."""
|
||||
return self._gateway_device_id
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info of the gateway."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._gateway_device_id)},
|
||||
self._attr_name = gateway_name
|
||||
self._attr_unique_id = f"{model}-{mac_address}"
|
||||
self._attr_available = False
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, gateway_device_id)},
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of this entity, if any."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use for device if any."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return true when state is known."""
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
async def _try_command(self, mask_error, func, *args, **kwargs):
|
||||
"""Call a device command handling error messages."""
|
||||
try:
|
||||
@ -129,22 +93,22 @@ class XiaomiGatewayAlarm(AlarmControlPanelEntity):
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._gateway.alarm.status)
|
||||
except DeviceException as ex:
|
||||
if self._available:
|
||||
self._available = False
|
||||
if self._attr_available:
|
||||
self._attr_available = False
|
||||
_LOGGER.error("Got exception while fetching the state: %s", ex)
|
||||
|
||||
return
|
||||
|
||||
_LOGGER.debug("Got new state: %s", state)
|
||||
|
||||
self._available = True
|
||||
self._attr_available = True
|
||||
|
||||
if state == XIAOMI_STATE_ARMED_VALUE:
|
||||
self._state = STATE_ALARM_ARMED_AWAY
|
||||
self._attr_state = STATE_ALARM_ARMED_AWAY
|
||||
elif state == XIAOMI_STATE_DISARMED_VALUE:
|
||||
self._state = STATE_ALARM_DISARMED
|
||||
self._attr_state = STATE_ALARM_DISARMED
|
||||
elif state == XIAOMI_STATE_ARMING_VALUE:
|
||||
self._state = STATE_ALARM_ARMING
|
||||
self._attr_state = STATE_ALARM_ARMING
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"New state (%s) doesn't match expected values: %s/%s/%s",
|
||||
@ -153,6 +117,6 @@ class XiaomiGatewayAlarm(AlarmControlPanelEntity):
|
||||
XIAOMI_STATE_DISARMED_VALUE,
|
||||
XIAOMI_STATE_ARMING_VALUE,
|
||||
)
|
||||
self._state = None
|
||||
self._attr_state = None
|
||||
|
||||
_LOGGER.debug("State value: %s", self._state)
|
||||
_LOGGER.debug("State value: %s", self._attr_state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user