2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Wink switches."""
|
2017-10-09 15:16:36 +00:00
|
|
|
import logging
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2016-06-29 21:16:53 +00:00
|
|
|
from homeassistant.helpers.entity import ToggleEntity
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN, WinkDevice
|
|
|
|
|
2017-10-09 15:16:36 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-12-17 03:45:58 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Wink platform."""
|
2015-07-20 07:41:57 +00:00
|
|
|
import pywink
|
|
|
|
|
2016-11-30 21:12:26 +00:00
|
|
|
for switch in pywink.get_switches():
|
2017-02-02 06:43:12 +00:00
|
|
|
_id = switch.object_id() + switch.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([WinkToggleDevice(switch, hass)])
|
2017-01-25 05:11:18 +00:00
|
|
|
for switch in pywink.get_powerstrips():
|
2017-02-02 06:43:12 +00:00
|
|
|
_id = switch.object_id() + switch.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([WinkToggleDevice(switch, hass)])
|
2017-01-25 05:11:18 +00:00
|
|
|
for sprinkler in pywink.get_sprinklers():
|
2017-02-02 06:43:12 +00:00
|
|
|
_id = sprinkler.object_id() + sprinkler.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([WinkToggleDevice(sprinkler, hass)])
|
2017-07-19 22:27:39 +00:00
|
|
|
for switch in pywink.get_binary_switch_groups():
|
|
|
|
_id = switch.object_id() + switch.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([WinkToggleDevice(switch, hass)])
|
2016-06-29 21:16:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WinkToggleDevice(WinkDevice, ToggleEntity):
|
2016-09-20 07:05:54 +00:00
|
|
|
"""Representation of a Wink toggle device."""
|
2016-06-29 21:16:53 +00:00
|
|
|
|
2018-10-01 06:55:00 +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"]["switch"].append(self)
|
2017-05-13 18:09:00 +00:00
|
|
|
|
2016-06-29 21:16:53 +00: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 17:20:28 +00:00
|
|
|
def turn_off(self, **kwargs):
|
2016-06-29 21:16:53 +00:00
|
|
|
"""Turn the device off."""
|
|
|
|
self.wink.set_state(False)
|
2017-02-02 06:43:12 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes."""
|
2017-03-25 14:28:16 +00:00
|
|
|
attributes = super(WinkToggleDevice, self).device_state_attributes
|
2017-02-02 06:43:12 +00:00
|
|
|
try:
|
|
|
|
event = self.wink.last_event()
|
2017-08-11 06:35:45 +00:00
|
|
|
if event is not None:
|
|
|
|
attributes["last_event"] = event
|
2017-02-02 06:43:12 +00:00
|
|
|
except AttributeError:
|
2017-03-25 14:28:16 +00:00
|
|
|
pass
|
|
|
|
return attributes
|