-
-
Notifications
You must be signed in to change notification settings - Fork 189
Auto update and expand _lights class variable in AdaptiveSwitch on access
#562
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
base: main
Are you sure you want to change the base?
Conversation
_lights class variable in AdaptiveSwitch_lights class variable in AdaptiveSwitch on access (replaces _expand_light_groups)
_lights class variable in AdaptiveSwitch on access (replaces _expand_light_groups)_lights class variable in AdaptiveSwitch on access
| data, | ||
| ) | ||
|
|
||
| def __getattribute__(self, name): |
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.
what about creating a property on the switch:
@property
def all_lights(self):
return self._expand_light_groups()
then use switch.all_lights everywhere?
Or maybe just lights (I not already in use in HA somewhere).
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.
brilliant.
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.
We'd have to modify all the references with this method.
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.
I see your reasoning :)
However, a custom __getattribute__ might be hard to overlook when debugging because it is not super obvious what happens from just looking at the 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.
Done
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.
I'm not looking forward to modifying the other PRs. Perhaps we merge this one last?
It seemed arbitrary or unnecessarily picky when
switch.pywould used_expand_light_groups()before using_lights, now it just auto-expands on each access.Code also uses
switch._lightsmore sparingly and only once per method.I also added
# pylint: disable=protected-accessto any function that accessed a class method outside of the class as that seemed to be what we've been going with.