forked from marthoc/homeseer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary_sensor.py
92 lines (66 loc) · 2.46 KB
/
binary_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Support for HomeSeer binary-type devices.
"""
from .pyhs3.device import GenericBinarySensor
from .hoomseer import HomeseerEntity
from homeassistant.components.binary_sensor import (
BinarySensorEntity,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_WINDOW,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_GARAGE_DOOR,
DEVICE_CLASS_SMOKE,
DEVICE_CLASS_GAS,
DEVICE_CLASS_VIBRATION,
)
from .const import DATA_CLIENT, _LOGGER, DOMAIN
DEPENDENCIES = ["homeseer"]
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up HomeSeer binary-type devices."""
binary_sensor_devices = []
homeseer = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
for device in homeseer.devices:
if issubclass(type(device), GenericBinarySensor):
dev = HSBinarySensor(device, homeseer)
binary_sensor_devices.append(dev)
_LOGGER.info(f"Added HomeSeer binary-senssor-type device: {dev.name}")
async_add_entities(binary_sensor_devices)
class HSBinarySensor(HomeseerEntity, BinarySensorEntity):
"""Representation of a HomeSeer binary-type device."""
_device_class = None
def __init__(self, device, connection):
HomeseerEntity.__init__(self, device, connection)
name = self._device.name.lower()
if "window" in name:
self._device_class = DEVICE_CLASS_WINDOW
if "garage" in name:
self._device_class = DEVICE_CLASS_GARAGE_DOOR
if "door" in name:
self._device_class = DEVICE_CLASS_DOOR
if "entry" in name:
self._device_class = DEVICE_CLASS_DOOR
if "garage door" in name:
self._device_class = DEVICE_CLASS_GARAGE_DOOR
if "motion" in name:
self._device_class = DEVICE_CLASS_MOTION
if "fire" in name:
self._device_class = DEVICE_CLASS_SMOKE
if "smoke" in name:
self._device_class = DEVICE_CLASS_SMOKE
if "monoxide" in name:
self._device_class = DEVICE_CLASS_GAS
if "glass break" in name:
self._device_class = DEVICE_CLASS_VIBRATION
@property
def is_on(self):
"""Return true if device is on.
Garage doors:
Closed is off
Open is on
"""
if self._device._on_value is None:
return self._device.value > 0
return self.device.value == self._device._on_value
@property
def device_class(self):
return self._device_class