mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00

* Update attr to property and default state method * State prop is defined in parent class * Demo platform fan * PyDoc * Copy-pasta artifact * PyDoc * Linting * Raise error if turn_off and turn_on not implemented * Update demo platform * Initial unit test commit * Readability * Unneeded typing * Should inherit from fan entity * Turn off polling * Initial oscillating flag * Pass HASS into demo * Typing * Invoke set_speed instead of setting directly * Service update * Update demo tests * Forgot to block after service call. * linting * Test to make sure not implemented is thrown * Is On Method test * Update const to match string * Update services yaml * Toggle method * Toggle service * Typing * TYPE O * Attribute check * Type-o * Type-o * Put typing back * ToggleEntity * Linting * Linting * Oops * Stale prints * Demo support
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
"""
|
|
Support for Insteon FanLinc.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/fan.insteon/
|
|
"""
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.fan import (FanEntity, SUPPORT_SET_SPEED,
|
|
SPEED_OFF, SPEED_LOW, SPEED_MED,
|
|
SPEED_HIGH)
|
|
from homeassistant.components.insteon_hub import (InsteonDevice, INSTEON,
|
|
filter_devices)
|
|
from homeassistant.const import STATE_UNKNOWN
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
DEVICE_CATEGORIES = [
|
|
{
|
|
'DevCat': 1,
|
|
'SubCat': [46]
|
|
}
|
|
]
|
|
|
|
DEPENDENCIES = ['insteon_hub']
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
"""Setup the Insteon Hub fan platform."""
|
|
devs = []
|
|
for device in filter_devices(INSTEON.devices, DEVICE_CATEGORIES):
|
|
devs.append(InsteonFanDevice(device))
|
|
add_devices(devs)
|
|
|
|
|
|
class InsteonFanDevice(InsteonDevice, FanEntity):
|
|
"""Represet an insteon fan device."""
|
|
|
|
def __init__(self, node: object) -> None:
|
|
"""Initialize the device."""
|
|
super(InsteonFanDevice, self).__init__(node)
|
|
self.speed = STATE_UNKNOWN # Insteon hub can't get state via REST
|
|
|
|
def turn_on(self, speed: str=None):
|
|
"""Turn the fan on."""
|
|
self.set_speed(speed if speed else SPEED_MED)
|
|
|
|
def turn_off(self):
|
|
"""Turn the fan off."""
|
|
self.set_speed(SPEED_OFF)
|
|
|
|
def set_speed(self, speed: str) -> None:
|
|
"""Set the fan speed."""
|
|
if self._send_command('fan', payload={'speed', speed}):
|
|
self.speed = speed
|
|
|
|
@property
|
|
def supported_features(self) -> int:
|
|
"""Get the supported features for device."""
|
|
return SUPPORT_SET_SPEED
|
|
|
|
@property
|
|
def speed_list(self) -> list:
|
|
"""Get the available speeds for the fan."""
|
|
return [SPEED_OFF, SPEED_LOW, SPEED_MED, SPEED_HIGH]
|