1 """Support for Xiomi Gateway alarm control panels."""
3 from __future__
import annotations
5 from functools
import partial
8 from miio
import DeviceException
11 AlarmControlPanelEntity,
12 AlarmControlPanelEntityFeature,
13 AlarmControlPanelState,
20 from .const
import CONF_GATEWAY, DOMAIN
22 _LOGGER = logging.getLogger(__name__)
24 XIAOMI_STATE_ARMED_VALUE =
"on"
25 XIAOMI_STATE_DISARMED_VALUE =
"off"
26 XIAOMI_STATE_ARMING_VALUE =
"oning"
31 config_entry: ConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Set up the Xiaomi Gateway Alarm from a config entry."""
36 gateway = hass.data[DOMAIN][config_entry.entry_id][CONF_GATEWAY]
39 f
"{config_entry.title} Alarm",
40 config_entry.data[
"model"],
41 config_entry.data[
"mac"],
42 config_entry.unique_id,
44 entities.append(entity)
49 """Representation of the XiaomiGatewayAlarm."""
51 _attr_icon =
"mdi:shield-home"
52 _attr_supported_features = AlarmControlPanelEntityFeature.ARM_AWAY
53 _attr_code_arm_required =
False
56 self, gateway_device, gateway_name, model, mac_address, gateway_device_id
58 """Initialize the entity."""
64 identifiers={(DOMAIN, gateway_device_id)},
68 """Call a device command handling error messages."""
70 result = await self.
hasshass.async_add_executor_job(
71 partial(func, *args, **kwargs)
73 _LOGGER.debug(
"Response received from miio device: %s", result)
74 except DeviceException
as exc:
75 _LOGGER.error(mask_error, exc)
80 "Turning the alarm on failed: %s", self.
_gateway_gateway.alarm.on
86 "Turning the alarm off failed: %s", self.
_gateway_gateway.alarm.off
90 """Fetch state from the device."""
92 state = await self.
hasshass.async_add_executor_job(self.
_gateway_gateway.alarm.status)
93 except DeviceException
as ex:
96 _LOGGER.error(
"Got exception while fetching the state: %s", ex)
100 _LOGGER.debug(
"Got new state: %s", state)
104 if state == XIAOMI_STATE_ARMED_VALUE:
106 elif state == XIAOMI_STATE_DISARMED_VALUE:
108 elif state == XIAOMI_STATE_ARMING_VALUE:
112 "New state (%s) doesn't match expected values: %s/%s/%s",
114 XIAOMI_STATE_ARMED_VALUE,
115 XIAOMI_STATE_DISARMED_VALUE,
116 XIAOMI_STATE_ARMING_VALUE,
None async_alarm_disarm(self, str|None code=None)
def _try_command(self, mask_error, func, *args, **kwargs)
def __init__(self, gateway_device, gateway_name, model, mac_address, gateway_device_id)
None async_alarm_arm_away(self, str|None code=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)