Migrate homekit_controller light to color_mode#69261
Conversation
|
Hey there @Jc2k, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( |
| if self.service.has(CharacteristicsTypes.HUE): | ||
| return COLOR_MODE_HS | ||
|
|
||
| if self.service.has(CharacteristicsTypes.SATURATION): | ||
| return COLOR_MODE_HS | ||
|
|
||
| if self.service.has(CharacteristicsTypes.COLOR_TEMPERATURE): | ||
| return COLOR_MODE_COLOR_TEMP |
There was a problem hiding this comment.
This does not change the behavior compared to without this PR because it would always report a non-None hs color for lights supporting hue/saturation which is interpreted as color mode hs by the base entity.
However, for lights which support both hs and white mode it would be better to report according to the light's state.
I did not immediately find anything useful in the library though. Any idea, @Jc2k , @bdraco?
There was a problem hiding this comment.
HomeKit (at least as defined in the public spec (https://developer.apple.com/file/?file=homekitspecification&agree=true)) doesn't have the concept of an active color mode. You can use h/s and you can use color temp. It has the characteristics you can see here, and thats it. There's no way to indicate which color mode is currently in use.
Sometimes you can figure out a bit more from the open source example code. There are some notes here:
Again, theres no characteristic to indicate a color mode there.
The HomeKit R2 spec explicitly states that the Color Temperature char must not be used for lamps which support color.
Does that help?
There was a problem hiding this comment.
OK, I see. I'll add a comment in the code stating that's the case.
There was a problem hiding this comment.
The situation has changed a bit in iOS 13+
The spec says that you're not supposed to have color and color temperature at the same time, but in practice even certified devices implement that now. Apple seems to be certifying them anyway, and the hope is that the spec will get updated in the next version to remove that restriction. iOS seems to handle it now so it seems like the documentation is behind the actual implementation
There was a problem hiding this comment.
The way iOS seems to handle it is, whichever characteristic was the last to get a notify/event for is the color mode you're in
There was a problem hiding this comment.
Hopefully we'll get a new spec or an ADK update... (doubt it).
It might be less sucky after I've done all the refactoring I want to in aiohomekit (I want the abstraction to be higher level than it is right now).
There was a problem hiding this comment.
Based on your discussion I don't think the simplification I did in 5ee6331 was correct, it should instead be like this:
- If the light reports support for both ct and hs, we should expose that as
supported_color_modes = {COLOR_MODE_COLOR_TEMP, COLOR_MODE_HS}(no change compared to before this PR) - Because aiohomekit does not track which color mode the light is in, a light supporting both ct and hs should just report color_mode
COLOR_MODE_HS(no change compared to before this PR)
Is that right?
There was a problem hiding this comment.
To be more pedantic on the second bullet: the HAP protocol itself (rather than aiohomekit) doesn't really have a concept of a current colour mode to track and aiohomekit's abstraction doesn't let us work around that. And even if it did, it would be an incomplete work around (we would lose the "current colour mode" on a simple HA restart for example). I assume the official iOS implementation is subject to the same limitations too.
(The thing I'm being pedantic about is that despite the changes in iOS 13 it's still not the case there is a variable /to/ track, we would have to track multiple variables for multiple event types (push, put and poll) and then infer our own value from the event timestamps of a subset of event types, only to have a partially working implementation at the end of it).
In the future we could implement the heuristics described to make it closer to the ideal, but short of Apple adding a new colour mode characteristic there is a potential for our implementation to seem "glitchy". So we might not want to implement such heuristics at all.
But the ultimate conclusion is the same, I think.
There was a problem hiding this comment.
OK, updated again.
Jc2k
left a comment
There was a problem hiding this comment.
Sorry this dropped off my radar, LGTM 👍
|
Looks good. Testing now |
Proposed change
Migrate homekit_controller light to color_mode
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: