HAP-python icon indicating copy to clipboard operation
HAP-python copied to clipboard

Global_setter for accessories

Open cdce8p opened this issue 7 years ago • 6 comments
trafficstars

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.

cdce8p avatar Apr 17 '18 21:04 cdce8p

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?

ikalchev avatar Apr 18 '18 05:04 ikalchev

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.

cdce8p avatar Apr 18 '18 09:04 cdce8p

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.

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

andrewatwood avatar Aug 15 '19 20:08 andrewatwood

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 avatar Mar 02 '20 23:03 cwawak

@cwawak https://github.com/home-assistant/core/pull/32348

bdraco avatar Mar 02 '20 23:03 bdraco

This was done in https://github.com/ikalchev/HAP-python/pull/373

bdraco avatar Aug 22 '21 20:08 bdraco