Replace strings with library constants in deCONZ climate platform

This commit is contained in:
Robert Svensson 2021-10-02 09:08:01 +02:00 committed by GitHub
parent 4cdbd3c576
commit 8258443a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,27 @@
"""Support for deCONZ climate devices."""
from __future__ import annotations
from pydeconz.sensor import Thermostat
from pydeconz.sensor import (
THERMOSTAT_FAN_MODE_AUTO,
THERMOSTAT_FAN_MODE_HIGH,
THERMOSTAT_FAN_MODE_LOW,
THERMOSTAT_FAN_MODE_MEDIUM,
THERMOSTAT_FAN_MODE_OFF,
THERMOSTAT_FAN_MODE_ON,
THERMOSTAT_FAN_MODE_SMART,
THERMOSTAT_MODE_AUTO,
THERMOSTAT_MODE_COOL,
THERMOSTAT_MODE_HEAT,
THERMOSTAT_MODE_OFF,
THERMOSTAT_PRESET_AUTO,
THERMOSTAT_PRESET_BOOST,
THERMOSTAT_PRESET_COMFORT,
THERMOSTAT_PRESET_COMPLEX,
THERMOSTAT_PRESET_ECO,
THERMOSTAT_PRESET_HOLIDAY,
THERMOSTAT_PRESET_MANUAL,
Thermostat,
)
from homeassistant.components.climate import DOMAIN, ClimateEntity
from homeassistant.components.climate.const import (
@ -33,22 +53,22 @@ from .gateway import get_gateway_from_config_entry
DECONZ_FAN_SMART = "smart"
FAN_MODE_TO_DECONZ = {
DECONZ_FAN_SMART: "smart",
FAN_AUTO: "auto",
FAN_HIGH: "high",
FAN_MEDIUM: "medium",
FAN_LOW: "low",
FAN_ON: "on",
FAN_OFF: "off",
DECONZ_FAN_SMART: THERMOSTAT_FAN_MODE_SMART,
FAN_AUTO: THERMOSTAT_FAN_MODE_AUTO,
FAN_HIGH: THERMOSTAT_FAN_MODE_HIGH,
FAN_MEDIUM: THERMOSTAT_FAN_MODE_MEDIUM,
FAN_LOW: THERMOSTAT_FAN_MODE_LOW,
FAN_ON: THERMOSTAT_FAN_MODE_ON,
FAN_OFF: THERMOSTAT_FAN_MODE_OFF,
}
DECONZ_TO_FAN_MODE = {value: key for key, value in FAN_MODE_TO_DECONZ.items()}
HVAC_MODE_TO_DECONZ = {
HVAC_MODE_AUTO: "auto",
HVAC_MODE_COOL: "cool",
HVAC_MODE_HEAT: "heat",
HVAC_MODE_OFF: "off",
HVAC_MODE_AUTO: THERMOSTAT_MODE_AUTO,
HVAC_MODE_COOL: THERMOSTAT_MODE_COOL,
HVAC_MODE_HEAT: THERMOSTAT_MODE_HEAT,
HVAC_MODE_OFF: THERMOSTAT_MODE_OFF,
}
DECONZ_PRESET_AUTO = "auto"
@ -57,13 +77,13 @@ DECONZ_PRESET_HOLIDAY = "holiday"
DECONZ_PRESET_MANUAL = "manual"
PRESET_MODE_TO_DECONZ = {
DECONZ_PRESET_AUTO: "auto",
PRESET_BOOST: "boost",
PRESET_COMFORT: "comfort",
DECONZ_PRESET_COMPLEX: "complex",
PRESET_ECO: "eco",
DECONZ_PRESET_HOLIDAY: "holiday",
DECONZ_PRESET_MANUAL: "manual",
DECONZ_PRESET_AUTO: THERMOSTAT_PRESET_AUTO,
PRESET_BOOST: THERMOSTAT_PRESET_BOOST,
PRESET_COMFORT: THERMOSTAT_PRESET_COMFORT,
DECONZ_PRESET_COMPLEX: THERMOSTAT_PRESET_COMPLEX,
PRESET_ECO: THERMOSTAT_PRESET_ECO,
DECONZ_PRESET_HOLIDAY: THERMOSTAT_PRESET_HOLIDAY,
DECONZ_PRESET_MANUAL: THERMOSTAT_PRESET_MANUAL,
}
DECONZ_TO_PRESET_MODE = {value: key for key, value in PRESET_MODE_TO_DECONZ.items()}
@ -116,7 +136,7 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
super().__init__(device, gateway)
self._hvac_mode_to_deconz = dict(HVAC_MODE_TO_DECONZ)
if "mode" not in device.raw["config"]:
if not device.mode:
self._hvac_mode_to_deconz = {
HVAC_MODE_HEAT: True,
HVAC_MODE_OFF: False,
@ -129,10 +149,10 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE
if "fanmode" in device.raw["config"]:
if device.fan_mode:
self._attr_supported_features |= SUPPORT_FAN_MODE
if "preset" in device.raw["config"]:
if device.preset:
self._attr_supported_features |= SUPPORT_PRESET_MODE
# Fan control
@ -214,7 +234,7 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
@property
def target_temperature(self) -> float:
"""Return the target temperature."""
if self._device.mode == "cool":
if self._device.mode == THERMOSTAT_MODE_COOL:
return self._device.cooling_setpoint
return self._device.heating_setpoint