Skip to content
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

Delay zwave updates for 100ms to group them. #6420

Merged
merged 14 commits into from Mar 5, 2017

Conversation

andrey-git
Copy link
Contributor

Description:

Delay zwave updates for 100ms to group them.

Related issue (if applicable): #6391

If the code does not interact with devices:

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

@mention-bot
Copy link

@andrey-git, thanks for your PR! By analyzing the history of the files in this pull request, we identified @turbokongen, @balloob and @fabaff to be potential reviewers.

if self.hass and not self._scheduled_update:
self._schedule_update()
else:
_LOGGER.info('Skip update for %s. It is already scheduled', self.entity_id)

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

@andrey-git
Copy link
Contributor Author

This solves some but not all duplicate updates.

if self.hass and not self._scheduled_update:
self._schedule_update()
else:
_LOGGER.info('Skip update for %s. It is already scheduled',
Copy link
Member

Choose a reason for hiding this comment

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

This could be debug at most but probably not log at all. It can spam a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@callback
def do_update():
"""Really update."""
self.hass.add_job(self.async_update_ha_state())
Copy link
Member

Choose a reason for hiding this comment

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

This should be async_add_job

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -916,3 +921,15 @@ def refresh_from_network(self):
return
for value_id in dependent_ids + [self._value.value_id]:
self._value.node.refresh_value(value_id)

def _schedule_update(self):
Copy link
Member

Choose a reason for hiding this comment

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

We should actually make this a callback and check at start if function if an update has already been scheduled. Otherwise because of race conditions we might schedule it twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if self.hass:
self.schedule_update_ha_state()
if self.hass and not self._scheduled_update:
self._schedule_update()
Copy link
Member

Choose a reason for hiding this comment

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

This should become hass.async_add_job(schedule)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to hass.add_job as async_add_job is only supposed to be called from a loop

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

🐬

self.hass.async_add_job(self.async_update_ha_state)
self._scheduled_update = False

if not self._scheduled_update:
Copy link
Member

Choose a reason for hiding this comment

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

Move if-statement to first line in function so Python doesn't have to create a function for nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -794,7 +796,7 @@ def value_changed(self):
# If value changed after device was created but before setup_platform
# was called - skip updating state.
if self.hass:
Copy link
Member

Choose a reason for hiding this comment

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

We are certain that we don't have to schedule an update if self._scheduled_update:

if self.hass and not self._scheduled_update:

(yes, we need a check in both places)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@callback
def _schedule_update(self):
"""Schedule delayed update."""
if not self._scheduled_update:
Copy link
Member

Choose a reason for hiding this comment

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

Should be the inverse. We should not do anything if an update is already scheduled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

🐬 🐬

@balloob balloob merged commit 46ec6d6 into home-assistant:dev Mar 5, 2017
@andrey-git andrey-git deleted the zwave_debounce branch March 5, 2017 17:32
@@ -769,6 +770,7 @@ def __init__(self, value, domain):
self._wakeup_value_id = None
self._battery_value_id = None
self._power_value_id = None
self._scheduled_update = False
Copy link
Member

Choose a reason for hiding this comment

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

For a future PR, maybe rename this to _update_scheduled to avoid mixup with _schedule_update method.

Copy link
Member

Choose a reason for hiding this comment

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

That's a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #6434

@home-assistant home-assistant locked and limited conversation to collaborators Jul 17, 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.

None yet

6 participants