3333from homeassistant .helpers .event import async_track_state_change
3434from . import DOMAIN as TAHOMA_DOMAIN , TahomaDevice
3535
36+ DEFAULT_TOLERANCE = 0.3
37+
38+ CONF_MIN_TEMP = "min_temp"
39+ CONF_MAX_TEMP = "max_temp"
40+ CONF_TARGET_TEMP = "target_temp"
3641CONF_AWAY_TEMP = "away_temp"
3742CONF_ECO_TEMP = "eco_temp"
3843CONF_COMFORT_TEMP = "comfort_temp"
3944CONF_ANTI_FREEZE_TEMP = "anti_freeze_temp"
45+ CONF_COLD_TOLERANCE = "cold_tolerance"
46+ CONF_HOT_TOLERANCE = "hot_tolerance"
47+ CONF_INITIAL_HVAC_MODE = "initial_hvac_mode"
4048
4149SUPPORT_AWAY_TEMP = 1
4250SUPPORT_ECO_TEMP = 2
4957 {
5058 vol .Required (CONF_NAME ): cv .string ,
5159 vol .Required (CONF_ENTITY_ID ): cv .entity_domain ("sensor" ),
52- vol .Optional (CONF_AWAY_TEMP ): vol .Coerce (float ),
60+ vol .Optional (CONF_MIN_TEMP ): vol .Coerce (float ),
61+ vol .Optional (CONF_MAX_TEMP ): vol .Coerce (float ),
62+ vol .Optional (CONF_COLD_TOLERANCE , default = DEFAULT_TOLERANCE ): vol .Coerce (float ),
63+ vol .Optional (CONF_HOT_TOLERANCE , default = DEFAULT_TOLERANCE ): vol .Coerce (float ),
64+ vol .Optional (CONF_INITIAL_HVAC_MODE ): vol .In (
65+ [HVAC_MODE_HEAT , HVAC_MODE_OFF ]
66+ ),
67+ vol .Optional (CONF_TARGET_TEMP ): vol .Coerce (float ),
5368 vol .Optional (CONF_ECO_TEMP ): vol .Coerce (float ),
5469 vol .Optional (CONF_COMFORT_TEMP ): vol .Coerce (float ),
5570 vol .Optional (CONF_ANTI_FREEZE_TEMP ): vol .Coerce (float ),
71+ vol .Optional (CONF_AWAY_TEMP ): vol .Coerce (float ),
5672 }
5773)
5874
@@ -77,10 +93,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
7793 for sensor in config ["sensors" ]:
7894 if sensor [CONF_NAME ] == name :
7995 device_sensor = sensor [CONF_ENTITY_ID ]
96+ min_temp = config .get (CONF_MIN_TEMP )
97+ max_temp = config .get (CONF_MAX_TEMP )
98+ cold_tolerance = config .get (CONF_COLD_TOLERANCE )
99+ hot_tolerance = config .get (CONF_HOT_TOLERANCE )
100+ target_temp = config .get (CONF_TARGET_TEMP )
80101 away_temp = sensor .get (CONF_AWAY_TEMP )
81102 eco_temp = sensor .get (CONF_ECO_TEMP )
82103 comfort_temp = sensor .get (CONF_COMFORT_TEMP )
83104 anti_freeze_temp = sensor .get (CONF_ANTI_FREEZE_TEMP )
105+ initial_hvac_mode = config .get (CONF_INITIAL_HVAC_MODE )
84106
85107 if device_sensor is None :
86108 _LOGGER .error ("Could not find a sensor for thermostat " + name )
@@ -91,6 +113,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
91113 device ,
92114 controller ,
93115 device_sensor ,
116+ min_temp ,
117+ max_temp ,
118+ cold_tolerance ,
119+ hot_tolerance ,
120+ initial_hvac_mode ,
121+ target_temp ,
94122 away_temp ,
95123 eco_temp ,
96124 comfort_temp ,
@@ -109,6 +137,12 @@ def __init__(
109137 tahoma_device ,
110138 controller ,
111139 sensor_entity_id ,
140+ min_temp ,
141+ max_temp ,
142+ cold_tolerance ,
143+ hot_tolerance ,
144+ initial_hvac_mode ,
145+ target_temp ,
112146 away_temp ,
113147 eco_temp ,
114148 comfort_temp ,
@@ -118,22 +152,12 @@ def __init__(
118152 super ().__init__ (tahoma_device , controller )
119153 if self .tahoma_device .type == "io:AtlanticElectricalHeaterIOComponent" :
120154 self ._type = "io"
121- if self .tahoma_device .active_states ["core:OnOffState" ] == "on" :
122- self ._hvac_mode = HVAC_MODE_HEAT
123- else :
124- self ._hvac_mode = HVAC_MODE_OFF
125155 if (
126156 self .tahoma_device .type
127157 == "somfythermostat:SomfyThermostatThermostatComponent"
128158 ):
129159 self ._type = "thermostat"
130- if (
131- self .tahoma_device .active_states ["core:DerogationActivationState" ]
132- == "active"
133- ):
134- self ._hvac_mode = HVAC_MODE_HEAT
135- else :
136- self ._hvac_mode = HVAC_MODE_OFF
160+ self ._hvac_mode = initial_hvac_mode
137161 self ._cur_temp = None
138162 self ._unit = TEMP_CELSIUS
139163 self .sensor_entity_id = sensor_entity_id
@@ -142,6 +166,11 @@ def __init__(
142166 self ._hvac_list = [HVAC_MODE_HEAT , HVAC_MODE_OFF ]
143167 self ._preset_mode = None
144168 self ._somfy_modes = 0
169+ self ._cold_tolerance = cold_tolerance
170+ self ._hot_tolerance = hot_tolerance
171+ self ._min_temp = min_temp
172+ self ._max_temp = max_temp
173+ self ._target_temp = target_temp
145174 self ._away_temp = away_temp
146175 self ._eco_temp = eco_temp
147176 self ._comfort_temp = comfort_temp
@@ -164,17 +193,13 @@ def __init__(
164193 if away_temp or eco_temp or comfort_temp or anti_freeze_temp or self ._somfy_modes :
165194 self ._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
166195 self ._preset_mode = PRESET_NONE
167- self ._target_temp = 21
168- self ._saved_target_temp = self ._target_temp
196+ self ._saved_target_temp = target_temp or comfort_temp or away_temp or eco_temp or anti_freeze_temp
169197 self ._temp_lock = asyncio .Lock ()
170198 self ._active = False
171- self ._cold_tolerance = 0.3
172- self ._hot_tolerance = 0.3
173199 self ._update_caller = "none"
174200
175201 def update (self ):
176202 """Update method."""
177- from time import sleep
178203 self .controller .get_states ([self .tahoma_device ])
179204 sensor_state = self .hass .states .get (self .sensor_entity_id )
180205 if sensor_state and sensor_state .state != STATE_UNKNOWN :
@@ -186,10 +211,6 @@ def update(self):
186211 else :
187212 self ._current_hvac_mode = CURRENT_HVAC_HEAT
188213 if self ._type == "thermostat" :
189- # if self.tahoma_device.active_states["somfythermostat:HeatingModeState"] == "freezeMode":
190- # self._target_temp = self.tahoma_device.active_states["somfythermostat:FreezeModeTargetTemperatureState"]
191- # else:
192- # self._target_temp = self.tahoma_device.active_states["core:TargetTemperatureState"]
193214 state = self .tahoma_device .active_states ["somfythermostat:DerogationHeatingModeState" ]
194215 _LOGGER .debug ("caller: %s, target: %s, saved: %s" , self ._update_caller , self ._target_temp ,
195216 self ._saved_target_temp )
@@ -327,6 +348,24 @@ def _is_device_active(self):
327348 state = self .tahoma_device .active_states ["core:OnOffState" ]
328349 return state == "on"
329350
351+ @property
352+ def min_temp (self ):
353+ """Return the minimum temperature."""
354+ if self ._min_temp is not None :
355+ return self ._min_temp
356+
357+ # get default temp from super class
358+ return super ().min_temp
359+
360+ @property
361+ def max_temp (self ):
362+ """Return the maximum temperature."""
363+ if self ._max_temp is not None :
364+ return self ._max_temp
365+
366+ # Get default temp from super class
367+ return super ().max_temp
368+
330369 def _apply_action (self , target_temperature ):
331370 if target_temperature < 16 :
332371 target_temperature = 16
0 commit comments