2019-02-13 20:21:14 +00:00
|
|
|
"""Support Wink alarm control panels."""
|
2017-01-25 05:11:18 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import homeassistant.components.alarm_control_panel as alarm
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.components.wink import DOMAIN, WinkDevice
|
|
|
|
from homeassistant.const import (
|
2019-01-24 07:20:20 +00:00
|
|
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED)
|
2017-01-25 05:11:18 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['wink']
|
2017-04-30 05:04:49 +00:00
|
|
|
|
2017-01-25 05:11:18 +00:00
|
|
|
STATE_ALARM_PRIVACY = 'Private'
|
|
|
|
|
|
|
|
|
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
|
|
|
import pywink
|
|
|
|
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
class WinkCameraDevice(WinkDevice, alarm.AlarmControlPanel):
|
|
|
|
"""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."""
|
2017-05-13 18:09:00 +00:00
|
|
|
self.hass.data[DOMAIN]['entities']['alarm_control_panel'].append(self)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes."""
|
|
|
|
return {
|
|
|
|
'private': self.wink.private()
|
|
|
|
}
|