-
Notifications
You must be signed in to change notification settings - Fork 142
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
Auto update and expand _lights
class variable in AdaptiveSwitch
on access
#562
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
@@ -838,6 +841,11 @@ def __init__( | |||
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.py
would used_expand_light_groups()
before using_lights
, now it just auto-expands on each access.Code also uses
switch._lights
more sparingly and only once per method.I also added
# pylint: disable=protected-access
to any function that accessed a class method outside of the class as that seemed to be what we've been going with.