2019-02-19 13:09:06 +00:00
|
|
|
"""Support for INSTEON fans via PowerLinc Modem."""
|
2018-02-25 19:13:39 +00:00
|
|
|
import logging
|
|
|
|
|
2020-05-17 13:27:38 +00:00
|
|
|
from pyinsteon.constants import FanSpeed
|
|
|
|
|
2019-02-19 13:09:06 +00:00
|
|
|
from homeassistant.components.fan import (
|
2020-05-17 13:27:38 +00:00
|
|
|
DOMAIN,
|
2019-07-31 19:25:30 +00:00
|
|
|
SPEED_HIGH,
|
|
|
|
SPEED_LOW,
|
|
|
|
SPEED_MEDIUM,
|
|
|
|
SPEED_OFF,
|
|
|
|
SUPPORT_SET_SPEED,
|
|
|
|
FanEntity,
|
|
|
|
)
|
2019-02-19 13:09:06 +00:00
|
|
|
|
2020-01-30 09:47:44 +00:00
|
|
|
from .insteon_entity import InsteonEntity
|
2020-05-17 13:27:38 +00:00
|
|
|
from .utils import async_add_insteon_entities
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-02-19 13:09:06 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2020-05-17 13:27:38 +00:00
|
|
|
FAN_SPEEDS = [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH]
|
|
|
|
SPEED_TO_VALUE = {
|
|
|
|
SPEED_OFF: FanSpeed.OFF,
|
|
|
|
SPEED_LOW: FanSpeed.LOW,
|
|
|
|
SPEED_MEDIUM: FanSpeed.MEDIUM,
|
|
|
|
SPEED_HIGH: FanSpeed.HIGH,
|
|
|
|
}
|
2018-02-25 19:13:39 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Set up the INSTEON entity class for the hass platform."""
|
|
|
|
async_add_insteon_entities(
|
|
|
|
hass, DOMAIN, InsteonFanEntity, async_add_entities, discovery_info
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-02-25 19:13:39 +00:00
|
|
|
|
|
|
|
|
2020-05-17 13:27:38 +00:00
|
|
|
class InsteonFanEntity(InsteonEntity, FanEntity):
|
|
|
|
"""An INSTEON fan entity."""
|
2018-02-25 19:13:39 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def speed(self) -> str:
|
|
|
|
"""Return the current speed."""
|
2020-05-17 13:27:38 +00:00
|
|
|
if self._insteon_device_group.value == FanSpeed.HIGH:
|
|
|
|
return SPEED_HIGH
|
|
|
|
if self._insteon_device_group.value == FanSpeed.MEDIUM:
|
|
|
|
return SPEED_MEDIUM
|
|
|
|
if self._insteon_device_group.value == FanSpeed.LOW:
|
|
|
|
return SPEED_LOW
|
|
|
|
return SPEED_OFF
|
2018-02-25 19:13:39 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def speed_list(self) -> list:
|
|
|
|
"""Get the list of available speeds."""
|
|
|
|
return FAN_SPEEDS
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self) -> int:
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_SET_SPEED
|
|
|
|
|
2018-10-01 06:59:45 +00:00
|
|
|
async def async_turn_on(self, speed: str = None, **kwargs) -> None:
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Turn on the fan."""
|
2018-02-25 19:13:39 +00:00
|
|
|
if speed is None:
|
|
|
|
speed = SPEED_MEDIUM
|
2018-10-01 06:59:45 +00:00
|
|
|
await self.async_set_speed(speed)
|
2018-02-25 19:13:39 +00:00
|
|
|
|
2018-10-01 06:59:45 +00:00
|
|
|
async def async_turn_off(self, **kwargs) -> None:
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Turn off the fan."""
|
|
|
|
await self._insteon_device.async_fan_off()
|
2018-02-25 19:13:39 +00:00
|
|
|
|
2018-10-01 06:59:45 +00:00
|
|
|
async def async_set_speed(self, speed: str) -> None:
|
2018-02-25 19:13:39 +00:00
|
|
|
"""Set the speed of the fan."""
|
2020-05-17 13:27:38 +00:00
|
|
|
fan_speed = SPEED_TO_VALUE[speed]
|
|
|
|
if fan_speed == FanSpeed.OFF:
|
|
|
|
await self._insteon_device.async_fan_off()
|
2018-02-25 19:13:39 +00:00
|
|
|
else:
|
2020-05-17 13:27:38 +00:00
|
|
|
await self._insteon_device.async_fan_on(on_level=fan_speed)
|