Skip to content

Commit 56d953a

Browse files
authored
Use contants in climate set_temperature (home-assistant#154008)
1 parent fe4eb87 commit 56d953a

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

homeassistant/components/aprilaire/climate.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from pyaprilaire.const import Attribute
88

99
from homeassistant.components.climate import (
10+
ATTR_TARGET_TEMP_HIGH,
11+
ATTR_TARGET_TEMP_LOW,
1012
FAN_AUTO,
1113
FAN_ON,
1214
PRESET_AWAY,
@@ -16,7 +18,12 @@
1618
HVACAction,
1719
HVACMode,
1820
)
19-
from homeassistant.const import PRECISION_HALVES, PRECISION_WHOLE, UnitOfTemperature
21+
from homeassistant.const import (
22+
ATTR_TEMPERATURE,
23+
PRECISION_HALVES,
24+
PRECISION_WHOLE,
25+
UnitOfTemperature,
26+
)
2027
from homeassistant.core import HomeAssistant
2128
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2229

@@ -232,15 +239,15 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
232239
cool_setpoint = 0
233240
heat_setpoint = 0
234241

235-
if temperature := kwargs.get("temperature"):
242+
if temperature := kwargs.get(ATTR_TEMPERATURE):
236243
if self.coordinator.data.get(Attribute.MODE) == 3:
237244
cool_setpoint = temperature
238245
else:
239246
heat_setpoint = temperature
240247
else:
241-
if target_temp_low := kwargs.get("target_temp_low"):
248+
if target_temp_low := kwargs.get(ATTR_TARGET_TEMP_LOW):
242249
heat_setpoint = target_temp_low
243-
if target_temp_high := kwargs.get("target_temp_high"):
250+
if target_temp_high := kwargs.get(ATTR_TARGET_TEMP_HIGH):
244251
cool_setpoint = target_temp_high
245252

246253
if cool_setpoint == 0 and heat_setpoint == 0:

homeassistant/components/bryant_evolution/climate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
from evolutionhttp import BryantEvolutionLocalClient
88

99
from homeassistant.components.climate import (
10+
ATTR_TARGET_TEMP_HIGH,
11+
ATTR_TARGET_TEMP_LOW,
1012
ClimateEntity,
1113
ClimateEntityFeature,
1214
HVACAction,
1315
HVACMode,
1416
)
15-
from homeassistant.const import UnitOfTemperature
17+
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
1618
from homeassistant.core import HomeAssistant
1719
from homeassistant.exceptions import HomeAssistantError
1820
from homeassistant.helpers.device_registry import DeviceInfo
@@ -208,24 +210,24 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
208210

209211
async def async_set_temperature(self, **kwargs: Any) -> None:
210212
"""Set new target temperature."""
211-
if kwargs.get("target_temp_high"):
212-
temp = int(kwargs["target_temp_high"])
213+
if value := kwargs.get(ATTR_TARGET_TEMP_HIGH):
214+
temp = int(value)
213215
if not await self._client.set_cooling_setpoint(temp):
214216
raise HomeAssistantError(
215217
translation_domain=DOMAIN, translation_key="failed_to_set_clsp"
216218
)
217219
self._attr_target_temperature_high = temp
218220

219-
if kwargs.get("target_temp_low"):
220-
temp = int(kwargs["target_temp_low"])
221+
if value := kwargs.get(ATTR_TARGET_TEMP_LOW):
222+
temp = int(value)
221223
if not await self._client.set_heating_setpoint(temp):
222224
raise HomeAssistantError(
223225
translation_domain=DOMAIN, translation_key="failed_to_set_htsp"
224226
)
225227
self._attr_target_temperature_low = temp
226228

227-
if kwargs.get("temperature"):
228-
temp = int(kwargs["temperature"])
229+
if value := kwargs.get(ATTR_TEMPERATURE):
230+
temp = int(value)
229231
fn = (
230232
self._client.set_heating_setpoint
231233
if self.hvac_mode == HVACMode.HEAT

homeassistant/components/evohome/climate.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
ClimateEntityFeature,
3030
HVACMode,
3131
)
32-
from homeassistant.const import ATTR_MODE, PRECISION_TENTHS, UnitOfTemperature
32+
from homeassistant.const import (
33+
ATTR_MODE,
34+
ATTR_TEMPERATURE,
35+
PRECISION_TENTHS,
36+
UnitOfTemperature,
37+
)
3338
from homeassistant.core import HomeAssistant, callback
3439
from homeassistant.exceptions import HomeAssistantError
3540
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@@ -243,7 +248,7 @@ def max_temp(self) -> float:
243248
async def async_set_temperature(self, **kwargs: Any) -> None:
244249
"""Set a new target temperature."""
245250

246-
temperature = kwargs["temperature"]
251+
temperature = kwargs[ATTR_TEMPERATURE]
247252

248253
if (until := kwargs.get("until")) is None:
249254
if self._evo_device.mode == EvoZoneMode.TEMPORARY_OVERRIDE:

homeassistant/components/melcloud/climate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,5 +408,5 @@ def target_temperature(self) -> float | None:
408408
async def async_set_temperature(self, **kwargs: Any) -> None:
409409
"""Set new target temperature."""
410410
await self._zone.set_target_temperature(
411-
kwargs.get("temperature", self.target_temperature)
411+
kwargs.get(ATTR_TEMPERATURE, self.target_temperature)
412412
)

homeassistant/components/tuya/climate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ClimateEntityFeature,
1919
HVACMode,
2020
)
21-
from homeassistant.const import UnitOfTemperature
21+
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
2222
from homeassistant.core import HomeAssistant, callback
2323
from homeassistant.helpers.dispatcher import async_dispatcher_connect
2424
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -352,7 +352,7 @@ def set_temperature(self, **kwargs: Any) -> None:
352352
{
353353
"code": self._set_temperature.dpcode,
354354
"value": round(
355-
self._set_temperature.scale_value_back(kwargs["temperature"])
355+
self._set_temperature.scale_value_back(kwargs[ATTR_TEMPERATURE])
356356
),
357357
}
358358
]

0 commit comments

Comments
 (0)