Use UnitOfTemperature in integrations (e-h) (#84305)
This commit is contained in:
parent
d89ba40010
commit
9580c4f1ec
28 changed files with 113 additions and 87 deletions
|
@ -63,8 +63,7 @@ from homeassistant.const import (
|
|||
STATE_STANDBY,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HA_DOMAIN
|
||||
from homeassistant.helpers.network import get_url
|
||||
|
@ -175,7 +174,7 @@ def register_trait(trait):
|
|||
|
||||
def _google_temp_unit(units):
|
||||
"""Return Google temperature unit."""
|
||||
if units == TEMP_FAHRENHEIT:
|
||||
if units == UnitOfTemperature.FAHRENHEIT:
|
||||
return "F"
|
||||
return "C"
|
||||
|
||||
|
@ -845,7 +844,10 @@ class TemperatureControlTrait(_Trait):
|
|||
current_temp = self.state.state
|
||||
if current_temp not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
||||
temp = round(
|
||||
TemperatureConverter.convert(float(current_temp), unit, TEMP_CELSIUS), 1
|
||||
TemperatureConverter.convert(
|
||||
float(current_temp), unit, UnitOfTemperature.CELSIUS
|
||||
),
|
||||
1,
|
||||
)
|
||||
response["temperatureSetpointCelsius"] = temp
|
||||
response["temperatureAmbientCelsius"] = temp
|
||||
|
@ -951,7 +953,10 @@ class TemperatureSettingTrait(_Trait):
|
|||
current_temp = attrs.get(climate.ATTR_CURRENT_TEMPERATURE)
|
||||
if current_temp is not None:
|
||||
response["thermostatTemperatureAmbient"] = round(
|
||||
TemperatureConverter.convert(current_temp, unit, TEMP_CELSIUS), 1
|
||||
TemperatureConverter.convert(
|
||||
current_temp, unit, UnitOfTemperature.CELSIUS
|
||||
),
|
||||
1,
|
||||
)
|
||||
|
||||
current_humidity = attrs.get(climate.ATTR_CURRENT_HUMIDITY)
|
||||
|
@ -962,27 +967,37 @@ class TemperatureSettingTrait(_Trait):
|
|||
if supported & climate.SUPPORT_TARGET_TEMPERATURE_RANGE:
|
||||
response["thermostatTemperatureSetpointHigh"] = round(
|
||||
TemperatureConverter.convert(
|
||||
attrs[climate.ATTR_TARGET_TEMP_HIGH], unit, TEMP_CELSIUS
|
||||
attrs[climate.ATTR_TARGET_TEMP_HIGH],
|
||||
unit,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
1,
|
||||
)
|
||||
response["thermostatTemperatureSetpointLow"] = round(
|
||||
TemperatureConverter.convert(
|
||||
attrs[climate.ATTR_TARGET_TEMP_LOW], unit, TEMP_CELSIUS
|
||||
attrs[climate.ATTR_TARGET_TEMP_LOW],
|
||||
unit,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
1,
|
||||
)
|
||||
else:
|
||||
if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None:
|
||||
target_temp = round(
|
||||
TemperatureConverter.convert(target_temp, unit, TEMP_CELSIUS), 1
|
||||
TemperatureConverter.convert(
|
||||
target_temp, unit, UnitOfTemperature.CELSIUS
|
||||
),
|
||||
1,
|
||||
)
|
||||
response["thermostatTemperatureSetpointHigh"] = target_temp
|
||||
response["thermostatTemperatureSetpointLow"] = target_temp
|
||||
else:
|
||||
if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None:
|
||||
response["thermostatTemperatureSetpoint"] = round(
|
||||
TemperatureConverter.convert(target_temp, unit, TEMP_CELSIUS), 1
|
||||
TemperatureConverter.convert(
|
||||
target_temp, unit, UnitOfTemperature.CELSIUS
|
||||
),
|
||||
1,
|
||||
)
|
||||
|
||||
return response
|
||||
|
@ -996,9 +1011,9 @@ class TemperatureSettingTrait(_Trait):
|
|||
|
||||
if command == COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT:
|
||||
temp = TemperatureConverter.convert(
|
||||
params["thermostatTemperatureSetpoint"], TEMP_CELSIUS, unit
|
||||
params["thermostatTemperatureSetpoint"], UnitOfTemperature.CELSIUS, unit
|
||||
)
|
||||
if unit == TEMP_FAHRENHEIT:
|
||||
if unit == UnitOfTemperature.FAHRENHEIT:
|
||||
temp = round(temp)
|
||||
|
||||
if temp < min_temp or temp > max_temp:
|
||||
|
@ -1017,9 +1032,11 @@ class TemperatureSettingTrait(_Trait):
|
|||
|
||||
elif command == COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE:
|
||||
temp_high = TemperatureConverter.convert(
|
||||
params["thermostatTemperatureSetpointHigh"], TEMP_CELSIUS, unit
|
||||
params["thermostatTemperatureSetpointHigh"],
|
||||
UnitOfTemperature.CELSIUS,
|
||||
unit,
|
||||
)
|
||||
if unit == TEMP_FAHRENHEIT:
|
||||
if unit == UnitOfTemperature.FAHRENHEIT:
|
||||
temp_high = round(temp_high)
|
||||
|
||||
if temp_high < min_temp or temp_high > max_temp:
|
||||
|
@ -1032,9 +1049,11 @@ class TemperatureSettingTrait(_Trait):
|
|||
)
|
||||
|
||||
temp_low = TemperatureConverter.convert(
|
||||
params["thermostatTemperatureSetpointLow"], TEMP_CELSIUS, unit
|
||||
params["thermostatTemperatureSetpointLow"],
|
||||
UnitOfTemperature.CELSIUS,
|
||||
unit,
|
||||
)
|
||||
if unit == TEMP_FAHRENHEIT:
|
||||
if unit == UnitOfTemperature.FAHRENHEIT:
|
||||
temp_low = round(temp_low)
|
||||
|
||||
if temp_low < min_temp or temp_low > max_temp:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue