forked from gvigroux/hon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
binary_sensor.py
160 lines (106 loc) · 5.9 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import logging
import asyncio
import json
from datetime import datetime, timedelta, timezone
from dateutil.tz import gettz
from typing import Optional
from enum import IntEnum
from .const import DOMAIN, OVEN_PROGRAMS, DISH_WASHER_MODE, DISH_WASHER_PROGRAMS, CLIMATE_MODE, APPLIANCE_TYPE
from .base import HonBaseCoordinator, HonBaseEntity, HonBaseBinarySensorEntity
from homeassistant.core import callback
from homeassistant.helpers import entity_platform
from homeassistant.config_entries import ConfigEntry
from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorDeviceClass,
)
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
hon = hass.data[DOMAIN][entry.unique_id]
appliances = []
for appliance in hon.appliances:
if appliance.get("macAddress", None) == None:
_LOGGER.warning("Appliance with no MAC")
continue
# Get or Create Coordinator
coordinator = await hon.async_get_coordinator(appliance)
await coordinator.async_config_entry_first_refresh()
# Every device should have a OnOff status
appliances.extend([HonBaseOnOff(hass, coordinator, entry, appliance)])
if( "doorStatusZ1" in coordinator.data ):
appliances.extend([HonBaseDoorStatus(hass, coordinator, entry, appliance, "Z1", "Zone 1")])
if( "doorStatusZ2" in coordinator.data ):
appliances.extend([HonBaseDoorStatus(hass, coordinator, entry, appliance, "Z2", "Zone 2")])
if( "doorLockStatus" in coordinator.data ):
appliances.extend([HonBaseDoorLockStatus(hass, coordinator, entry, appliance)])
if( "lockStatus" in coordinator.data ):
appliances.extend([HonBaseChildLockStatus(hass, coordinator, entry, appliance)])
if( "lightStatus" in coordinator.data ):
appliances.extend([HonBaseLightStatus(hass, coordinator, entry, appliance)])
if( "remoteCtrValid" in coordinator.data ):
appliances.extend([HonBaseRemoteControl(hass, coordinator, entry, appliance)])
if( "preheatStatus" in coordinator.data ):
appliances.extend([HonBasePreheating(hass, coordinator, entry, appliance)])
async_add_entities(appliances)
platform = entity_platform.async_get_current_platform()
#platform.async_register_entity_service("turn_lights_on",{},"async_set_on",)
#platform.async_register_entity_service("turn_lights_off",{},"async_set_off",)
class HonBaseOnOff(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance) -> None:
super().__init__(coordinator, appliance, "onOffStatus", "Status")
self._attr_device_class = BinarySensorDeviceClass.POWER
def coordinator_update(self):
if( "onOffStatus" in self._coordinator.data ):
self._attr_is_on = self._coordinator.data["onOffStatus"]["parNewVal"] == "1"
else:
self._attr_is_on = self._coordinator.data["category"] == "CONNECTED"
class HonBaseDoorStatus(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance, zone = "Z1", zone_name = "Zone 1") -> None:
super().__init__(coordinator, appliance, "doorStatus" + self._zone, f"Door Status {zone_name}")
self._zone = zone
self._attr_device_class = BinarySensorDeviceClass.DOOR
def coordinator_update(self):
self._attr_is_on = self._coordinator.data["doorStatus" + self._zone]["parNewVal"] == "1"
class HonBaseLightStatus(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance) -> None:
super().__init__(coordinator, appliance, "lightStatus", "Light")
self._attr_device_class = BinarySensorDeviceClass.LIGHT
self._attr_icon = "mdi:lightbulb"
def coordinator_update(self):
self._attr_is_on = self._coordinator.data["lightStatus"]["parNewVal"] == "1"
#async def async_set_on(self):
# parameters = {"lightStatus": "1"}
# await self.async_set(parameters)
# self._attr_is_on = True
# self.async_write_ha_state()
#async def async_set_off(self):
# parameters = {"lightStatus": "0"}
# await self.async_set(parameters)
# self._attr_is_on = False
# self.async_write_ha_state()
class HonBaseRemoteControl(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance) -> None:
super().__init__(coordinator, appliance, "remoteCtrValid", "Remote Control")
self._attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
self._attr_icon = "mdi:remote"
def coordinator_update(self):
self._attr_is_on = self._coordinator.data["remoteCtrValid"]["parNewVal"] == 1
class HonBaseDoorLockStatus(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance) -> None:
super().__init__(coordinator, appliance, "doorLockStatus", "Door Lock")
self._attr_device_class = BinarySensorDeviceClass.LOCK
def coordinator_update(self):
self._attr_is_on = self._coordinator.data["doorLockStatus"]["parNewVal"] == "0"
class HonBaseChildLockStatus(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance) -> None:
super().__init__(coordinator, appliance, "lockStatus", "Child Lock")
self._attr_device_class = BinarySensorDeviceClass.LOCK
def coordinator_update(self):
self._attr_is_on = self._coordinator.data["lockStatus"]["parNewVal"] == "0"
class HonBasePreheating(HonBaseBinarySensorEntity):
def __init__(self, hass, coordinator, entry, appliance) -> None:
super().__init__(coordinator, appliance, "preheatStatus", "Preheating")
self._attr_device_class = BinarySensorDeviceClass.HEAT
self._attr_icon = "mdi:thermometer-chevron-up"
def coordinator_update(self):
self._attr_is_on = json["preheatStatus"]["parNewVal"] == "1"