-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathluxtronik.py
75 lines (53 loc) · 1.89 KB
/
luxtronik.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
"""
Support for Luxtronik heatpump controllers.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/luxtronik/
"""
import logging
from datetime import timedelta
import voluptuous as vol
from homeassistant.const import (CONF_HOST, CONF_PORT)
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['luxtronik==0.0.3']
_LOGGER = logging.getLogger(__name__)
CONF_SENSORS = 'sensors'
DATA_LUXTRONIK = 'DATA_LT'
LUXTRONIK_PLATFORMS = ['switch', 'binary_sensor', 'sensor']
DOMAIN = 'luxtronik'
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST, default=""): cv.string,
vol.Required(CONF_PORT, default=8889): cv.port,
}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config):
"""Set up the Luxtronik component."""
conf = config[DOMAIN]
host = conf.get(CONF_HOST)
port = conf.get(CONF_PORT)
lt = LuxtronikData(host, port)
lt.update(no_throttle=True)
hass.data[DATA_LUXTRONIK] = lt
return True
class LuxtronikData(object):
"""Handle all communication with Luxtronik."""
def __init__(self, host, port):
"""Initialize the Luxtronik connection."""
from luxtronik import Luxtronik
self._host = host
self._port = port
self._luxtronik = Luxtronik(host, port)
self.data = None
def valid_sensor_id(self, sensor_id):
"""Validate if configured sensor ID is in data."""
for category in self.data:
for value in self.data[category]:
if self.data[category][value]['id'] == sensor_id:
return True
return False
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Use the data from Luxtronik."""
self.data = self._luxtronik.get_data()