Moved common z-wave node functionality to a common z-wave class
This commit is contained in:
1 parent
5b6371ecda
commit
1a422ecd5a
4 files changed
+84
-138
No files matched your search
@@ -9,7 +9,9 @@ Zwave platform that handles simple binary switches.
|
||||
import homeassistant.components.zwave as zwave
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.components.zwave import ZWaveDeviceEntity
|
||||
|
||||
DOMAIN = "switch"
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@@ -32,14 +34,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
add_devices([ZwaveSwitch(value)])
|
||||
|
||||
|
||||
class ZwaveSwitch(SwitchDevice):
|
||||
class ZwaveSwitch(ZWaveDeviceEntity, SwitchDevice):
|
||||
""" Provides a zwave switch. """
|
||||
def __init__(self, value):
|
||||
from openzwave.network import ZWaveNetwork
|
||||
from pydispatch import dispatcher
|
||||
|
||||
self._value = value
|
||||
self._node = value.node
|
||||
ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
||||
|
||||
self._state = value.data
|
||||
dispatcher.connect(
|
||||
@@ -51,39 +52,6 @@ class ZwaveSwitch(SwitchDevice):
|
||||
self._state = value.data
|
||||
self.update_ha_state()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a demo switch. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns a unique id. """
|
||||
return "ZWAVE-{}-{}".format(self._node.node_id, self._value.object_id)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device. """
|
||||
name = self._node.name or "{} {}".format(
|
||||
self._node.manufacturer_name, self._node.product_name)
|
||||
|
||||
return "{} {}".format(name, self._value.label)
|
||||
|
||||
@property
|
||||
def entity_id(self):
|
||||
""" Returns the entity_id of the device if any.
|
||||
The entity_id contains node_id and value instance id
|
||||
to not collide with other entity_ids"""
|
||||
|
||||
entity_id = "switch.{}_{}".format(slugify(self.name),
|
||||
self._node.node_id)
|
||||
|
||||
# Add the instance id if there is more than one instance for the value
|
||||
if self._value.instance > 1:
|
||||
return "{}_{}".format(entity_id, self._value.instance)
|
||||
|
||||
return entity_id
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if device is on. """
|
||||
@@ -91,8 +59,8 @@ class ZwaveSwitch(SwitchDevice):
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" Turn the device on. """
|
||||
self._node.set_switch(self._value.value_id, True)
|
||||
self._value.node.set_switch(self._value.value_id, True)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" Turn the device off. """
|
||||
self._node.set_switch(self._value.value_id, False)
|
||||
self._value.node.set_switch(self._value.value_id, False)
|
||||
Reference in new issue
Block a user