14
14
CURRENT_HVAC_OFF ,
15
15
SUPPORT_PRESET_MODE ,
16
16
SUPPORT_TARGET_TEMPERATURE ,
17
+ ATTR_CURRENT_HUMIDITY
17
18
)
18
19
from homeassistant .const import ATTR_TEMPERATURE , TEMP_CELSIUS
19
20
from .const import DOMAIN
24
25
25
26
async def async_setup_entry (hass , config_entry , async_add_entities ):
26
27
"""Set up entry."""
27
- _LOGGER .debug ("Setting up entry, module udid: " + config_entry .data ["udid" ])
28
+ udid = config_entry .data ["module" ]["udid" ]
29
+ _LOGGER .debug ("Setting up entry, module udid: " + udid )
28
30
api = hass .data [DOMAIN ][config_entry .entry_id ]
29
- zones = await api .get_module_zones (config_entry .data ["udid" ])
31
+ zones = await api .get_module_zones (udid )
32
+ thermostats = [
33
+ TechThermostat (
34
+ zones [zone ],
35
+ api ,
36
+ udid
37
+ )
38
+ for zone in zones
39
+ ]
30
40
31
- async_add_entities (
32
- [
33
- TechThermostat (
34
- zones [zone ],
35
- api ,
36
- config_entry ,
37
- )
38
- for zone in zones
39
- ],
40
- True ,
41
- )
41
+ async_add_entities (thermostats , True )
42
42
43
43
44
44
class TechThermostat (ClimateEntity ):
45
45
"""Representation of a Tech climate."""
46
46
47
- def __init__ (self , device , api , config_entry ):
47
+ def __init__ (self , device , api , udid ):
48
48
"""Initialize the Tech device."""
49
49
_LOGGER .debug ("Init TechThermostat..." )
50
- self ._config_entry = config_entry
50
+ self ._udid = udid
51
51
self ._api = api
52
52
self ._id = device ["zone" ]["id" ]
53
+ self ._unique_id = udid + "_" + str (device ["zone" ]["id" ])
53
54
self .update_properties (device )
54
55
55
56
def update_properties (self , device ):
@@ -62,6 +63,10 @@ def update_properties(self, device):
62
63
self ._temperature = device ["zone" ]["currentTemperature" ] / 10
63
64
else :
64
65
self ._temperature = None
66
+ if device ["zone" ]["humidity" ] is not None :
67
+ self ._humidity = device ["zone" ]["humidity" ]
68
+ else :
69
+ self ._humidity = None
65
70
state = device ["zone" ]["flags" ]["relayState" ]
66
71
if state == "on" :
67
72
self ._state = CURRENT_HVAC_HEAT
@@ -78,7 +83,7 @@ def update_properties(self, device):
78
83
@property
79
84
def unique_id (self ) -> str :
80
85
"""Return a unique ID."""
81
- return self ._id
86
+ return self ._unique_id
82
87
83
88
@property
84
89
def name (self ):
@@ -116,8 +121,8 @@ def hvac_action(self) -> Optional[str]:
116
121
117
122
async def async_update (self ):
118
123
"""Call by the Tech device callback to update state."""
119
- _LOGGER .debug ("Updating Tech zone: %s, udid: %s, id: %s" , self ._name , self ._config_entry . data [ "udid" ] , self ._id )
120
- device = await self ._api .get_zone (self ._config_entry . data [ "udid" ] , self ._id )
124
+ _LOGGER .debug ("Updating Tech zone: %s, udid: %s, id: %s" , self ._name , self ._udid , self ._id )
125
+ device = await self ._api .get_zone (self ._udid , self ._id )
121
126
self .update_properties (device )
122
127
123
128
@property
@@ -130,6 +135,11 @@ def current_temperature(self):
130
135
"""Return the current temperature."""
131
136
return self ._temperature
132
137
138
+ @property
139
+ def current_humidity (self ):
140
+ """Return current humidity."""
141
+ return self ._humidity
142
+
133
143
@property
134
144
def target_temperature (self ):
135
145
"""Return the temperature we try to reach."""
@@ -141,13 +151,13 @@ async def async_set_temperature(self, **kwargs):
141
151
if temperature :
142
152
_LOGGER .debug ("%s: Setting temperature to %s" , self ._name , temperature )
143
153
self ._temperature = temperature
144
- await self ._api .set_const_temp (self ._config_entry . data [ "udid" ] , self ._id , temperature )
154
+ await self ._api .set_const_temp (self ._udid , self ._id , temperature )
145
155
146
156
async def async_set_hvac_mode (self , hvac_mode ):
147
157
"""Set new target hvac mode."""
148
158
_LOGGER .debug ("%s: Setting hvac mode to %s" , self ._name , hvac_mode )
149
159
if hvac_mode == HVAC_MODE_OFF :
150
- await self ._api .set_zone (self ._config_entry . data [ "udid" ] , self ._id , False )
160
+ await self ._api .set_zone (self ._udid , self ._id , False )
151
161
elif hvac_mode == HVAC_MODE_HEAT :
152
- await self ._api .set_zone (self ._config_entry . data [ "udid" ] , self ._id , True )
162
+ await self ._api .set_zone (self ._udid , self ._id , True )
153
163
0 commit comments