From a4318c312585233baeecd0daefd94c5f8b742a2c Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Sat, 18 Feb 2017 23:00:27 -0500 Subject: [PATCH] Added tamper detection to Wink devices. (#6072) * Added tamper detection to wink devices. --- .../components/binary_sensor/wink.py | 8 ++-- homeassistant/components/wink.py | 38 +++++++++++++------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/binary_sensor/wink.py b/homeassistant/components/binary_sensor/wink.py index da60c54a0fd..797ef9649b6 100644 --- a/homeassistant/components/binary_sensor/wink.py +++ b/homeassistant/components/binary_sensor/wink.py @@ -92,13 +92,13 @@ class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice, Entity): def __init__(self, wink, hass): """Initialize the Wink binary sensor.""" super().__init__(wink, hass) - try: + if hasattr(self.wink, 'unit'): self._unit_of_measurement = self.wink.unit() - except AttributeError: + else: self._unit_of_measurement = None - try: + if hasattr(self.wink, 'capability'): self.capability = self.wink.capability() - except AttributeError: + else: self.capability = None @property diff --git a/homeassistant/components/wink.py b/homeassistant/components/wink.py index 0ef03f54083..6bde1600a82 100644 --- a/homeassistant/components/wink.py +++ b/homeassistant/components/wink.py @@ -139,7 +139,6 @@ class WinkDevice(Entity): """Initialize the Wink device.""" self.hass = hass self.wink = wink - self._battery = self.wink.battery_level() hass.data[DOMAIN]['pubnub'].add_subscription( self.wink.pubnub_channel, self._pubnub_update) hass.data[DOMAIN]['entities'].append(self) @@ -183,17 +182,24 @@ class WinkDevice(Entity): def device_state_attributes(self): """Return the state attributes.""" attributes = {} - if self._battery: - attributes[ATTR_BATTERY_LEVEL] = self._battery_level - if self._manufacturer_device_model: - _model = self._manufacturer_device_model - attributes["manufacturer_device_model"] = _model - if self._manufacturer_device_id: - attributes["manufacturer_device_id"] = self._manufacturer_device_id - if self._device_manufacturer: - attributes["device_manufacturer"] = self._device_manufacturer - if self._model_name: - attributes["model_name"] = self._model_name + battery = self._battery_level + if battery: + attributes[ATTR_BATTERY_LEVEL] = battery + man_dev_model = self._manufacturer_device_model + if man_dev_model: + attributes["manufacturer_device_model"] = man_dev_model + man_dev_id = self._manufacturer_device_id + if man_dev_id: + attributes["manufacturer_device_id"] = man_dev_id + dev_man = self._device_manufacturer + if dev_man: + attributes["device_manufacturer"] = dev_man + model_name = self._model_name + if model_name: + attributes["model_name"] = model_name + tamper = self._tamper + if tamper is not None: + attributes["tamper_detected"] = tamper return attributes @property @@ -221,3 +227,11 @@ class WinkDevice(Entity): def _model_name(self): """Return the model name.""" return self.wink.model_name() + + @property + def _tamper(self): + """Return the devices tamper status.""" + if hasattr(self.wink, 'tamper_detected'): + return self.wink.tamper_detected() + else: + return None