Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fan support to lutron_caseta (#29033)
* Adding lutron_caseta fan controller. Updated to pylutron 0.5.1 * Accidental import remain * updating for black formatting * Fix blank spaces * Moving third party import * update to 0.5.1 to pass checks * fix deletion of new line * Update fan.py * Update with dev branch, update from comments, added mediumhigh
- Loading branch information
1 parent
f1a4e21
commit 665613e
Showing
2 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"""Support for Lutron Caseta fans.""" | ||
import logging | ||
|
||
from pylutron_caseta import FAN_OFF, FAN_LOW, FAN_MEDIUM, FAN_MEDIUM_HIGH, FAN_HIGH | ||
|
||
from homeassistant.components.fan import ( | ||
SUPPORT_SET_SPEED, | ||
FanEntity, | ||
DOMAIN, | ||
SPEED_HIGH, | ||
SPEED_LOW, | ||
SPEED_MEDIUM, | ||
SPEED_OFF, | ||
) | ||
|
||
from . import LUTRON_CASETA_SMARTBRIDGE, LutronCasetaDevice | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
VALUE_TO_SPEED = { | ||
None: SPEED_OFF, | ||
FAN_OFF: SPEED_OFF, | ||
FAN_LOW: SPEED_LOW, | ||
FAN_MEDIUM: SPEED_MEDIUM, | ||
FAN_MEDIUM_HIGH: SPEED_MEDIUM, | ||
FAN_HIGH: SPEED_HIGH, | ||
} | ||
|
||
SPEED_TO_VALUE = { | ||
SPEED_OFF: FAN_OFF, | ||
SPEED_LOW: FAN_LOW, | ||
SPEED_MEDIUM: FAN_MEDIUM, | ||
SPEED_HIGH: FAN_HIGH, | ||
} | ||
|
||
FAN_SPEEDS = [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] | ||
|
||
|
||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): | ||
"""Set up Lutron fan.""" | ||
entities = [] | ||
bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE] | ||
fan_devices = bridge.get_devices_by_domain(DOMAIN) | ||
|
||
for fan_device in fan_devices: | ||
entity = LutronCasetaFan(fan_device, bridge) | ||
entities.append(entity) | ||
|
||
async_add_entities(entities, True) | ||
|
||
|
||
class LutronCasetaFan(LutronCasetaDevice, FanEntity): | ||
"""Representation of a Lutron Caseta fan. Including Fan Speed.""" | ||
|
||
@property | ||
def speed(self) -> str: | ||
"""Return the current speed.""" | ||
return VALUE_TO_SPEED[self._device["fan_speed"]] | ||
|
||
@property | ||
def speed_list(self) -> list: | ||
"""Get the list of available speeds.""" | ||
return FAN_SPEEDS | ||
|
||
@property | ||
def supported_features(self) -> int: | ||
"""Flag supported features. Speed Only.""" | ||
return SUPPORT_SET_SPEED | ||
|
||
async def async_turn_on(self, speed: str = None, **kwargs): | ||
"""Turn the fan on.""" | ||
if speed is None: | ||
speed = SPEED_MEDIUM | ||
await self.async_set_speed(speed) | ||
|
||
async def async_turn_off(self, **kwargs): | ||
"""Turn the fan off.""" | ||
await self.async_set_speed(SPEED_OFF) | ||
|
||
async def async_set_speed(self, speed: str) -> None: | ||
"""Set the speed of the fan.""" | ||
self._smartbridge.set_fan(self.device_id, SPEED_TO_VALUE[speed]) | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if device is on.""" | ||
return VALUE_TO_SPEED[self._device["fan_speed"]] in [ | ||
SPEED_LOW, | ||
SPEED_MEDIUM, | ||
SPEED_HIGH, | ||
] | ||
|
||
async def async_update(self): | ||
"""Update when forcing a refresh of the device.""" | ||
self._device = self._smartbridge.get_device_by_id(self.device_id) | ||
_LOGGER.debug("State of this lutron fan device is %s", self._device) |