This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
climate.py
executable file
·177 lines (149 loc) · 5.49 KB
/
climate.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import json
import logging
import requests
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from urllib.request import urlopen
from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA)
from homeassistant.components.climate.const import (
STATE_HEAT, SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import (
TEMP_CELSIUS, ATTR_TEMPERATURE)
_LOGGER = logging.getLogger(__name__)
ATTR_PRESSURE = 'pressure'
ATTR_RSSI = 'rf_message_rssi'
ATTR_CH_TEMP = 'ch_temp'
ATTR_TAP_TEMP = 'tap_temp'
DEFAULT_AUTH = False
DEFAULT_USERNAME = 'admin'
DEFAULT_PASSWORD = 'intergas'
CONF_NAME = 'name'
CONF_HOST = 'host'
CONF_AUTH = 'auth'
CONF_USERNAME = 'username'
CONF_PASSWORD = 'password'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_NAME): cv.string,
vol.Optional(CONF_AUTH, default=DEFAULT_AUTH): cv.boolean,
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
})
def _lsbmsb(lsb, msb):
temp = (lsb + msb*256) / 100.0
if temp == 327.67:
return 5
else:
return temp
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the InComfort thermostat."""
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
auth = config.get(CONF_AUTH)
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
add_devices([InComfortThermostat(name, host, auth, username, password)])
class InComfortThermostat(ClimateDevice):
"""Representation of a InComfort Thermostat device."""
def __init__(self, name, host, auth, username, password):
"""Initialize the thermostat."""
self.host = host
self._name = name
self._auth = auth
self._username = username
self._password = password
self._current_temperature = None
self._target_temperature = None
self._pressure = None
self._rf_message_rssi = None
self._ch_temp = None
self._tap_temp = None
self._state = None
self.data = None
self.update()
@property
def state(self):
"""Return the current state."""
if self.data is not None:
if bool(self.data['IO'] & 8):
self._state = 'Verwarmen'
else:
self._state = 'Standby'
else:
self._state = None
return self._state
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE
@property
def name(self):
"""Return the name of the thermostat, if any."""
return self._name
@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
@property
def current_temperature(self):
"""Return the current temperature."""
if self.data is not None:
self._current_temperature = _lsbmsb(
self.data['room_temp_1_lsb'], self.data['room_temp_1_msb'])
else:
self._current_temperature = None
return self._current_temperature
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attr = {}
super_attr = super().device_state_attributes
if super_attr is not None:
attr.update(super_attr)
if self.data is not None:
attr[ATTR_PRESSURE] = _lsbmsb(
self.data['ch_pressure_lsb'], self.data['ch_pressure_msb'])
attr[ATTR_RSSI] = self.data['rf_message_rssi']
attr[ATTR_CH_TEMP] = _lsbmsb(
self.data['ch_temp_lsb'], self.data['ch_temp_msb'])
attr[ATTR_TAP_TEMP] = _lsbmsb(
self.data['tap_temp_lsb'], self.data['tap_temp_msb'])
else:
attr[ATTR_PRESSURE] = None
attr[ATTR_RSSI] = None
attr[ATTR_CH_TEMP] = None
attr[ATTR_TAP_TEMP] = None
return attr
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if self.data is not None:
self._target_temperature = _lsbmsb(
self.data['room_temp_set_1_lsb'], self.data['room_temp_set_1_msb'])
else:
self._target_temperature = None
return self._target_temperature
@property
def should_poll(self):
"""Return the polling state."""
return True
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
if self._auth:
requests.get('http://' + self.host + '/protect/data.json?heater=0&thermostat=0&setpoint=' +
str((min(max(temperature, 5), 30) - 5.0) * 10), auth=(self._username, self._password))
else:
requests.get('http://' + self.host + '/data.json?heater=0&thermostat=0&setpoint=' +
str((min(max(temperature, 5), 30) - 5.0) * 10))
self._target_temperature = temperature
def update(self):
"""Get the latest data."""
if self._auth:
req = requests.get('http://' + self.host + '/protect/data.json?heater=0', auth=(self._username, self._password))
else:
req = requests.get('http://' + self.host + '/data.json?heater=0')
text = req.json()
self.data = text