2019-02-13 20:21:14 +00:00
|
|
|
"""Support Wink alarm control panels."""
|
2019-10-10 16:51:28 +00:00
|
|
|
import pywink
|
|
|
|
|
2017-01-25 05:11:18 +00:00
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
2019-11-25 23:42:53 +00:00
|
|
|
from homeassistant.components.alarm_control_panel.const import (
|
|
|
|
SUPPORT_ALARM_ARM_AWAY,
|
|
|
|
SUPPORT_ALARM_ARM_HOME,
|
|
|
|
)
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_ALARM_ARMED_AWAY,
|
|
|
|
STATE_ALARM_ARMED_HOME,
|
|
|
|
STATE_ALARM_DISARMED,
|
|
|
|
)
|
2017-01-25 05:11:18 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN, WinkDevice
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_ALARM_PRIVACY = "Private"
|
2017-01-25 05:11:18 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Wink platform."""
|
2017-01-25 05:11:18 +00:00
|
|
|
|
|
|
|
for camera in pywink.get_cameras():
|
2017-02-02 06:43:12 +00:00
|
|
|
# get_cameras returns multiple device types.
|
|
|
|
# Only add those that aren't sensors.
|
|
|
|
try:
|
|
|
|
camera.capability()
|
|
|
|
except AttributeError:
|
|
|
|
_id = camera.object_id() + camera.name()
|
2019-07-31 19:25:30 +00:00
|
|
|
if _id not in hass.data[DOMAIN]["unique_ids"]:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([WinkCameraDevice(camera, hass)])
|
2017-01-25 05:11:18 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:05:28 +00:00
|
|
|
class WinkCameraDevice(WinkDevice, alarm.AlarmControlPanelEntity):
|
2017-01-25 05:11:18 +00:00
|
|
|
"""Representation a Wink camera alarm."""
|
|
|
|
|
2018-10-01 06:49:19 +00:00
|
|
|
async def async_added_to_hass(self):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Call when entity is added to hass."""
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.data[DOMAIN]["entities"]["alarm_control_panel"].append(self)
|
2017-05-13 18:09:00 +00:00
|
|
|
|
2017-01-25 05:11:18 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the device."""
|
|
|
|
wink_state = self.wink.state()
|
|
|
|
if wink_state == "away":
|
|
|
|
state = STATE_ALARM_ARMED_AWAY
|
|
|
|
elif wink_state == "home":
|
|
|
|
state = STATE_ALARM_DISARMED
|
|
|
|
elif wink_state == "night":
|
|
|
|
state = STATE_ALARM_ARMED_HOME
|
|
|
|
else:
|
2019-01-24 07:20:20 +00:00
|
|
|
state = None
|
2017-01-25 05:11:18 +00:00
|
|
|
return state
|
|
|
|
|
2019-11-25 23:42:53 +00:00
|
|
|
@property
|
|
|
|
def supported_features(self) -> int:
|
|
|
|
"""Return the list of supported features."""
|
|
|
|
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
|
|
|
|
|
2017-01-25 05:11:18 +00:00
|
|
|
def alarm_disarm(self, code=None):
|
|
|
|
"""Send disarm command."""
|
|
|
|
self.wink.set_mode("home")
|
|
|
|
|
|
|
|
def alarm_arm_home(self, code=None):
|
|
|
|
"""Send arm home command."""
|
|
|
|
self.wink.set_mode("night")
|
|
|
|
|
|
|
|
def alarm_arm_away(self, code=None):
|
|
|
|
"""Send arm away command."""
|
|
|
|
self.wink.set_mode("away")
|
|
|
|
|
|
|
|
@property
|
2021-03-11 19:16:26 +00:00
|
|
|
def extra_state_attributes(self):
|
2017-01-25 05:11:18 +00:00
|
|
|
"""Return the state attributes."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return {"private": self.wink.private()}
|