Use UnitOfTemperature in climate entities [t-z] (#83129)

This commit is contained in:
epenet 2022-12-05 10:18:57 +01:00 committed by GitHub
parent ee5de654ab
commit c7a6b5983f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 44 additions and 44 deletions

View file

@ -16,7 +16,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -213,7 +213,7 @@ def create_climate_entity(tado, name: str, zone_id: int, device_info: dict):
class TadoClimate(TadoZoneEntity, ClimateEntity): class TadoClimate(TadoZoneEntity, ClimateEntity):
"""Representation of a Tado climate entity.""" """Representation of a Tado climate entity."""
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__( def __init__(
self, self,

View file

@ -23,7 +23,7 @@ from homeassistant.components.climate import (
ClimateEntityFeature, ClimateEntityFeature,
HVACMode, HVACMode,
) )
from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, TEMP_FAHRENHEIT from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -84,7 +84,7 @@ class TfiacClimate(ClimateEntity):
| ClimateEntityFeature.SWING_MODE | ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TARGET_TEMPERATURE
) )
_attr_temperature_unit = TEMP_FAHRENHEIT _attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
def __init__(self, hass, client): def __init__(self, hass, client):
"""Init class.""" """Init class."""

View file

@ -14,7 +14,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -55,7 +55,7 @@ class SaunaClimate(ToloSaunaCoordinatorEntity, ClimateEntity):
| ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.FAN_MODE
) )
_attr_target_temperature_step = 1 _attr_target_temperature_step = 1
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__( def __init__(
self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry

View file

@ -21,7 +21,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -50,7 +50,7 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__( def __init__(
self, self,

View file

@ -12,7 +12,7 @@ from homeassistant.components.climate import (
ClimateEntityFeature, ClimateEntityFeature,
HVACMode, HVACMode,
) )
from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -68,7 +68,7 @@ class Touchline(ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, touchline_thermostat): def __init__(self, touchline_thermostat):
"""Initialize the Touchline device.""" """Initialize the Touchline device."""

View file

@ -18,7 +18,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -147,16 +147,16 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
) or all( ) or all(
dpcode in device.status for dpcode in (DPCode.TEMP_SET, DPCode.TEMP_SET_F) dpcode in device.status for dpcode in (DPCode.TEMP_SET, DPCode.TEMP_SET_F)
): ):
prefered_temperature_unit = TEMP_CELSIUS prefered_temperature_unit = UnitOfTemperature.CELSIUS
if any( if any(
"f" in device.status[dpcode].lower() "f" in device.status[dpcode].lower()
for dpcode in (DPCode.C_F, DPCode.TEMP_UNIT_CONVERT) for dpcode in (DPCode.C_F, DPCode.TEMP_UNIT_CONVERT)
if isinstance(device.status.get(dpcode), str) if isinstance(device.status.get(dpcode), str)
): ):
prefered_temperature_unit = TEMP_FAHRENHEIT prefered_temperature_unit = UnitOfTemperature.FAHRENHEIT
# Default to Celsius # Default to Celsius
self._attr_temperature_unit = TEMP_CELSIUS self._attr_temperature_unit = UnitOfTemperature.CELSIUS
# Figure out current temperature, use preferred unit or what is available # Figure out current temperature, use preferred unit or what is available
celsius_type = self.find_dpcode( celsius_type = self.find_dpcode(
@ -166,13 +166,16 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
(DPCode.TEMP_CURRENT_F, DPCode.UPPER_TEMP_F), dptype=DPType.INTEGER (DPCode.TEMP_CURRENT_F, DPCode.UPPER_TEMP_F), dptype=DPType.INTEGER
) )
if farhenheit_type and ( if farhenheit_type and (
prefered_temperature_unit == TEMP_FAHRENHEIT prefered_temperature_unit == UnitOfTemperature.FAHRENHEIT
or (prefered_temperature_unit == TEMP_CELSIUS and not celsius_type) or (
prefered_temperature_unit == UnitOfTemperature.CELSIUS
and not celsius_type
)
): ):
self._attr_temperature_unit = TEMP_FAHRENHEIT self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
self._current_temperature = farhenheit_type self._current_temperature = farhenheit_type
elif celsius_type: elif celsius_type:
self._attr_temperature_unit = TEMP_CELSIUS self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self._current_temperature = celsius_type self._current_temperature = celsius_type
# Figure out setting temperature, use preferred unit or what is available # Figure out setting temperature, use preferred unit or what is available
@ -183,8 +186,11 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
DPCode.TEMP_SET_F, dptype=DPType.INTEGER, prefer_function=True DPCode.TEMP_SET_F, dptype=DPType.INTEGER, prefer_function=True
) )
if farhenheit_type and ( if farhenheit_type and (
prefered_temperature_unit == TEMP_FAHRENHEIT prefered_temperature_unit == UnitOfTemperature.FAHRENHEIT
or (prefered_temperature_unit == TEMP_CELSIUS and not celsius_type) or (
prefered_temperature_unit == UnitOfTemperature.CELSIUS
and not celsius_type
)
): ):
self._set_temperature = farhenheit_type self._set_temperature = farhenheit_type
elif celsius_type: elif celsius_type:

View file

@ -11,7 +11,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -40,7 +40,7 @@ class VelbusClimate(VelbusEntity, ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_hvac_mode = HVACMode.HEAT _attr_hvac_mode = HVACMode.HEAT
_attr_hvac_modes = [HVACMode.HEAT] _attr_hvac_modes = [HVACMode.HEAT]
_attr_preset_modes = list(PRESET_MODES) _attr_preset_modes = list(PRESET_MODES)

View file

@ -28,8 +28,7 @@ from homeassistant.const import (
CONF_USERNAME, CONF_USERNAME,
PRECISION_HALVES, PRECISION_HALVES,
STATE_ON, STATE_ON,
TEMP_CELSIUS, UnitOfTemperature,
TEMP_FAHRENHEIT,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -145,8 +144,8 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
def temperature_unit(self) -> str: def temperature_unit(self) -> str:
"""Return the unit of measurement, as defined by the API.""" """Return the unit of measurement, as defined by the API."""
if self._client.tempunits == self._client.TEMPUNITS_F: if self._client.tempunits == self._client.TEMPUNITS_F:
return TEMP_FAHRENHEIT return UnitOfTemperature.FAHRENHEIT
return TEMP_CELSIUS return UnitOfTemperature.CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):

View file

@ -14,12 +14,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature
ATTR_TEMPERATURE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
Platform,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -104,9 +99,9 @@ class VeraThermostat(VeraDevice[veraApi.VeraThermostat], ClimateEntity):
vera_temp_units = self.vera_device.vera_controller.temperature_units vera_temp_units = self.vera_device.vera_controller.temperature_units
if vera_temp_units == "F": if vera_temp_units == "F":
return TEMP_FAHRENHEIT return UnitOfTemperature.FAHRENHEIT
return TEMP_CELSIUS return UnitOfTemperature.CELSIUS
@property @property
def current_temperature(self) -> float | None: def current_temperature(self) -> float | None:

View file

@ -27,7 +27,7 @@ from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
PRECISION_TENTHS, PRECISION_TENTHS,
PRECISION_WHOLE, PRECISION_WHOLE,
TEMP_CELSIUS, UnitOfTemperature,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_platform from homeassistant.helpers import entity_platform
@ -147,7 +147,7 @@ class ViCareClimate(ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, name, api, circuit, device_config, heating_type): def __init__(self, name, api, circuit, device_config, heating_type):
"""Initialize the climate device.""" """Initialize the climate device."""

View file

@ -22,7 +22,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity import generate_entity_id from homeassistant.helpers.entity import generate_entity_id
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -102,7 +102,7 @@ class AirConEntity(ClimateEntity):
) )
_attr_swing_modes = SUPPORTED_SWING_MODES _attr_swing_modes = SUPPORTED_SWING_MODES
_attr_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP _attr_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_should_poll = False _attr_should_poll = False
def __init__(self, hass, said, name, backend_selector: BackendSelector, auth: Auth): def __init__(self, hass, said, name, backend_selector: BackendSelector, auth: Auth):

View file

@ -16,7 +16,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -67,7 +67,7 @@ class YoLinkClimateEntity(YoLinkEntity, ClimateEntity):
super().__init__(config_entry, coordinator) super().__init__(config_entry, coordinator)
self._attr_unique_id = f"{coordinator.device.device_id}_climate" self._attr_unique_id = f"{coordinator.device.device_id}_climate"
self._attr_name = f"{coordinator.device.device_name} (Thermostat)" self._attr_name = f"{coordinator.device.device_name} (Thermostat)"
self._attr_temperature_unit = TEMP_CELSIUS self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self._attr_fan_modes = [FAN_ON, FAN_AUTO] self._attr_fan_modes = [FAN_ON, FAN_AUTO]
self._attr_min_temp = -10 self._attr_min_temp = -10
self._attr_max_temp = 50 self._attr_max_temp = 50

View file

@ -33,8 +33,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
PRECISION_TENTHS, PRECISION_TENTHS,
TEMP_CELSIUS,
Platform, Platform,
UnitOfTemperature,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -139,7 +139,7 @@ class Thermostat(ZhaEntity, ClimateEntity):
DEFAULT_MIN_TEMP = 7 DEFAULT_MIN_TEMP = 7
_attr_precision = PRECISION_TENTHS _attr_precision = PRECISION_TENTHS
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, unique_id, zha_device, channels, **kwargs): def __init__(self, unique_id, zha_device, channels, **kwargs):
"""Initialize ZHA Thermostat instance.""" """Initialize ZHA Thermostat instance."""

View file

@ -20,7 +20,7 @@ from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_PORT, CONF_PORT,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
TEMP_CELSIUS, UnitOfTemperature,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -130,7 +130,7 @@ class ZhongHongClimate(ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, hub, addr_out, addr_in): def __init__(self, hub, addr_out, addr_in):
"""Set up the ZhongHong climate devices.""" """Set up the ZhongHong climate devices."""