1 """Support for Minut Point."""
3 from __future__
import annotations
5 from collections.abc
import Callable
9 DOMAIN
as ALARM_CONTROL_PANEL_DOMAIN,
10 AlarmControlPanelEntity,
11 AlarmControlPanelEntityFeature,
12 AlarmControlPanelState,
20 from .
import MinutPointClient
21 from .const
import DOMAIN
as POINT_DOMAIN, POINT_DISCOVERY_NEW, SIGNAL_WEBHOOK
23 _LOGGER = logging.getLogger(__name__)
27 "off": AlarmControlPanelState.DISARMED,
28 "alarm_silenced": AlarmControlPanelState.DISARMED,
29 "alarm_grace_period_expired": AlarmControlPanelState.TRIGGERED,
35 config_entry: ConfigEntry,
36 async_add_entities: AddEntitiesCallback,
38 """Set up a Point's alarm_control_panel based on a config entry."""
40 async
def async_discover_home(home_id):
41 """Discover and add a discovered home."""
42 client = config_entry.runtime_data.client
47 POINT_DISCOVERY_NEW.format(ALARM_CONTROL_PANEL_DOMAIN, POINT_DOMAIN),
53 """The platform class required by Home Assistant."""
55 _attr_supported_features = AlarmControlPanelEntityFeature.ARM_AWAY
56 _attr_code_arm_required =
False
58 def __init__(self, point_client: MinutPointClient, home_id: str) ->
None:
59 """Initialize the entity."""
68 identifiers={(POINT_DOMAIN, home_id)},
74 """Call when entity is added to HOme Assistant."""
81 """Disconnect dispatcher listener when removed."""
88 """Process new event from the webhook."""
89 _type = data.get(
"event", {}).
get(
"type")
90 _device_id = data.get(
"event", {}).
get(
"device_id")
91 _changed_by = data.get(
"event", {}).
get(
"user_id")
93 _device_id
not in self.
_home_home[
"devices"]
and _type
not in EVENT_MAP
94 )
and _type !=
"alarm_silenced":
96 _LOGGER.debug(
"Received webhook: %s", _type)
97 self.
_home_home[
"alarm_status"] = _type
103 """Return state of the device."""
104 return EVENT_MAP.get(
105 self.
_home_home[
"alarm_status"], AlarmControlPanelState.ARMED_AWAY
109 """Send disarm command."""
112 self.
_home_home[
"alarm_status"] =
"off"
115 """Send arm away command."""
116 status = await self.
_client_client.async_alarm_arm(self.
_home_id_home_id)
118 self.
_home_home[
"alarm_status"] =
"on"
None __init__(self, MinutPointClient point_client, str home_id)
None async_added_to_hass(self)
None async_alarm_arm_away(self, str|None code=None)
None async_will_remove_from_hass(self)
def _webhook_event(self, data, webhook)
AlarmControlPanelState alarm_state(self)
None async_alarm_disarm(self, str|None code=None)
_async_unsub_hook_dispatcher_connect
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)