Skip to content

Commit

Permalink
Improvements to zwave lock platform (home-assistant#5066)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbokongen authored and balloob committed Dec 27, 2016
1 parent 7b6503c commit fee47f3
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions homeassistant/components/lock/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,34 @@
"""
# Because we do not compile openzwave on CI
# pylint: disable=import-error
import logging

from homeassistant.components.lock import DOMAIN, LockDevice
from homeassistant.components import zwave

_LOGGER = logging.getLogger(__name__)

ATTR_NOTIFICATION = 'notification'

LOCK_NOTIFICATION = {
1: 'Manual Lock',
2: 'Manual Unlock',
3: 'RF Lock',
4: 'RF Unlock',
5: 'Keypad Lock',
6: 'Keypad Unlock',
254: 'Unknown Event'
}

LOCK_STATUS = {
1: True,
2: False,
3: True,
4: False,
5: True,
6: False
}


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down Expand Up @@ -40,15 +65,32 @@ def __init__(self, value):

zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)

self._state = value.data
self._node = value.node
self._state = None
self._notification = None
dispatcher.connect(
self._value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
self.update_properties()

def _value_changed(self, value):
"""Called when a value has changed on the network."""
if self._value.value_id == value.value_id:
self._state = value.data
self.update_ha_state()
if self._value.value_id == value.value_id or \
self._value.node == value.node:
self.update_properties()
self.schedule_update_ha_state()

def update_properties(self):
"""Callback on data change for the registered node/value pair."""
for value in self._node.get_values(
class_id=zwave.const.COMMAND_CLASS_ALARM).values():
if value.label != "Access Control":
continue
self._notification = LOCK_NOTIFICATION.get(value.data)
if self._notification:
self._state = LOCK_STATUS.get(value.data)
break
if not self._notification:
self._state = self._value.data

@property
def is_locked(self):
Expand All @@ -62,3 +104,11 @@ def lock(self, **kwargs):
def unlock(self, **kwargs):
"""Unlock the device."""
self._value.data = False

@property
def device_state_attributes(self):
"""Return the device specific state attributes."""
data = super().device_state_attributes
if self._notification:
data[ATTR_NOTIFICATION] = self._notification
return data

0 comments on commit fee47f3

Please sign in to comment.