mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 13:17:53 +00:00
ZWave Sensor values push changes to HA
This commit is contained in:
parent
67161d686b
commit
19d243d159
@ -4,11 +4,14 @@ homeassistant.components.sensor.zwave
|
|||||||
|
|
||||||
Interfaces with Z-Wave sensors.
|
Interfaces with Z-Wave sensors.
|
||||||
"""
|
"""
|
||||||
|
from openzwave.network import ZWaveNetwork
|
||||||
|
from pydispatch import dispatcher
|
||||||
|
|
||||||
import homeassistant.components.zwave as zwave
|
import homeassistant.components.zwave as zwave
|
||||||
from homeassistant.helpers import Device
|
from homeassistant.helpers import Device
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_FRIENDLY_NAME, ATTR_BATTERY_LEVEL, ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_BATTERY_LEVEL, ATTR_UNIT_OF_MEASUREMENT, STATE_ON, STATE_OFF,
|
||||||
TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_LOCATION, STATE_ON, STATE_OFF)
|
TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_LOCATION)
|
||||||
|
|
||||||
|
|
||||||
class ZWaveSensor(Device):
|
class ZWaveSensor(Device):
|
||||||
@ -17,6 +20,14 @@ class ZWaveSensor(Device):
|
|||||||
self._value = sensor_value
|
self._value = sensor_value
|
||||||
self._node = sensor_value.node
|
self._node = sensor_value.node
|
||||||
|
|
||||||
|
dispatcher.connect(
|
||||||
|
self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def should_poll(self):
|
||||||
|
""" False because we will push our own state to HA when changed. """
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
""" Returns a unique id. """
|
""" Returns a unique id. """
|
||||||
@ -39,7 +50,6 @@ class ZWaveSensor(Device):
|
|||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
""" Returns the state attributes. """
|
||||||
attrs = {
|
attrs = {
|
||||||
ATTR_FRIENDLY_NAME: self.name,
|
|
||||||
zwave.ATTR_NODE_ID: self._node.node_id,
|
zwave.ATTR_NODE_ID: self._node.node_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +75,11 @@ class ZWaveSensor(Device):
|
|||||||
""" Unit if sensor has one. """
|
""" Unit if sensor has one. """
|
||||||
return self._value.units
|
return self._value.units
|
||||||
|
|
||||||
|
def _value_changed(self, value):
|
||||||
|
""" Called when a value has changed on the network. """
|
||||||
|
if self._value.value_id == value.value_id:
|
||||||
|
self.update_ha_state()
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class ZWaveBinarySensor(ZWaveSensor):
|
class ZWaveBinarySensor(ZWaveSensor):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user