[*.zwave] Refactor of zwave value_changed (#5512)
* Refactor of zwave value_changed * Rename update_properties to update * Revert "Rename update_properties to update" This reverts commit 723578e7d4e2156507c70f649a124a6193edc0db.
This commit is contained in:
1 parent
d0538fe3aa
commit
923431110a
8 files changed
+58
-136
No files matched your search
@@ -15,6 +15,7 @@ from homeassistant.helpers import discovery
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL, ATTR_LOCATION, ATTR_ENTITY_ID, CONF_CUSTOMIZE,
|
||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.event import track_time_change
|
||||
from homeassistant.util import convert, slugify
|
||||
import homeassistant.config as conf_util
|
||||
@@ -600,14 +601,36 @@ def setup(hass, config):
|
||||
return True
|
||||
|
||||
|
||||
class ZWaveDeviceEntity:
|
||||
class ZWaveDeviceEntity(Entity):
|
||||
"""Representation of a Z-Wave node entity."""
|
||||
|
||||
def __init__(self, value, domain):
|
||||
"""Initialize the z-Wave device."""
|
||||
# pylint: disable=import-error
|
||||
from openzwave.network import ZWaveNetwork
|
||||
from pydispatch import dispatcher
|
||||
self._value = value
|
||||
self.entity_id = "{}.{}".format(domain, self._object_id())
|
||||
|
||||
dispatcher.connect(
|
||||
self.network_value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
|
||||
|
||||
def network_value_changed(self, value):
|
||||
"""Called when a value has changed on the network."""
|
||||
if self._value.value_id == value.value_id or \
|
||||
self._value.node == value.node:
|
||||
_LOGGER.debug('Value changed for label %s', self._value.label)
|
||||
self.value_changed(value)
|
||||
|
||||
def value_changed(self, value):
|
||||
"""Called when a value for this entity's node has changed."""
|
||||
self.update_properties()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def update_properties(self):
|
||||
"""Callback on data changes for node values."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
|
||||
Reference in new issue
Block a user