2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Wink fans."""
|
2019-10-10 16:51:28 +00:00
|
|
|
import pywink
|
|
|
|
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.components.fan import (
|
2019-07-31 19:25:30 +00:00
|
|
|
SPEED_HIGH,
|
|
|
|
SPEED_LOW,
|
|
|
|
SPEED_MEDIUM,
|
|
|
|
SUPPORT_DIRECTION,
|
|
|
|
SUPPORT_SET_SPEED,
|
|
|
|
FanEntity,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import DOMAIN, WinkDevice
|
2017-05-13 18:09:00 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SPEED_AUTO = "auto"
|
|
|
|
SPEED_LOWEST = "lowest"
|
2017-07-19 22:27:39 +00:00
|
|
|
SUPPORTED_FEATURES = SUPPORT_DIRECTION + SUPPORT_SET_SPEED
|
|
|
|
|
2017-01-14 06:08:13 +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."""
|
2017-01-14 06:08:13 +00:00
|
|
|
|
2017-02-02 06:43:12 +00:00
|
|
|
for fan in pywink.get_fans():
|
2019-07-31 19:25:30 +00:00
|
|
|
if fan.object_id() + fan.name() not in hass.data[DOMAIN]["unique_ids"]:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([WinkFanDevice(fan, hass)])
|
2017-01-14 06:08:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WinkFanDevice(WinkDevice, FanEntity):
|
|
|
|
"""Representation of a Wink fan."""
|
|
|
|
|
2018-10-01 06:59:45 +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"]["fan"].append(self)
|
2017-05-13 18:09:00 +00:00
|
|
|
|
2018-07-30 11:44:31 +00:00
|
|
|
def set_direction(self, direction: str) -> None:
|
2017-01-14 06:08:13 +00:00
|
|
|
"""Set the direction of the fan."""
|
|
|
|
self.wink.set_fan_direction(direction)
|
|
|
|
|
2018-07-30 11:44:31 +00:00
|
|
|
def set_speed(self, speed: str) -> None:
|
2017-01-14 06:08:13 +00:00
|
|
|
"""Set the speed of the fan."""
|
2017-07-19 22:27:39 +00:00
|
|
|
self.wink.set_state(True, speed)
|
2017-01-14 06:08:13 +00:00
|
|
|
|
2018-07-30 11:44:31 +00:00
|
|
|
def turn_on(self, speed: str = None, **kwargs) -> None:
|
2017-01-14 06:08:13 +00:00
|
|
|
"""Turn on the fan."""
|
2017-07-19 22:27:39 +00:00
|
|
|
self.wink.set_state(True, speed)
|
2017-01-14 06:08:13 +00:00
|
|
|
|
2018-07-30 11:44:31 +00:00
|
|
|
def turn_off(self, **kwargs) -> None:
|
2017-01-14 06:08:13 +00:00
|
|
|
"""Turn off the fan."""
|
|
|
|
self.wink.set_state(False)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the entity is on."""
|
|
|
|
return self.wink.state()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def speed(self) -> str:
|
|
|
|
"""Return the current speed."""
|
|
|
|
current_wink_speed = self.wink.current_fan_speed()
|
|
|
|
if SPEED_AUTO == current_wink_speed:
|
|
|
|
return SPEED_AUTO
|
|
|
|
if SPEED_LOWEST == current_wink_speed:
|
|
|
|
return SPEED_LOWEST
|
|
|
|
if SPEED_LOW == current_wink_speed:
|
|
|
|
return SPEED_LOW
|
|
|
|
if SPEED_MEDIUM == current_wink_speed:
|
|
|
|
return SPEED_MEDIUM
|
|
|
|
if SPEED_HIGH == current_wink_speed:
|
|
|
|
return SPEED_HIGH
|
2019-01-24 07:20:20 +00:00
|
|
|
return None
|
2017-01-14 06:08:13 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_direction(self):
|
|
|
|
"""Return direction of the fan [forward, reverse]."""
|
|
|
|
return self.wink.current_fan_direction()
|
|
|
|
|
|
|
|
@property
|
2018-07-30 11:44:31 +00:00
|
|
|
def speed_list(self) -> list:
|
2017-01-14 06:08:13 +00:00
|
|
|
"""Get the list of available speeds."""
|
|
|
|
wink_supported_speeds = self.wink.fan_speeds()
|
|
|
|
supported_speeds = []
|
|
|
|
if SPEED_AUTO in wink_supported_speeds:
|
|
|
|
supported_speeds.append(SPEED_AUTO)
|
|
|
|
if SPEED_LOWEST in wink_supported_speeds:
|
|
|
|
supported_speeds.append(SPEED_LOWEST)
|
|
|
|
if SPEED_LOW in wink_supported_speeds:
|
|
|
|
supported_speeds.append(SPEED_LOW)
|
|
|
|
if SPEED_MEDIUM in wink_supported_speeds:
|
|
|
|
supported_speeds.append(SPEED_MEDIUM)
|
|
|
|
if SPEED_HIGH in wink_supported_speeds:
|
|
|
|
supported_speeds.append(SPEED_HIGH)
|
|
|
|
return supported_speeds
|
2017-07-19 22:27:39 +00:00
|
|
|
|
|
|
|
@property
|
2018-07-30 11:44:31 +00:00
|
|
|
def supported_features(self) -> int:
|
2017-07-19 22:27:39 +00:00
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORTED_FEATURES
|