Use UnitOfTemperature in climate entities [g-l] (#83127)

* Use UnitOfTemperature in climate entities [g-l]

* Adjust gree

* Adjust honeywell
This commit is contained in:
epenet 2022-12-05 10:42:24 +01:00 committed by GitHub
parent 40d337479e
commit 68e454712d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 60 additions and 71 deletions

View File

@ -35,12 +35,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_WHOLE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -151,7 +146,9 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
def temperature_unit(self) -> str:
"""Return the temperature units for the device."""
units = self.coordinator.device.temperature_units
return TEMP_CELSIUS if units == TemperatureUnits.C else TEMP_FAHRENHEIT
if units == TemperatureUnits.C:
return UnitOfTemperature.CELSIUS
return UnitOfTemperature.FAHRENHEIT
@property
def current_temperature(self) -> float:
@ -182,12 +179,16 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
@property
def min_temp(self) -> float:
"""Return the minimum temperature supported by the device."""
return TEMP_MIN if self.temperature_unit == TEMP_CELSIUS else TEMP_MIN_F
if self.temperature_unit == UnitOfTemperature.CELSIUS:
return TEMP_MIN
return TEMP_MIN_F
@property
def max_temp(self) -> float:
"""Return the maximum temperature supported by the device."""
return TEMP_MAX if self.temperature_unit == TEMP_CELSIUS else TEMP_MAX_F
if self.temperature_unit == UnitOfTemperature.CELSIUS:
return TEMP_MAX
return TEMP_MAX_F
@property
def target_temperature_step(self) -> float:

View File

@ -19,8 +19,7 @@ from homeassistant.const import (
CONF_ID,
CONF_NAME,
CONF_PORT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
@ -120,9 +119,9 @@ class HeatmiserV3Thermostat(ClimateEntity):
return
self.dcb = self.therm.read_dcb()
self._attr_temperature_unit = (
TEMP_CELSIUS
UnitOfTemperature.CELSIUS
if (self.therm.get_temperature_format() == "C")
else TEMP_FAHRENHEIT
else UnitOfTemperature.FAHRENHEIT
)
self._current_temperature = int(self.therm.get_floor_temp())
self._target_temperature = int(self.therm.get_target_temp())

View File

@ -25,12 +25,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_WHOLE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -184,9 +179,9 @@ class ClimateAehW4a1(ClimateEntity):
self._on = status["run_status"]
if status["temperature_Fahrenheit"] == "0":
self._attr_temperature_unit = TEMP_CELSIUS
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
else:
self._attr_temperature_unit = TEMP_FAHRENHEIT
self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
self._current_temperature = int(status["indoor_temperature_status"], 2)
@ -274,14 +269,14 @@ class ClimateAehW4a1(ClimateEntity):
@property
def min_temp(self):
"""Return the minimum temperature."""
if self.temperature_unit == TEMP_CELSIUS:
if self.temperature_unit == UnitOfTemperature.CELSIUS:
return MIN_TEMP_C
return MIN_TEMP_F
@property
def max_temp(self):
"""Return the maximum temperature."""
if self.temperature_unit == TEMP_CELSIUS:
if self.temperature_unit == UnitOfTemperature.CELSIUS:
return MAX_TEMP_C
return MAX_TEMP_F
@ -301,7 +296,7 @@ class ClimateAehW4a1(ClimateEntity):
_LOGGER.debug("Setting temp of %s to %s", self._unique_id, temp)
if self._preset_mode != PRESET_NONE:
await self.async_set_preset_mode(PRESET_NONE)
if self.temperature_unit == TEMP_CELSIUS:
if self.temperature_unit == UnitOfTemperature.CELSIUS:
await self._device.command(f"temp_{int(temp)}_C")
else:
await self._device.command(f"temp_{int(temp)}_F")

View File

@ -14,7 +14,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -45,7 +45,7 @@ HIVE_TO_HASS_HVAC_ACTION = {
True: HVACAction.HEATING,
}
TEMP_UNIT = {"C": TEMP_CELSIUS, "F": TEMP_FAHRENHEIT}
TEMP_UNIT = {"C": UnitOfTemperature.CELSIUS, "F": UnitOfTemperature.FAHRENHEIT}
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)
_LOGGER = logging.getLogger()

View File

@ -32,7 +32,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, Platform
from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -114,7 +114,7 @@ async def async_setup_entry(
class HomeKitBaseClimateEntity(HomeKitEntity, ClimateEntity):
"""The base HomeKit Controller climate entity."""
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""

View File

@ -12,7 +12,7 @@ from homeassistant.components.climate import (
ClimateEntityFeature,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -58,7 +58,7 @@ class HMThermostat(HMDevice, ClimateEntity):
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
@property
def hvac_mode(self) -> HVACMode:

View File

@ -24,7 +24,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -69,7 +69,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
_attr_supported_features = (
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
)
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None:
"""Initialize heating group."""

View File

@ -22,7 +22,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -103,9 +103,9 @@ class HoneywellUSThermostat(ClimateEntity):
self._attr_unique_id = device.deviceid
self._attr_name = device.name
self._attr_temperature_unit = (
TEMP_CELSIUS if device.temperature_unit == "C" else TEMP_FAHRENHEIT
)
self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
if device.temperature_unit == "C":
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self._attr_preset_modes = [PRESET_NONE, PRESET_AWAY, PRESET_HOLD]
self._attr_is_aux_heat = device.system_mode == "emheat"

View File

@ -11,7 +11,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -68,8 +68,8 @@ class HassAqualinkThermostat(AqualinkEntity, ClimateEntity):
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
if self.dev.unit == "F":
return TEMP_FAHRENHEIT
return TEMP_CELSIUS
return UnitOfTemperature.FAHRENHEIT
return UnitOfTemperature.CELSIUS
@property
def min_temp(self) -> int:

View File

@ -9,7 +9,7 @@ from homeassistant.components.climate import (
ClimateEntityFeature,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -41,7 +41,7 @@ class InComfortClimate(IncomfortChild, ClimateEntity):
_attr_hvac_mode = HVACMode.HEAT
_attr_hvac_modes = [HVACMode.HEAT]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, client, heater, room) -> None:
"""Initialize the climate device."""

View File

@ -17,7 +17,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -89,8 +89,8 @@ class InsteonClimateEntity(InsteonEntity, ClimateEntity):
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
if self._insteon_device.configuration[CELSIUS].value:
return TEMP_CELSIUS
return TEMP_FAHRENHEIT
return UnitOfTemperature.CELSIUS
return UnitOfTemperature.FAHRENHEIT
@property
def current_humidity(self) -> int | None:

View File

@ -10,7 +10,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -51,7 +51,7 @@ class IntellifireClimate(IntellifireEntity, ClimateEntity):
_attr_max_temp = 37
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_target_temperature_step = 1.0
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
last_temp = DEFAULT_THERMOSTAT_TEMP
def __init__(

View File

@ -27,7 +27,7 @@ from homeassistant.const import (
CONF_DEVICE,
CONF_PASSWORD,
CONF_USERNAME,
TEMP_CELSIUS,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
@ -145,7 +145,7 @@ class IntesisAC(ClimateEntity):
"""Represents an Intesishome air conditioning device."""
_attr_should_poll = False
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, ih_device_id, ih_device, controller):
"""Initialize the thermostat."""

View File

@ -29,12 +29,7 @@ from homeassistant.components.climate import (
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_TENTHS,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -103,10 +98,10 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
if not (uom := self._node.aux_properties.get(PROP_UOM)):
return self.hass.config.units.temperature_unit
if uom.value == UOM_ISY_CELSIUS:
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS
if uom.value == UOM_ISY_FAHRENHEIT:
return TEMP_FAHRENHEIT
return TEMP_FAHRENHEIT
return UnitOfTemperature.FAHRENHEIT
return UnitOfTemperature.FAHRENHEIT
@property
def current_humidity(self) -> int | None:

View File

@ -25,7 +25,7 @@ from homeassistant.const import (
CONF_EXCLUDE,
PRECISION_HALVES,
PRECISION_TENTHS,
TEMP_CELSIUS,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_platform
@ -129,7 +129,7 @@ class ControllerDevice(ClimateEntity):
_attr_precision = PRECISION_TENTHS
_attr_should_poll = False
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, controller: Controller) -> None:
"""Initialise ControllerDevice."""
@ -437,7 +437,7 @@ class ZoneDevice(ClimateEntity):
_attr_precision = PRECISION_TENTHS
_attr_should_poll = False
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, controller: ControllerDevice, zone: Zone) -> None:
"""Initialise ZoneDevice."""

View File

@ -19,8 +19,8 @@ from homeassistant.const import (
ATTR_TEMPERATURE,
CONF_ENTITY_CATEGORY,
CONF_NAME,
TEMP_CELSIUS,
Platform,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -133,7 +133,7 @@ class KNXClimate(KnxEntity, ClimateEntity):
"""Representation of a KNX climate device."""
_device: XknxClimate
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, xknx: XKNX, config: ConfigType) -> None:
"""Initialize of a KNX climate device."""

View File

@ -19,8 +19,7 @@ from homeassistant.const import (
CONF_ENTITIES,
CONF_SOURCE,
CONF_UNIT_OF_MEASUREMENT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -114,10 +113,10 @@ class LcnClimate(LcnEntity, ClimateEntity):
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
# Config schema only allows for: TEMP_CELSIUS and TEMP_FAHRENHEIT
# Config schema only allows for: UnitOfTemperature.CELSIUS and UnitOfTemperature.FAHRENHEIT
if self.unit == pypck.lcn_defs.VarUnit.FAHRENHEIT:
return TEMP_FAHRENHEIT
return TEMP_CELSIUS
return UnitOfTemperature.FAHRENHEIT
return UnitOfTemperature.CELSIUS
@property
def current_temperature(self) -> float | None:

View File

@ -11,7 +11,7 @@ from homeassistant.components.climate import (
HVACAction,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -49,7 +49,7 @@ class LightwaveTrv(ClimateEntity):
_attr_max_temp = DEFAULT_MAX_TEMP
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_target_temperature_step = 0.5
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, name, device_id, lwlink, serial):
"""Initialize LightwaveTrv entity."""

View File

@ -23,8 +23,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_WHOLE,
TEMP_CELSIUS,
Platform,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -92,7 +92,7 @@ class ConditionerEntity(LookinCoordinatorEntity, ClimateEntity):
"""An aircon or heat pump."""
_attr_current_humidity: float | None = None # type: ignore[assignment]
_attr_temperature_unit = TEMP_CELSIUS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE