2015-05-13 19:18:30 +02:00
|
|
|
"""
|
|
|
|
Support for Wink switches.
|
2015-10-21 10:47:31 +02:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 13:12:18 +01:00
|
|
|
https://home-assistant.io/components/switch.wink/
|
2015-05-13 19:18:30 +02:00
|
|
|
"""
|
2017-05-13 14:09:00 -04:00
|
|
|
import asyncio
|
2017-10-09 11:16:36 -04:00
|
|
|
import logging
|
2014-12-16 00:01:15 -08:00
|
|
|
|
2018-01-21 07:35:38 +01:00
|
|
|
from homeassistant.components.wink import DOMAIN, WinkDevice
|
2016-06-29 17:16:53 -04:00
|
|
|
from homeassistant.helpers.entity import ToggleEntity
|
2014-12-16 00:01:15 -08:00
|
|
|
|
2016-09-20 03:05:54 -04:00
|
|
|
DEPENDENCIES = ['wink']
|
2014-12-16 00:01:15 -08:00
|
|
|
|
2017-10-09 11:16:36 -04:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-12-16 22:45:58 -05:00
|
|
|
|
2018-08-24 16:37:30 +02:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-02 18:18:47 +02:00
|
|
|
"""Set up the Wink platform."""
|
2015-07-20 00:41:57 -07:00
|
|
|
import pywink
|
|
|
|
|
2016-11-30 16:12:26 -05:00
|
|
|
for switch in pywink.get_switches():
|
2017-02-02 01:43:12 -05:00
|
|
|
_id = switch.object_id() + switch.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 16:37:30 +02:00
|
|
|
add_entities([WinkToggleDevice(switch, hass)])
|
2017-01-25 00:11:18 -05:00
|
|
|
for switch in pywink.get_powerstrips():
|
2017-02-02 01:43:12 -05:00
|
|
|
_id = switch.object_id() + switch.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 16:37:30 +02:00
|
|
|
add_entities([WinkToggleDevice(switch, hass)])
|
2017-01-25 00:11:18 -05:00
|
|
|
for sprinkler in pywink.get_sprinklers():
|
2017-02-02 01:43:12 -05:00
|
|
|
_id = sprinkler.object_id() + sprinkler.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 16:37:30 +02:00
|
|
|
add_entities([WinkToggleDevice(sprinkler, hass)])
|
2017-07-19 18:27:39 -04:00
|
|
|
for switch in pywink.get_binary_switch_groups():
|
|
|
|
_id = switch.object_id() + switch.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 16:37:30 +02:00
|
|
|
add_entities([WinkToggleDevice(switch, hass)])
|
2016-06-29 17:16:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
class WinkToggleDevice(WinkDevice, ToggleEntity):
|
2016-09-20 03:05:54 -04:00
|
|
|
"""Representation of a Wink toggle device."""
|
2016-06-29 17:16:53 -04:00
|
|
|
|
2017-05-13 14:09:00 -04:00
|
|
|
@asyncio.coroutine
|
|
|
|
def async_added_to_hass(self):
|
2018-01-21 07:35:38 +01:00
|
|
|
"""Call when entity is added to hass."""
|
2017-05-13 14:09:00 -04:00
|
|
|
self.hass.data[DOMAIN]['entities']['switch'].append(self)
|
|
|
|
|
2016-06-29 17:16:53 -04:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if device is on."""
|
|
|
|
return self.wink.state()
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
"""Turn the device on."""
|
|
|
|
self.wink.set_state(True)
|
|
|
|
|
2018-02-11 18:20:28 +01:00
|
|
|
def turn_off(self, **kwargs):
|
2016-06-29 17:16:53 -04:00
|
|
|
"""Turn the device off."""
|
|
|
|
self.wink.set_state(False)
|
2017-02-02 01:43:12 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes."""
|
2017-03-25 10:28:16 -04:00
|
|
|
attributes = super(WinkToggleDevice, self).device_state_attributes
|
2017-02-02 01:43:12 -05:00
|
|
|
try:
|
|
|
|
event = self.wink.last_event()
|
2017-08-11 02:35:45 -04:00
|
|
|
if event is not None:
|
|
|
|
attributes["last_event"] = event
|
2017-02-02 01:43:12 -05:00
|
|
|
except AttributeError:
|
2017-03-25 10:28:16 -04:00
|
|
|
pass
|
|
|
|
return attributes
|