-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Lagute LW-12 Wifi LED control #13307
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2de4ebf
Added platform lw12wifi for Lagute LW-12 Wifi Lights
jaypikay ef5f015
Added lw12wifi to the list of omitted files to test
jaypikay b3c949d
Added lw12 module as new requirement for lw12wifi platform
jaypikay 087816c
Added configuration example docstring for platform lw12wifi
jaypikay 4376db0
Updating code according to review in PR:
jaypikay fe259e5
Further improvements to satisfy PR.
jaypikay d5fecc7
Check if the set effect is supported, otherwise revert to normal light.
jaypikay ce75f21
Added describing missing docstrings to all functions.
jaypikay 52ef268
Adopted code to work with HS color setting.
jaypikay bc92495
Syntactical change in comment.
jaypikay a543629
Removed redefinition of DOMAIN.
jaypikay f8a0f7b
Refactored lw12 controller setup: removed requirement for host and po…
jaypikay 97fbf6f
Rewritten supported feature setup to a more static expression.
jaypikay 0d8c2ac
Removed unused rgb_color property
jaypikay b99c33a
Fixed typo in comment for set_light_option
jaypikay 2ca9372
Changed RGB option validation schema
jaypikay d747674
Removed instance properties as config options
jaypikay 9e8fe2b
Removed optional settings to be more inline with code style.
jaypikay 1bd6bee
Removed unused option from config example
jaypikay cf76c39
Removal of unused import
jaypikay 57bd2fd
Added property to disable state polling for this entity.
jaypikay 09b89f7
Raise an exception if an unknown effect was selected.
jaypikay 895b2ab
Fixed an issue with the check for known effects.
jaypikay 1227a6a
As we do not need to set a default, use simple accessing by key.
jaypikay 4e1b8fc
Log if an unknown effect was selected.
jaypikay 5da9fe0
Added link to future documentation.
jaypikay 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,158 @@ | ||
| """ | ||
| Support for Lagute LW-12 WiFi LED Controller. | ||
|
|
||
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/light.lw12wifi/ | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.light import ( | ||
| ATTR_BRIGHTNESS, ATTR_EFFECT, ATTR_HS_COLOR, ATTR_TRANSITION, | ||
| Light, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, | ||
| SUPPORT_COLOR, SUPPORT_TRANSITION | ||
| ) | ||
| from homeassistant.const import ( | ||
| CONF_HOST, CONF_NAME, CONF_PORT | ||
| ) | ||
| import homeassistant.helpers.config_validation as cv | ||
| import homeassistant.util.color as color_util | ||
|
|
||
|
|
||
| REQUIREMENTS = ['lw12==0.9.2'] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| DEFAULT_NAME = 'LW-12 FC' | ||
| DEFAULT_PORT = 5000 | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, | ||
| vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Setup LW-12 WiFi LED Controller platform.""" | ||
| import lw12 | ||
|
|
||
| # Assign configuration variables. | ||
| name = config.get(CONF_NAME) | ||
| host = config.get(CONF_HOST) | ||
| port = config.get(CONF_PORT) | ||
| # Add devices | ||
| lw12_light = lw12.LW12Controller(host, port) | ||
| add_devices([LW12WiFi(name, lw12_light)]) | ||
|
|
||
|
|
||
| class LW12WiFi(Light): | ||
| """LW-12 WiFi LED Controller.""" | ||
|
|
||
| def __init__(self, name, lw12_light): | ||
| """Initialisation of LW-12 WiFi LED Controller. | ||
|
|
||
| Args: | ||
| name: Friendly name for this platform to use. | ||
| lw12_light: Instance of the LW12 controller. | ||
| """ | ||
| self._light = lw12_light | ||
| self._name = name | ||
| self._state = None | ||
| self._effect = None | ||
| self._rgb_color = [255, 255, 255] | ||
| self._brightness = 255 | ||
| # Setup feature list | ||
| self._supported_features = SUPPORT_BRIGHTNESS | SUPPORT_EFFECT \ | ||
| | SUPPORT_COLOR | SUPPORT_TRANSITION | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the display name of the controlled light.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def brightness(self): | ||
| """Return the brightness of the light.""" | ||
| return self._brightness | ||
|
|
||
| @property | ||
| def hs_color(self): | ||
| """Read back the hue-saturation of the light.""" | ||
| return color_util.color_RGB_to_hs(*self._rgb_color) | ||
|
|
||
| @property | ||
| def effect(self): | ||
| """Return current light effect.""" | ||
| if self._effect is None: | ||
| return None | ||
| return self._effect.replace('_', ' ').title() | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if light is on.""" | ||
| return self._state | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Return a list of supported features.""" | ||
| return self._supported_features | ||
|
|
||
| @property | ||
| def effect_list(self): | ||
| """Return a list of available effects. | ||
|
|
||
| Use the Enum element name for display. | ||
| """ | ||
| import lw12 | ||
| return [effect.name.replace('_', ' ').title() | ||
| for effect in lw12.LW12_EFFECT] | ||
|
|
||
| @property | ||
| def assumed_state(self) -> bool: | ||
| """Return True if unable to access real state of the entity.""" | ||
| return True | ||
|
|
||
| @property | ||
| def shoud_poll(self) -> bool: | ||
| """Return False to not poll the state of this entity.""" | ||
| return False | ||
|
|
||
| def turn_on(self, **kwargs): | ||
| """Instruct the light to turn on.""" | ||
| import lw12 | ||
| self._light.light_on() | ||
| if ATTR_HS_COLOR in kwargs: | ||
| self._rgb_color = color_util.color_hs_to_RGB( | ||
| *kwargs[ATTR_HS_COLOR]) | ||
| self._light.set_color(*self._rgb_color) | ||
| self._effect = None | ||
| if ATTR_BRIGHTNESS in kwargs: | ||
| self._brightness = kwargs.get(ATTR_BRIGHTNESS) | ||
| brightness = int(self._brightness / 255 * 100) | ||
| self._light.set_light_option(lw12.LW12_LIGHT.BRIGHTNESS, | ||
| brightness) | ||
| if ATTR_EFFECT in kwargs: | ||
| self._effect = kwargs[ATTR_EFFECT].replace(' ', '_').upper() | ||
| # Check if a known and supported effect was selected. | ||
| if self._effect in [eff.name for eff in lw12.LW12_EFFECT]: | ||
| # Selected effect is supported and will be applied. | ||
| self._light.set_effect(lw12.LW12_EFFECT[self._effect]) | ||
| else: | ||
| # Unknown effect was set, recover by disabling the effect | ||
| # mode and log an error. | ||
| _LOGGER.error("Unknown effect selected: %s", self._effect) | ||
| self._effect = None | ||
| if ATTR_TRANSITION in kwargs: | ||
| transition_speed = int(kwargs[ATTR_TRANSITION]) | ||
| self._light.set_light_option(lw12.LW12_LIGHT.FLASH, | ||
| transition_speed) | ||
| self._state = True | ||
|
|
||
| def turn_off(self, **kwargs): | ||
| """Instruct the light to turn off.""" | ||
| self._light.light_off() | ||
| self._state = False | ||
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
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.
Please add the property
should_polland have it returnFalseThere 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.
Might not be needed if #14229 gets merged before this PR.