HAP-python
HAP-python copied to clipboard
Global_setter for accessories
I think it might be useful to implement something like a global_setter for services. Those should get called when one or more char values of this service are about to be changed to provide an access point for end users.
The concrete case is an issue / bug with the HomeKit lightbulb service. When setting the light to a specific brightness in the Home app from the off state, HomeKit calls to char client_update_values, one for the state (on / off) and one for the brightness char.
Reacting to both with the currently used setter_callbacks could lead to flickering if say the light is first set to on (100%) and only then to the wanted brightness.
Links:
- https://github.com/home-assistant/home-assistant/issues/13768
- https://github.com/home-assistant/homebridge-homeassistant/issues/218
- https://github.com/nfarina/homebridge/issues/807
- https://github.com/snowdd1/homebridge-knx/issues/47
Update I've looked at the HAP doc, it might be better to implement it in the accessory class.
I see the problem. This can be handled in the setters for the bulb I guess (with a small wait before applying I suppose). How do you think it would be the most useful? How should the setter figure out that more than one char is about to be changed?
I though that using the accessory_dirver/set_characteristics method might work as an entry point. That way we can avoid using delays.
I did a little test and this is what this method is called with in this case:
# aid=2 --> Light
# iid=9 --> State (on/off)
# iid=10 --> Brightness
{'characteristics': [{'aid': 2, 'iid': 9, 'value': 1}, {'aid': 2, 'iid': 10, 'value': 60}]}
It should be fairly simple to call the hook method from that. Thought about passing a dictionary with the
{char_1: value, char_2: value}
where char_1 and char_2 are the char objects.
I should be able to have a PR for it this week.
I though that using the
accessory_dirver/set_characteristicsmethod might work as an entry point. That way we can avoid using delays. I did a little test and this is what this method is called with in this case:# aid=2 --> Light # iid=9 --> State (on/off) # iid=10 --> Brightness {'characteristics': [{'aid': 2, 'iid': 9, 'value': 1}, {'aid': 2, 'iid': 10, 'value': 60}]}It should be fairly simple to call the hook method from that. Thought about passing a dictionary with the
{char_1: value, char_2: value}where
char_1andchar_2are the char objects.I should be able to have a PR for it this week.
Any progress on that? Still having that annoying symptom on my end of lights hitting 100% before going to their set dim level when setting via Homekit
Hi. I’m still interested in the outcome of this issue as I understand it triggers an annoying bug in Home Assistant causing lights to go to 100% before going to desired brightness. My eyes! Let me know if I can help test any patches. Thank you.
@cwawak https://github.com/home-assistant/core/pull/32348
This was done in https://github.com/ikalchev/HAP-python/pull/373