Small code quality fix in Teslemetry (#124603)

* Fix cop_mode logic bug

* Update climate.py

* Fix attributes
pull/124969/head^2
Brett Adams 2024-09-01 00:41:00 +10:00 committed by GitHub
parent 30aa3a26ad
commit 3e60d7aa11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 9 deletions

View File

@ -183,20 +183,28 @@ COP_MODES = {
"FanOnly": HVACMode.FAN_ONLY, "FanOnly": HVACMode.FAN_ONLY,
} }
# String to celsius
COP_LEVELS = { COP_LEVELS = {
"Low": 30, "Low": 30,
"Medium": 35, "Medium": 35,
"High": 40, "High": 40,
} }
# Celsius to IntEnum
TEMP_LEVELS = {
30: CabinOverheatProtectionTemp.LOW,
35: CabinOverheatProtectionTemp.MEDIUM,
40: CabinOverheatProtectionTemp.HIGH,
}
class TeslemetryCabinOverheatProtectionEntity(TeslemetryVehicleEntity, ClimateEntity): class TeslemetryCabinOverheatProtectionEntity(TeslemetryVehicleEntity, ClimateEntity):
"""Telemetry vehicle cabin overheat protection entity.""" """Telemetry vehicle cabin overheat protection entity."""
_attr_precision = PRECISION_WHOLE _attr_precision = PRECISION_WHOLE
_attr_target_temperature_step = 5 _attr_target_temperature_step = 5
_attr_min_temp = 30 _attr_min_temp = COP_LEVELS["Low"]
_attr_max_temp = 40 _attr_max_temp = COP_LEVELS["High"]
_attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_hvac_modes = list(COP_MODES.values()) _attr_hvac_modes = list(COP_MODES.values())
_enable_turn_on_off_backwards_compatibility = False _enable_turn_on_off_backwards_compatibility = False
@ -256,13 +264,7 @@ class TeslemetryCabinOverheatProtectionEntity(TeslemetryVehicleEntity, ClimateEn
if not (temp := kwargs.get(ATTR_TEMPERATURE)): if not (temp := kwargs.get(ATTR_TEMPERATURE)):
return return
if temp == 30: if (cop_mode := TEMP_LEVELS.get(temp)) is None:
cop_mode = CabinOverheatProtectionTemp.LOW
elif temp == 35:
cop_mode = CabinOverheatProtectionTemp.MEDIUM
elif temp == 40:
cop_mode = CabinOverheatProtectionTemp.HIGH
else:
raise ServiceValidationError( raise ServiceValidationError(
translation_domain=DOMAIN, translation_domain=DOMAIN,
translation_key="invalid_cop_temp", translation_key="invalid_cop_temp",