-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_sensor.py
93 lines (69 loc) · 3.04 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
from homeassistant.components.binary_sensor import BinarySensorEntity
from .const import DOMAIN
from homeassistant.components.lock import LockEntity, SUPPORT_OPEN
from homeassistant.helpers import entity_platform, service
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from aionuki import NukiLock, NukiOpener
from .const import DOMAIN, SERVICE_LOCK_N_GO, ATTR_CODE
from homeassistant.helpers.config_validation import ( # https://github.com/home-assistant/core/blob/dev/homeassistant/components/lock/__init__.py
make_entity_service_schema,
)
import logging
_LOGGER = logging.getLogger(__name__)
class NukiDoorSensorPlatform(BinarySensorEntity):
# Should Home Assistant check with the entity for an updated state. If set to False, entity will need to notify Home Assistant of new updates by calling one of the schedule update methods.
should_poll = False
# Type of binary sensor.
device_class = "door" # On means open, Off means closed.
def __init__(self, config, obj):
self._config = config
self.lockObj = obj
super().__init__()
# Generic Properties
@property
def available(self):
""" Indicate if Home Assistant is able to read the state and control the underlying device. """
return True and self.enabled
@property
def device_state_attributes(self):
""" Extra information to store in the state machine. It needs to be information that further explains the state, it should not be static information like firmware version. """
return {}
@property
def unique_id(self):
""" A unique identifier for this entity. Needs to be unique within a platform (ie light.hue). Should not be configurable by the user or be changeable. Learn more. """
return str(self.lockObj.nuki_id) + "_doorsensor"
@property
def name(self):
""" Name of the entity. """
return "Door Sensor"
# Binary sensor properties
@property
def is_on(self):
""" If the binary sensor is currently on or off.. """
return self.lockObj.is_open
@property
def device_info(self):
"""Device info for the ups."""
if not self.unique_id:
return None
device_info = {
"identifiers": {(DOMAIN, self.lockObj.nuki_id)},
"name": self.name,
"via_device": self.lockObj.nuki_id,
}
return device_info
# Type of binary sensor.
device_class = "door" # On means open, Off means closed.
# "battery" # On means low, Off means normal.
# Setup
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Hue lights from a config entry."""
platform = hass.data[DOMAIN][config_entry.entry_id]
deviceList = []
for lock in platform.devices:
device = NukiDoorSensorPlatform(config_entry.data, lock)
platform.registerUpdateCallback(device.async_schedule_update_ha_state)
deviceList.append(device)
async_add_entities(deviceList, True)
_LOGGER.debug("Started door sensor platform.")