2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Wink covers."""
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.components.cover import ATTR_POSITION, CoverDevice
|
|
|
|
|
|
|
|
from . import DOMAIN, WinkDevice
|
2016-08-24 01:23: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 cover platform."""
|
2016-08-24 01:23:18 +00:00
|
|
|
import pywink
|
|
|
|
|
2017-02-02 06:43:12 +00:00
|
|
|
for shade in pywink.get_shades():
|
|
|
|
_id = shade.object_id() + shade.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([WinkCoverDevice(shade, hass)])
|
2018-06-20 13:41:28 +00:00
|
|
|
for shade in pywink.get_shade_groups():
|
|
|
|
_id = shade.object_id() + shade.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([WinkCoverDevice(shade, hass)])
|
2017-02-02 06:43:12 +00:00
|
|
|
for door in pywink.get_garage_doors():
|
|
|
|
_id = door.object_id() + door.name()
|
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([WinkCoverDevice(door, hass)])
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WinkCoverDevice(WinkDevice, CoverDevice):
|
2016-09-20 07:05:54 +00:00
|
|
|
"""Representation of a Wink cover device."""
|
2016-08-24 01:23:18 +00:00
|
|
|
|
2018-06-30 16:10:59 +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']['cover'].append(self)
|
|
|
|
|
2017-07-06 03:02:16 +00:00
|
|
|
def close_cover(self, **kwargs):
|
2018-01-25 16:31:38 +00:00
|
|
|
"""Close the cover."""
|
2016-08-24 01:23:18 +00:00
|
|
|
self.wink.set_state(0)
|
|
|
|
|
2017-07-06 03:02:16 +00:00
|
|
|
def open_cover(self, **kwargs):
|
2018-01-25 16:31:38 +00:00
|
|
|
"""Open the cover."""
|
2016-08-24 01:23:18 +00:00
|
|
|
self.wink.set_state(1)
|
|
|
|
|
2018-02-11 17:20:28 +00:00
|
|
|
def set_cover_position(self, **kwargs):
|
2018-01-25 16:31:38 +00:00
|
|
|
"""Move the cover shutter to a specific position."""
|
2018-02-11 17:20:28 +00:00
|
|
|
position = kwargs.get(ATTR_POSITION)
|
|
|
|
self.wink.set_state(position/100)
|
2017-02-06 13:43:36 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
2018-01-25 16:31:38 +00:00
|
|
|
"""Return the current position of cover shutter."""
|
|
|
|
if self.wink.state() is not None:
|
|
|
|
return int(self.wink.state()*100)
|
2019-01-24 07:20:20 +00:00
|
|
|
return None
|
2017-02-06 13:43:36 +00:00
|
|
|
|
2016-08-24 01:23:18 +00:00
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
|
|
|
state = self.wink.state()
|
2017-02-06 13:43:36 +00:00
|
|
|
return bool(state == 0)
|