-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Add fan support to lutron_caseta #24770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5611b6e
Added fan support to the lutron_caseta component. Additional changes …
djj211 fddf138
Added SSL Config and tidying up
djj211 8d6e706
Further tidying up
djj211 78ce9e4
More Tidying
djj211 5dae49d
More Tidying
djj211 f6a3b2c
Fixing small pylint issues
djj211 5ba3c83
Updates from PR and removal of config
djj211 34d01ab
Fixing messed up indent
djj211 ca4740b
Removed MediumHigh Speed
djj211 d2dbb5a
Added Speed list and removed setup_platform return
djj211 0091720
Added Speed list and removed setup_platform return
djj211 f9c8074
Fixing Spacing
djj211 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,82 @@ | ||
| """Support for Lutron Caseta fans.""" | ||
| import logging | ||
|
|
||
| from homeassistant.components.fan import ( | ||
| SUPPORT_SET_SPEED, FanEntity, DOMAIN) | ||
|
|
||
| from . import LUTRON_CASETA_SMARTBRIDGE, LutronCasetaDevice | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| LUTRON_SPEED_OFF = 'Off' | ||
| LUTRON_SPEED_LOW = 'Low' | ||
| LUTRON_SPEED_MEDIUM = 'Medium' | ||
| LUTRON_SPEED_MEDIUMHIGH = "MediumHigh" | ||
| LUTRON_SPEED_HIGH = 'High' | ||
|
|
||
|
|
||
| async def async_setup_platform( | ||
| hass, config, async_add_entities, discovery_info=None): | ||
| """Set up Lutron fan.""" | ||
| devs = [] | ||
| bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE] | ||
| fan_devices = bridge.get_devices_by_domain(DOMAIN) | ||
|
|
||
| for fan_device in fan_devices: | ||
| dev = LutronCasetaFan(fan_device, bridge) | ||
| devs.append(dev) | ||
|
|
||
| async_add_entities(devs, True) | ||
| return True | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing is checking this return value. We can remove the statement.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MartinHjelmare return value removed. |
||
|
|
||
|
|
||
| class LutronCasetaFan(LutronCasetaDevice, FanEntity): | ||
| """Representation of a Lutron Caseta fan. Including Fan Speed.""" | ||
|
|
||
| @property | ||
| def speed(self) -> str: | ||
| """Return the current speed.""" | ||
| return self._state["fan_speed"] | ||
|
|
||
| @property | ||
| def speed_list(self) -> list: | ||
| """Get the list of available speeds. | ||
|
|
||
| Note: The default Hass Speeds were all lower case | ||
| and missing MediumHigh. Lutron Case and fan | ||
| speeds specified instead. | ||
| """ | ||
| return [LUTRON_SPEED_OFF, LUTRON_SPEED_LOW, LUTRON_SPEED_MEDIUM, | ||
| LUTRON_SPEED_MEDIUMHIGH, LUTRON_SPEED_HIGH] | ||
|
|
||
| @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 = LUTRON_SPEED_MEDIUMHIGH | ||
| await self.async_set_speed(speed) | ||
|
|
||
| async def async_turn_off(self, **kwargs): | ||
| """Turn the fan off.""" | ||
| await self.async_set_speed(LUTRON_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) | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if device is on.""" | ||
| return self._state["fan_speed"] in [LUTRON_SPEED_LOW, | ||
| LUTRON_SPEED_MEDIUM, | ||
| LUTRON_SPEED_MEDIUMHIGH, | ||
| LUTRON_SPEED_HIGH] | ||
|
|
||
| async def async_update(self): | ||
| """Update when forcing a refresh of the device.""" | ||
| self._state = self._smartbridge.get_device_by_id(self._device_id) | ||
| _LOGGER.debug("State of this lutron fan device is %s", self._state) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only speeds in the base fan component are allowed to be returned in the speed list or accepted as set speed argument.
We can build two dicts to map between home assistant speeds and device speeds. Make a best effort. It might not be a perfect map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinHjelmare I added the two dictionaries to map between speeds and devices (modeled off some other fan integrations). The base fan component does not have a "MediumHigh" field to map to. Not sure if you prefer that I take the approach that I did, or if you prefer that I add "mediumhigh" to the base component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add new speeds without approval in an issue in our architecture repo.
Please remove all speeds not currently in the base fan component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinHjelmare Understood. I will open an issue. I removed the speed not in the base fan component.