forked from gvigroux/hon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cooler.py
67 lines (54 loc) · 2.04 KB
/
cooler.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
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
CoordinatorEntity,
)
import logging
from datetime import timedelta
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class HonCoolerCoordinator(DataUpdateCoordinator):
def __init__(self, hass, hon, appliance):
"""Initialize my coordinator."""
super().__init__(
hass,
_LOGGER,
# Name of the data. For logging purposes.
name="hOn Cooler",
# Polling interval. Will only be polled if there are subscribers.
update_interval=timedelta(seconds=30),
)
self._hon = hon
self._mac = appliance["macAddress"]
self._type_name = appliance["applianceTypeName"]
async def _async_update_data(self):
return await self._hon.async_get_state(self._mac, self._type_name)
class HonCoolerEntity(CoordinatorEntity):
def __init__(self, hass, entry, coordinator, appliance) -> None:
super().__init__(coordinator)
self._hon = hass.data[DOMAIN][entry.unique_id]
self._hass = hass
self._brand = appliance["brand"]
if "nickName" in appliance:
self._name = appliance["nickName"]
else:
self._name = "Cooler"
self._mac = appliance["macAddress"]
self._connectivity = appliance["connectivity"]
self._model = appliance["modelName"]
self._series = appliance["series"]
self._model_id = appliance["applianceModelId"]
self._type_name = appliance["applianceTypeName"]
self._serial_number = appliance["serialNumber"]
self._fw_version = appliance["fwVersion"]
@property
def device_info(self):
return {
"identifiers": {
# Serial numbers are unique identifiers within a specific domain
(DOMAIN, self._mac)
},
"name": self._name,
"manufacturer": self._brand,
"model": self._model,
"sw_version": self._fw_version,
}