-
Notifications
You must be signed in to change notification settings - Fork 37
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
Improves light support #155
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Hello @danielcaceresm and @make-all, as I do not have any IR controlled light I completely depend on you and your testing. ;-) So If you say it is OK, I will merge it. ;-) |
Hello @litinoveweedle! I have these changes working with my lights from I made the PR without any issue. I don't have lights using the colder/warmer commands and I can't test the old behavior but I tried to not modify it. |
I just did some testing, and it appears the color temperature adjustment is acting strangely for small adjustments. It seems to yoyo between colder and warmer, and reaching the end (where multiple commands are sent to resync) when the HA control is half way. |
I think I found the issue:
The code is sending an "on" command when the color temperature lookup results in no change needed. This has the side effect of "memory recall" on my light. It is also happening with brightness. |
By coincidence I have recently related discussion. Overall the SmartIR is assumed state device (as we do not know state of the device). We can take two ways - be optimistic (trust that real device is in the state as reported by HA) or pessimistic (send always command to converge device to the required state). I am probably going to implement config switch to be able to implement both option so user can decide per device which approach to use. This feature is originally aked for media_player class, but to keep SmartIR consistent I will implement it for every class - lights as well. This would then solve the mentioned issue - if you can set mode to optimistic. Will this work fork you? |
@danielcaceresm Thank you once more for the contribution. As the light device file becomes more versatile ( and complex ;-) ), could you please also try to document format (based on you example) in the CODES_SYNTAX.md. I am also open to splitting this file into fourth - one for each class, as it rather seems growing fast. ;-) |
My lights do get out of sync, so "optimistic" is not exactly what I need. I added code to give extra commands to make sure it is at the end of the range for brightness and color temperature when reaching what HA thinks is the end of the range to deal with the sync problem for example. I guess if someone has a light that wraps instead of no-op when a remote up/down button tries to go beyond the range, they would want to turn that off, so that toggle would still be useful. But I think turning the light on when we think it is already on should only be done when turn_on is called without arguments. That is effectively what the old code did, as it recorded "done_something" whenever processing the brightness and color_temp arguments, regardless of whether they resulted in a command being sent. But in this change it was modified to only record "done_something" when a command was actually sent, so it is falling through to send the on command when the brightness/color_temp is moved by increments smaller than the light's supported step size. This triggers when using adaptive lighting for example. |
custom_components/smartir/light.py
Outdated
# commands to go the full range. | ||
if new_color_temp == len(self._colortemps) - 1 or new_color_temp == 0: | ||
steps = len(self._colortemps) | ||
did_something = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line (279) needs to move back up to above line 267, to avoid sending "on" commands when a color temp is given but does not result in a change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the assignation to line 245, affecting the both branches of the if.
custom_components/smartir/light.py
Outdated
or new_brightness == 0 | ||
): | ||
steps = len(self._brightnesses) | ||
did_something = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line (331) needs to move back to above line 316, actually it could move back up to above line 298 where it was previously and the one on line 307 removed, since after the change both branches of the if statement are setting it unconditionally.
The one on line 290 in the original code (aligned with 307) was left over from an earlier version where I originally did exactly what you did here, and has probably misled you about the intention. It should have been removed when it was moved to line 270 in the original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the assignation to line 291, affecting the both branches of the if. Thanks!
@litinoveweedle I modified the file adding the documentation for the light format. Please let me know if any adjustments are needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behaves OK now for the up/down controlled lights
I added support to 2 lights I owns:
Example:
Enhancements:
CMD_COLORTEMPERATURE
andCMD_BRIGHTNESS
commands to control color temperature and brightness, allowing specific commands per brightness or color values instead of up/down steps.async_turn_on
method to handle cases whereCMD_POWER_ON
is not available by setting the last known color temperature and brightness.async_turn_off
method to check the current state before sending the power-off command.Bug Fixes: