Add new iGlo component#11171
Conversation
| return | ||
|
|
||
|
|
||
| def turn_off(self, **kwargs): |
| port = config.get(CONF_PORT) | ||
| add_devices([IGloLamp(name, host, port)]) | ||
|
|
||
| class IGloLamp(Light): |
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.string, | ||
| }) | ||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): |
| from homeassistant.components.light import ( | ||
| ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP, | ||
| SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR | ||
| Light, PLATFORM_SCHEMA |
Add extra blank lines
| """Initialize the light.""" | ||
| from iglo import Lamp | ||
| self._name = name | ||
| self._host = host |
| from iglo import Lamp | ||
| self._name = name | ||
| self._host = host | ||
| self._port = port |
| self._host = host | ||
| self._port = port | ||
| self._lamp = Lamp(0, host, port) | ||
| self.update() |
| host = config.get(CONF_HOST) | ||
| name = config.get(CONF_NAME) | ||
| port = config.get(CONF_PORT) | ||
| add_devices([IGloLamp(name, host, port)]) |
There was a problem hiding this comment.
Use True as second parameter.
I assume that there will be a exception of the device is not present.
| self._host = host | ||
| self._port = port | ||
| self._lamp = Lamp(0, host, port) | ||
| self.update() |
| """Turn the light on.""" | ||
| if not self._on: | ||
| self._lamp.switch(True) | ||
| self._on = True |
There was a problem hiding this comment.
You shouldn't change any instance attributes that store state in the turn on/off methods. The update method will be called after turn_on or turn_off is called, since this is a polling entity, so state will be updated that way.
| self._lamp.switch(True) | ||
| self._on = True | ||
| if ATTR_BRIGHTNESS in kwargs: | ||
| self._brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) |
| return | ||
|
|
||
| if ATTR_RGB_COLOR in kwargs: | ||
| self._rgb = kwargs[ATTR_RGB_COLOR] |
| return | ||
|
|
||
| if ATTR_COLOR_TEMP in kwargs: | ||
| self._color_temp = 255 - kwargs[ATTR_COLOR_TEMP] |
|
|
||
| def turn_off(self, **kwargs): | ||
| """Turn the light off.""" | ||
| self._on = False |
Remove unused variables Update before add
|
Thanks for the tips @fabaff & @MartinHjelmare |
| @property | ||
| def min_mireds(self): | ||
| """Return the coldest color_temp that this light supports.""" | ||
| return 1 |
There was a problem hiding this comment.
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.
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.
Doing it this way will mean that examples for other lights do not work properly. It also breaks the kelvin alias for white temperature.
But now you know where the problem is, once you notice :)
Description:
Adding support for new iGlo component
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4222
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.