-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Add new iGlo component #11171
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| """ | ||
| 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): | ||
|
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. expected 2 blank lines, found 1 |
||
| """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)]) | ||
|
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. Use I assume that there will be a exception of the device is not present. |
||
|
|
||
|
|
||
| class IGloLamp(Light): | ||
|
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. expected 2 blank lines, found 1 |
||
| """Representation of an iGlo light.""" | ||
|
|
||
| def __init__(self, name, host, port): | ||
| """Initialize the light.""" | ||
| from iglo import Lamp | ||
| self._name = name | ||
| self._host = host | ||
|
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. Not used. |
||
| self._port = port | ||
|
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. Dito. |
||
| self._lamp = Lamp(0, host, port) | ||
| self.update() | ||
|
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. See above.
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. See above. |
||
| self._on = True | ||
|
|
||
| @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 | ||
|
Contributor
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. 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.
Member
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. 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.
Contributor
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. Doing it this way will mean that examples for other lights do not work properly. It also breaks the But now you know where the problem is, once you notice :) |
||
|
|
||
| @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) | ||
| self._on = 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. You shouldn't change any instance attributes that store state in the turn on/off methods. The |
||
| if ATTR_BRIGHTNESS in kwargs: | ||
| self._brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) | ||
|
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. See above. |
||
| self._lamp.brightness(self._brightness) | ||
| return | ||
|
|
||
| if ATTR_RGB_COLOR in kwargs: | ||
| self._rgb = kwargs[ATTR_RGB_COLOR] | ||
|
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. See above. |
||
| self._lamp.rgb(*self._rgb) | ||
| return | ||
|
|
||
| if ATTR_COLOR_TEMP in kwargs: | ||
| self._color_temp = 255 - kwargs[ATTR_COLOR_TEMP] | ||
|
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. See above. |
||
| self._lamp.white(self._color_temp) | ||
| return | ||
|
|
||
| def turn_off(self, **kwargs): | ||
|
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. too many blank lines (2) |
||
| """Turn the light off.""" | ||
| self._on = False | ||
|
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. See above. |
||
| 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'] | ||
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.
SyntaxError: invalid syntax