-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: service call adaptation #628
feat: service call adaptation #628
Conversation
@protyposis, I just had 2 babies and cannot find the time to properly review this. If you like, I can add you as a maintainer of this repo. Then you can merge this and release if you are comfortable. LMK I am approving without detailed look at this. Otherwise idea is great though! |
Thanks, I accepted the invitation :) Is my assumption correct that releases are created manually in this repo, like this?
|
@protyposis, that’s 100% correct! 😄 |
I haven't taken a look at the code in depth yet, but if I'm understanding this implementation correctly, it's a pretty huge deal. It sounds like you're able to hook into service calls and modify them before sending them off again? This would be absolutely massive and something I've been interested in doing for a while, not just in the lighting space. This is useful to generally augment behavior of service calls without having to write a wrapper script (as seen in that comment you linked) and call that instead. Would something along these lines also allow you to set up "hooks" for actions you could take before a service runs? Most importantly, do you think this would be a candidate for an architecture proposal? Alternatively, if core doesn't want to go in that direction architecturally, perhaps this general functionality could be extracted into its own custom_component? Thoughts @protyposis? |
Exactly✌️
Definitely. Currently, it allows registering a single async "interceptor" function, which defers service execution until it resolves. It could be easily extended with a flexible hooking interface.
Yes. The current implementation has a few disadvantages that a proper implementation in core could fix:
I'd like to start that discussion once we collected enough evidence (through positive user feedback) that this approach has the potential to be a valuable core HA feature. |
Thanks so much for all the awesome work! I got some time to try it out but unfortunately it doesn't seem to work in my setup (https://github.com/basnijholt/home-assistant-config/blob/master/includes/adaptive_lighting.yaml). I added some logging statements here: adaptive-lighting/custom_components/adaptive_lighting/switch.py Lines 1847 to 1848 in 1cedb3f
And see: I believe this is because there is only a single Instead it might be an idea to use to identify the switch? Any thoughts? |
Adapt
light.turn_on
service calls, that initially turn on a light, directly (called proactive adaptation in code) by injecting brightness and color into the service call data payload. This makes lights immediately turn on with the correct adaptation settings. Resolves #594.Traditionally, AL follows a reactive adaptation approach, which reacts to state change events. This works fine in most cases, but can result in a noticeable adaptation delay when turning on a light (due to events not being instant, and due to various light hardware quirks). Example: Previously, a light might first turn on at 100% brightness before AL kicks in and adapts it down to 1%. Now it directly turns on at 1% brightness.
This only affects service calls which turn on lights that are off, i.e., the initial turn-on. Also, this first version only adapts service calls that target a single light entity. Everything else continues to work as usual. This feature requires access to an internal/protected
hass
property and automatically falls back to the reactive adaptation mode in case it becomes unavailable in future HA versions (and requires adjustments in AL). This also makes certain workarounds obsolete, e.g., usingadaptive_lighting.apply
to turn on lights, or explicitly applying AL state to light service calls (#585 (comment)).Update:
light.toggle
service calls iff they turn a light on.initial_transition
.