Added osramlightify groups.#7376
Conversation
Allows you to make use of the build in osram lightify groups. Group states get handeled similar as in the case of phillips hue. A lightify group shows up as light in the homeassistant webinterface. If one light of the group is on, the complete group is considered to be on. To use this feature, first define some groups within your lighrify bridge, then set add `allow_lightify_groups=true` to you osramlightify config. It might look like: ````yaml - platform: osramlightify host: IP-ADDRES allow_lightify_groups: true ```
|
@deisi, thanks for your PR! By analyzing the history of the files in this pull request, we identified @olimpiurob, @tfriedel and @tchellomello to be potential reviewers. |
| MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) | ||
| MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100) | ||
| CONF_ALLOW_LIGHTIFY_GROUPS = "allow_lightify_groups" | ||
| DEFAULT_ALLOW_LIGHTIFY_GROUPS = False |
| bridge.update_all_light_status() | ||
| bridge.update_group_list() | ||
| except socket.error: | ||
| errno, errstr = sys.exc_info()[:2] |
There was a problem hiding this comment.
Wait, what are you doing here? You can just catch the actual error instead of hacking around it using exception frames:
except socket.error as err:
if isinstance(err, socket.timeout):
_LOGGER.error(…)However, you are now swallowing all the not timeout related errors which means that something might go wrong but no one will know.
There was a problem hiding this comment.
In python 3 socket.error is an alias of OSError.
There was a problem hiding this comment.
Instead of checking the error type you can have multiple except statements. First one that catches TimeoutError, then a general one for OSError.
|
|
||
| self._luminary.set_onoff(0) | ||
| self._state = False | ||
| self.schedule_update_ha_state() |
There was a problem hiding this comment.
Can you remove this line? it's not needed since should_poll is defaulting to True and so this is automatically called.
There was a problem hiding this comment.
You mean the self._state = False ?
Well yes I can remove it, but I saw, that without it, HA gets a lot more unresponsive, because otherwise it the GUI jumps back to the on state and then after a couple of seconds it jumps back to off. If that is okay, I'm willing to remove it, I just felt it works better with.
There was a problem hiding this comment.
It's not something that we should fix in a platform but instead fix for everyone at once. We already wait 2 seconds for a status update: https://github.com/home-assistant/home-assistant-polymer/blob/master/src/components/entity/ha-entity-toggle.html#L135-L136
Please remove this line.
|
|
||
| class OsramLightifyLight(Light): | ||
| """Representation of an Osram Lightify Light.""" | ||
| class Luminary(): |
There was a problem hiding this comment.
Why not have this class already inherit from Light ?
|
|
||
| The group is on, if any of the lights in on. | ||
| """ | ||
| states = [] |
There was a problem hiding this comment.
This is inefficient as you now first have to gather all results before checking if any are True.
lights = self._bridge.lights()
return any(lights[light_id].on() for light_id in self._light_ids)| super().update() | ||
| self._light_ids = self._luminary.lights() | ||
| self._light = self._bridge.lights()[self._light_ids[0]] | ||
| self._brightness = int(self._light.lum() * 2.25) |
| """Update group status.""" | ||
| super().update() | ||
| self._light_ids = self._luminary.lights() | ||
| self._light = self._bridge.lights()[self._light_ids[0]] |
There was a problem hiding this comment.
Why are you storing the light as an instance variable?
There was a problem hiding this comment.
looking at it you are right I don't need to. I will remove it.
| def update(self): | ||
| """Update group status.""" | ||
| super().update() | ||
| self._light_ids = self._luminary.lights() |
There was a problem hiding this comment.
What is self._luminiary and is it only used to fetch the lights?
I think that things are getting very complicated because of the inheritance.
There was a problem hiding this comment.
I think that things are getting very complicated because of the inheritance.
I first stared out without, but my code became 90% redundant and so I splittend i t up. The only difference between the two is the update and get_state method.
What is
self._luminiaryand is it only used to fetch the lights?
Well its the main interface to the lightify API. Essentially all communication with the lights goes through the self._luminary obj. It is called like this, because it is the name of the class within the lightify API itself. I use it, because it is the common ground between lights and groups of lights just like throughout this module as well.
|
Can you also remove all the debug statements in properties ? It is slowing down Hass a lot and it's unnecessary. |
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/light.osramlightify/ | ||
| """ | ||
| import sys |
| def setup_bridge(bridge, add_devices_callback): | ||
| """Set up the Lightify bridge.""" | ||
| def setup_bridge(bridge, add_devices_callback, add_groups): | ||
| """Setup the Lightify bridge.""" |
There was a problem hiding this comment.
If I remove it, the DEFAULT_ALLOW_LIGHTIFY_GROUPS = True config becomes useless.
|
This is ok to merge when the comment change has been reversed and linting has been fixed 🎉 |
|
I tried to rebase it, but I coudnt rebase anything before the merge. Shoud I make a new PR or is it okay the way it is? |
|
You should revert the change to the doc string as @balloob asked, before we can merge. See comment above. Just make a new commit where you change it back to like it was before. |
|
Awesome, this was a Feature Request I really wanted! Thank you! <3 |
|
:) I wanted it as well, and so I made it.
chimpy <notifications@github.com> writes:
… Awesome, this was a Feature Request I really wanted! Thank you! <3
|
|
This change breaks my Home Assistant setup. Each time I start HA the value of self._light_ids[0] seems to be incorrect but the error does not always happen with the same light. Maybe there's a discrepancy between the bridge and the states in HA. I've rolled back to 0.43.2 for now and the problem went away. |
|
Hey Ian
Would you be willing to help me fix it? I cant reproduce it, so I need
somebody to test a fix and probably give me some debug output.
Cheers.
Ian Young <notifications@github.com> writes:
… This change breaks my Home Assistant setup. Each time I start HA the value of self._light_ids[0] seems to be incorrect but the error does not always happen with the same light. Maybe there's a discrepancy between the bridge and the states in HA. I've rolled back to 0.43.2 for now and the problem went away.
`2017-05-10 13:31:46 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform osramlightify
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 155, in _async_setup_platform
entity_platform.schedule_add_entities, discovery_info
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/asyncio/futures.py", line 358, in __iter__
yield self # This tells Task to wait for completion.
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/asyncio/tasks.py", line 290, in _wakeup
future.result()
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/opt/rh/rh-python35/root/usr/lib64/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/osramlightify.py", line 60, in setup_platform
setup_bridge(bridge, add_devices, add_groups)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/osramlightify.py", line 106, in setup_bridge
update_lights()
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 303, in wrapper
result = method(*args, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 303, in wrapper
result = method(*args, **kwargs)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/osramlightify.py", line 97, in update_lights
update_lights)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/osramlightify.py", line 268, in __init__
super().__init__(group, update_lights)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/osramlightify.py", line 121, in __init__
self.update()
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/osramlightify.py", line 282, in update
light = self._bridge.lights()[self._light_ids[0]]
KeyError: 9518399593890067646`
|
|
I won't be available until Wednesday but I can help you after then. |
|
Please open an issue and discuss a potential fix there. |
Allows you to make use of the build in osram lightify groups. Group states get
handeled similar as in the case of phillips hue. A lightify group shows up as
light in the homeassistant webinterface. If one light of the
group is on, the complete group is considered to be on.
To use this feature, first define some groups within your lighrify bridge, then
add
allow_lightify_groups=trueto you osramlightify config.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.If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass