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
21 changes: 19 additions & 2 deletions homeassistant/components/zwave/__init__.py
Expand Up @@ -12,6 +12,7 @@

import voluptuous as vol

from homeassistant.core import callback
from homeassistant.loader import get_platform
from homeassistant.helpers import discovery
from homeassistant.const import (
Expand Down Expand Up @@ -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

self._update_attributes()

dispatcher.connect(
Expand All @@ -793,8 +795,8 @@ def value_changed(self):
self.update_properties()
# If value changed after device was created but before setup_platform
# was called - skip updating state.
if self.hass:
self.schedule_update_ha_state()
if self.hass and not self._scheduled_update:
self.hass.add_job(self._schedule_update)

def _update_ids(self):
"""Update value_ids from which to pull attributes."""
Expand Down Expand Up @@ -916,3 +918,18 @@ def refresh_from_network(self):
return
for value_id in dependent_ids + [self._value.value_id]:
self._value.node.refresh_value(value_id)

@callback
def _schedule_update(self):
"""Schedule delayed update."""
if self._scheduled_update:
return

@callback
def do_update():
"""Really update."""
self.hass.async_add_job(self.async_update_ha_state)
self._scheduled_update = False

self._scheduled_update = True
self.hass.loop.call_later(0.1, do_update)