8000 Do not call update() in constructor by fabaff · Pull Request #8148 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 4 commits into from
Jun 27, 2017
Merged

Do not call update() in constructor #8148

merged 4 commits into from
Jun 27, 2017

Conversation

fabaff
Copy link
Member
@fabaff fabaff commented Jun 22, 2017

Description:

  • Do not call update() in constructor
  • Remove checks in setup and log entry

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: glances
    host: localhost
    resources:
      - 'disk_use_percent'
      - 'disk_use'
      - 'disk_free'

Checklist:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

Copy link
Member
@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


dev = []
for resource in var_conf:
dev.append(GlancesSensor(rest, name, resource))

add_devices(dev)
add_devices(dev, True)
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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!

Copy link
Member Author

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)
Copy link
Member

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 ?

Copy link
Member Author

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.

Copy link
Member Author
@fabaff fabaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments addressed.

@fabaff fabaff merged commit fa6e93f into home-assistant:dev Jun 27, 2017
@fabaff fabaff deleted the glances branch June 27, 2017 08:56
@balloob balloob mentioned this pull request Jul 1, 2017
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
* Do not call update() in constructor

* Move handling to update and re-add throttle

* Fix indent

* Fix interval
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0