Skip to content

Commit

Permalink
Delay zwave updates for 100ms to group them. (#6420)
Browse files Browse the repository at this point in the history
* Add Zwave refresh services

* services file

* Use dispatcher

* Add zwave prefix to signal

* Delay zwave updates for 100ms to group them.

* Fixes

* lint

* Access _scheduled_update from loop thread only.

* More async

* Some optimizations

* Fix
  • Loading branch information
andrey-git authored and balloob committed Mar 5, 2017
1 parent 660e777 commit 46ec6d6
Showing 1 changed file with 19 additions and 2 deletions.
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
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)

0 comments on commit 46ec6d6

Please sign in to comment.