-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add new iGlo component #11171
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
Add new iGlo component #11171
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,124 @@ | ||
| """ | ||
| Support for lights under the iGlo brand. | ||
|
|
||
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/light.iglo/ | ||
| """ | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_PORT) | ||
| from homeassistant.components.light import ( | ||
| ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP, | ||
| SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, | ||
| Light, PLATFORM_SCHEMA | ||
| ) | ||
|
|
||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| REQUIREMENTS = ['iglo==1.0.0'] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DEFAULT_NAME = 'iGlo Light' | ||
| DEFAULT_PORT = 8080 | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, | ||
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.string, | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the iGlo lighs.""" | ||
| host = config.get(CONF_HOST) | ||
| name = config.get(CONF_NAME) | ||
| port = config.get(CONF_PORT) | ||
| add_devices([IGloLamp(name, host, port)], True) | ||
|
|
||
|
|
||
| class IGloLamp(Light): | ||
| """Representation of an iGlo light.""" | ||
|
|
||
| def __init__(self, name, host, port): | ||
| """Initialize the light.""" | ||
| from iglo import Lamp | ||
| self._name = name | ||
| self._lamp = Lamp(0, host, port) | ||
| self._on = True | ||
| self._brightness = 255 | ||
| self._rgb = (0, 0, 0) | ||
| self._color_temp = 0 | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the light.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def brightness(self): | ||
| """Return the brightness of this light between 0..255.""" | ||
| return int((self._brightness / 200.0) * 255) | ||
|
|
||
| @property | ||
| def color_temp(self): | ||
| """Return the color temperature.""" | ||
| return self._color_temp | ||
|
|
||
| @property | ||
| def min_mireds(self): | ||
| """Return the coldest color_temp that this light supports.""" | ||
| return 1 | ||
|
|
||
| @property | ||
| def max_mireds(self): | ||
| """Return the warmest color_temp that this light supports.""" | ||
| return 255 | ||
|
|
||
| @property | ||
| def rgb_color(self): | ||
| """Return the RGB value.""" | ||
| return self._rgb | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Flag supported features.""" | ||
| return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if light is on.""" | ||
| return self._on | ||
|
|
||
| def turn_on(self, **kwargs): | ||
| """Turn the light on.""" | ||
| if not self._on: | ||
| self._lamp.switch(True) | ||
| if ATTR_BRIGHTNESS in kwargs: | ||
| brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) | ||
| self._lamp.brightness(brightness) | ||
| return | ||
|
|
||
| if ATTR_RGB_COLOR in kwargs: | ||
| rgb = kwargs[ATTR_RGB_COLOR] | ||
| self._lamp.rgb(*rgb) | ||
| return | ||
|
|
||
| if ATTR_COLOR_TEMP in kwargs: | ||
| color_temp = 255 - kwargs[ATTR_COLOR_TEMP] | ||
| self._lamp.white(color_temp) | ||
| return | ||
|
|
||
| def turn_off(self, **kwargs): | ||
| """Turn the light off.""" | ||
| self._lamp.switch(False) | ||
|
|
||
| def update(self): | ||
| """Update light status.""" | ||
| state = self._lamp.state() | ||
| self._on = state['on'] | ||
| self._brightness = state['brightness'] | ||
| self._rgb = state['rgb'] | ||
| self._color_temp = 255 - state['white'] | ||
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.
I just saw this merged so I know I am too late to the party.
Anyway, this is supposed to be in mired, the unknown "reciprocal megakelvin" unit.
You find the mired value with this formula: 1000000/kelvin. So if the light does 7000 Kelvin as its coldest white, the min_mired value should be 143.
Same goes for max_mireds and color_temp.
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.
I don't really understand the mirad thing, but the lights accept a colour temp value between 1 and 255 to change between warm and cool white. Maybe I will look into it more once I move back into the part of my house with my new lights and start using this on my main HA.
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.
Doing it this way will mean that examples for other lights do not work properly. It also breaks the
kelvinalias for white temperature.But now you know where the problem is, once you notice :)