1414 CURRENT_HVAC_OFF ,
1515 SUPPORT_PRESET_MODE ,
1616 SUPPORT_TARGET_TEMPERATURE ,
17+ ATTR_CURRENT_HUMIDITY
1718)
1819from homeassistant .const import ATTR_TEMPERATURE , TEMP_CELSIUS
1920from .const import DOMAIN
2425
2526async def async_setup_entry (hass , config_entry , async_add_entities ):
2627 """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 )
2830 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+ ]
3040
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 )
4242
4343
4444class TechThermostat (ClimateEntity ):
4545 """Representation of a Tech climate."""
4646
47- def __init__ (self , device , api , config_entry ):
47+ def __init__ (self , device , api , udid ):
4848 """Initialize the Tech device."""
4949 _LOGGER .debug ("Init TechThermostat..." )
50- self ._config_entry = config_entry
50+ self ._udid = udid
5151 self ._api = api
5252 self ._id = device ["zone" ]["id" ]
53+ self ._unique_id = udid + "_" + str (device ["zone" ]["id" ])
5354 self .update_properties (device )
5455
5556 def update_properties (self , device ):
@@ -62,6 +63,10 @@ def update_properties(self, device):
6263 self ._temperature = device ["zone" ]["currentTemperature" ] / 10
6364 else :
6465 self ._temperature = None
66+ if device ["zone" ]["humidity" ] is not None :
67+ self ._humidity = device ["zone" ]["humidity" ]
68+ else :
69+ self ._humidity = None
6570 state = device ["zone" ]["flags" ]["relayState" ]
6671 if state == "on" :
6772 self ._state = CURRENT_HVAC_HEAT
@@ -78,7 +83,7 @@ def update_properties(self, device):
7883 @property
7984 def unique_id (self ) -> str :
8085 """Return a unique ID."""
81- return self ._id
86+ return self ._unique_id
8287
8388 @property
8489 def name (self ):
@@ -116,8 +121,8 @@ def hvac_action(self) -> Optional[str]:
116121
117122 async def async_update (self ):
118123 """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 )
121126 self .update_properties (device )
122127
123128 @property
@@ -130,6 +135,11 @@ def current_temperature(self):
130135 """Return the current temperature."""
131136 return self ._temperature
132137
138+ @property
139+ def current_humidity (self ):
140+ """Return current humidity."""
141+ return self ._humidity
142+
133143 @property
134144 def target_temperature (self ):
135145 """Return the temperature we try to reach."""
@@ -141,13 +151,13 @@ async def async_set_temperature(self, **kwargs):
141151 if temperature :
142152 _LOGGER .debug ("%s: Setting temperature to %s" , self ._name , temperature )
143153 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 )
145155
146156 async def async_set_hvac_mode (self , hvac_mode ):
147157 """Set new target hvac mode."""
148158 _LOGGER .debug ("%s: Setting hvac mode to %s" , self ._name , hvac_mode )
149159 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 )
151161 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 )
153163
0 commit comments