Added tamper detection to Wink devices. (#6072)

* Added tamper detection to wink devices.
This commit is contained in:
William Scanlon 2017-02-18 23:00:27 -05:00 committed by GitHub
parent 5f095b5126
commit a4318c3125
2 changed files with 30 additions and 16 deletions

View file

@ -92,13 +92,13 @@ class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice, Entity):
def __init__(self, wink, hass): def __init__(self, wink, hass):
"""Initialize the Wink binary sensor.""" """Initialize the Wink binary sensor."""
super().__init__(wink, hass) super().__init__(wink, hass)
try: if hasattr(self.wink, 'unit'):
self._unit_of_measurement = self.wink.unit() self._unit_of_measurement = self.wink.unit()
except AttributeError: else:
self._unit_of_measurement = None self._unit_of_measurement = None
try: if hasattr(self.wink, 'capability'):
self.capability = self.wink.capability() self.capability = self.wink.capability()
except AttributeError: else:
self.capability = None self.capability = None
@property @property

View file

@ -139,7 +139,6 @@ class WinkDevice(Entity):
"""Initialize the Wink device.""" """Initialize the Wink device."""
self.hass = hass self.hass = hass
self.wink = wink self.wink = wink
self._battery = self.wink.battery_level()
hass.data[DOMAIN]['pubnub'].add_subscription( hass.data[DOMAIN]['pubnub'].add_subscription(
self.wink.pubnub_channel, self._pubnub_update) self.wink.pubnub_channel, self._pubnub_update)
hass.data[DOMAIN]['entities'].append(self) hass.data[DOMAIN]['entities'].append(self)
@ -183,17 +182,24 @@ class WinkDevice(Entity):
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attributes = {} attributes = {}
if self._battery: battery = self._battery_level
attributes[ATTR_BATTERY_LEVEL] = self._battery_level if battery:
if self._manufacturer_device_model: attributes[ATTR_BATTERY_LEVEL] = battery
_model = self._manufacturer_device_model man_dev_model = self._manufacturer_device_model
attributes["manufacturer_device_model"] = _model if man_dev_model:
if self._manufacturer_device_id: attributes["manufacturer_device_model"] = man_dev_model
attributes["manufacturer_device_id"] = self._manufacturer_device_id man_dev_id = self._manufacturer_device_id
if self._device_manufacturer: if man_dev_id:
attributes["device_manufacturer"] = self._device_manufacturer attributes["manufacturer_device_id"] = man_dev_id
if self._model_name: dev_man = self._device_manufacturer
attributes["model_name"] = self._model_name 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 return attributes
@property @property
@ -221,3 +227,11 @@ class WinkDevice(Entity):
def _model_name(self): def _model_name(self):
"""Return the model name.""" """Return the model name."""
return self.wink.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