2019-02-14 15:01:46 +00:00
|
|
|
"""Support for the Hive binary sensors."""
|
2020-09-12 16:07:13 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2020-09-12 21:20:30 +00:00
|
|
|
DEVICE_CLASS_MOTION,
|
2020-09-12 16:07:13 +00:00
|
|
|
DEVICE_CLASS_OPENING,
|
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-12-08 20:06:05 +00:00
|
|
|
from . import DATA_HIVE, DOMAIN, HiveEntity
|
2018-01-15 22:24:12 +00:00
|
|
|
|
2020-09-12 16:07:13 +00:00
|
|
|
DEVICETYPE_DEVICE_CLASS = {
|
2020-09-12 21:20:30 +00:00
|
|
|
"motionsensor": DEVICE_CLASS_MOTION,
|
2020-09-12 16:07:13 +00:00
|
|
|
"contactsensor": DEVICE_CLASS_OPENING,
|
|
|
|
}
|
2018-01-15 22:24:12 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-01-15 22:24:12 +00:00
|
|
|
"""Set up Hive sensor devices."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
2019-09-27 21:18:34 +00:00
|
|
|
session = hass.data.get(DATA_HIVE)
|
|
|
|
devs = []
|
|
|
|
for dev in discovery_info:
|
|
|
|
devs.append(HiveBinarySensorEntity(session, dev))
|
|
|
|
add_entities(devs)
|
2018-01-15 22:24:12 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
|
2018-01-15 22:24:12 +00:00
|
|
|
"""Representation of a Hive binary sensor."""
|
|
|
|
|
2019-01-09 04:15:12 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return unique ID of entity."""
|
|
|
|
return self._unique_id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self):
|
|
|
|
"""Return device information."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name}
|
2019-01-09 04:15:12 +00:00
|
|
|
|
2018-01-15 22:24:12 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this sensor."""
|
|
|
|
return DEVICETYPE_DEVICE_CLASS.get(self.node_device_type)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the binary sensor."""
|
|
|
|
return self.node_name
|
|
|
|
|
2018-04-16 19:00:13 +00:00
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Show Device Attributes."""
|
|
|
|
return self.attributes
|
|
|
|
|
2018-01-15 22:24:12 +00:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the binary sensor is on."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return self.session.sensor.get_state(self.node_id, self.node_device_type)
|
2018-01-15 22:24:12 +00:00
|
|
|
|
|
|
|
def update(self):
|
2018-01-27 19:58:27 +00:00
|
|
|
"""Update all Node data from Hive."""
|
2018-01-15 22:24:12 +00:00
|
|
|
self.session.core.update_data(self.node_id)
|
2019-07-31 19:25:30 +00:00
|
|
|
self.attributes = self.session.attributes.state_attributes(self.node_id)
|