This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsensor.py
71 lines (56 loc) · 1.93 KB
/
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
"""
Support for Aqualink temperature sensors.
"""
import logging
import time
from typing import TYPE_CHECKING, Optional
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_SENSORS, DEVICE_CLASS_TEMPERATURE, STATE_OFF, STATE_ON,
TEMP_CELSIUS, TEMP_FAHRENHEIT)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.components.sensor import DOMAIN
from .const import DOMAIN as AQUALINK_DOMAIN
_LOGGER = logging.getLogger(__name__)
PARALLEL_UPDATES = 0
if TYPE_CHECKING:
from iaqualink import AqualinkSensor
async def async_setup_entry(hass: HomeAssistantType,
config_entry: ConfigEntry,
async_add_entities) -> None:
"""Set up discovered sensors."""
devs = []
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
devs.append(HassAqualinkSensor(dev))
async_add_entities(devs, True)
class HassAqualinkSensor(Entity):
def __init__(self, dev: 'AqualinkSensor'):
Entity.__init__(self)
self.dev = dev
@property
def name(self) -> str:
return self.dev.label
@property
def unit_of_measurement(self) -> str:
if self.dev.system.temp_unit == "F":
return TEMP_FAHRENHEIT
else:
return TEMP_CELSIUS
@property
def state(self) -> str:
return int(self.dev.state) if self.dev.state else None
@property
def device_class(self) -> Optional[str]:
if self.dev.name.endswith('_temp'):
return DEVICE_CLASS_TEMPERATURE
return None
@property
def icon(self) -> Optional[str]:
if self.dev.name.endswith('_temp'):
return 'mdi:thermometer'
return None
async def async_update(self) -> None:
return None
# Disable for now since throttling on the API side doesn't work.
# await self.dev.system.update()