-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Do not call update() in constructor #8148
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
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.
I think this part need to be inside update and not recalc every state call... https://github.com/fabaff/home-assistant/blob/94c1358ff5b2f0a2cd08ec838ccbf0c6daebbffe/homeassistant/components/sensor/glances.py#L109-L150
|
||
dev = [] | ||
for resource in var_conf: | ||
dev.append(GlancesSensor(rest, name, resource)) | ||
|
||
add_devices(dev) | ||
add_devices(dev, 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.
I think that need not be True
here since it was call above.
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.
Thanks. It would indeed lead to two calls.
@@ -170,12 +162,11 @@ def __init__(self, resource): | |||
self._resource = resource | |||
self.data = dict() | |||
|
|||
@Throttle(MIN_TIME_BETWEEN_UPDATES) |
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.
You will still need the Throttle. Each entity will call update
and thus if you have 5 entities, you will update 5 times!
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.
Thanks
@@ -25,7 +25,7 @@ | |||
DEFAULT_NAME = 'Glances' | |||
DEFAULT_PORT = '61208' | |||
|
|||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) | |||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=60) |
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.
60 minutes seems a bit long ?
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.
Sure, should be one minute as before.
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.
All comments addressed.
* Do not call update() in constructor * Move handling to update and re-add throttle * Fix indent * Fix interval
Description:
Example entry for
configuration.yaml
(if applicable):Checklist:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests pass