Use _attr_temperature_unit in climate entities (#77472)

This commit is contained in:
epenet 2022-08-29 10:20:55 +02:00 committed by GitHub
parent 8ed689fede
commit 0c401bcab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 28 additions and 114 deletions

View File

@ -115,6 +115,8 @@ def format_target_temperature(target_temperature):
class DaikinClimate(ClimateEntity): class DaikinClimate(ClimateEntity):
"""Representation of a Daikin HVAC.""" """Representation of a Daikin HVAC."""
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, api: DaikinApi) -> None: def __init__(self, api: DaikinApi) -> None:
"""Initialize the climate device.""" """Initialize the climate device."""
@ -180,11 +182,6 @@ class DaikinClimate(ClimateEntity):
"""Return a unique ID.""" """Return a unique ID."""
return self._api.device.mac return self._api.device.mac
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -136,6 +136,8 @@ _PRESETS: EsphomeEnumMapper[ClimatePreset, str] = EsphomeEnumMapper(
class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEntity): class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEntity):
"""A climate implementation for ESPHome.""" """A climate implementation for ESPHome."""
_attr_temperature_unit = TEMP_CELSIUS
@property @property
def precision(self) -> float: def precision(self) -> float:
"""Return the precision of the climate device.""" """Return the precision of the climate device."""
@ -146,11 +148,6 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
# Fall back to highest precision, tenths # Fall back to highest precision, tenths
return PRECISION_TENTHS return PRECISION_TENTHS
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def hvac_modes(self) -> list[str]: def hvac_modes(self) -> list[str]:
"""Return the list of available operation modes.""" """Return the list of available operation modes."""

View File

@ -67,11 +67,7 @@ class FritzboxThermostat(FritzBoxEntity, ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement that is used."""
return TEMP_CELSIUS
@property @property
def precision(self) -> float: def precision(self) -> float:

View File

@ -56,11 +56,7 @@ class HMThermostat(HMDevice, ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS
@property
def temperature_unit(self):
"""Return the unit of measurement that is used."""
return TEMP_CELSIUS
@property @property
def hvac_mode(self) -> HVACMode: def hvac_mode(self) -> HVACMode:

View File

@ -66,6 +66,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
) )
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None: def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None:
"""Initialize heating group.""" """Initialize heating group."""
@ -86,11 +87,6 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
via_device=(HMIPC_DOMAIN, self._device.homeId), via_device=(HMIPC_DOMAIN, self._device.homeId),
) )
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def target_temperature(self) -> float: def target_temperature(self) -> float:
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""

View File

@ -37,6 +37,7 @@ class InComfortClimate(IncomfortChild, ClimateEntity):
_attr_hvac_mode = HVACMode.HEAT _attr_hvac_mode = HVACMode.HEAT
_attr_hvac_modes = [HVACMode.HEAT] _attr_hvac_modes = [HVACMode.HEAT]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, client, heater, room) -> None: def __init__(self, client, heater, room) -> None:
"""Initialize the climate device.""" """Initialize the climate device."""
@ -54,11 +55,6 @@ class InComfortClimate(IncomfortChild, ClimateEntity):
"""Return the device state attributes.""" """Return the device state attributes."""
return {"status": self._room.status} return {"status": self._room.status}
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def current_temperature(self) -> float | None: def current_temperature(self) -> float | None:
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -144,6 +144,7 @@ class IntesisAC(ClimateEntity):
"""Represents an Intesishome air conditioning device.""" """Represents an Intesishome air conditioning device."""
_attr_should_poll = False _attr_should_poll = False
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, ih_device_id, ih_device, controller): def __init__(self, ih_device_id, ih_device, controller):
"""Initialize the thermostat.""" """Initialize the thermostat."""
@ -218,11 +219,6 @@ class IntesisAC(ClimateEntity):
"""Return the name of the AC device.""" """Return the name of the AC device."""
return self._device_name return self._device_name
@property
def temperature_unit(self):
"""Intesishome API uses celsius on the backend."""
return TEMP_CELSIUS
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
"""Return the device specific state attributes.""" """Return the device specific state attributes."""

View File

@ -127,6 +127,7 @@ class ControllerDevice(ClimateEntity):
"""Representation of iZone Controller.""" """Representation of iZone Controller."""
_attr_should_poll = False _attr_should_poll = False
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, controller: Controller) -> None: def __init__(self, controller: Controller) -> None:
"""Initialise ControllerDevice.""" """Initialise ControllerDevice."""
@ -252,11 +253,6 @@ class ControllerDevice(ClimateEntity):
"""Return the name of the entity.""" """Return the name of the entity."""
return f"iZone Controller {self._controller.device_uid}" return f"iZone Controller {self._controller.device_uid}"
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
@property @property
def precision(self) -> float: def precision(self) -> float:
"""Return the precision of the system.""" """Return the precision of the system."""
@ -443,6 +439,7 @@ class ZoneDevice(ClimateEntity):
"""Representation of iZone Zone.""" """Representation of iZone Zone."""
_attr_should_poll = False _attr_should_poll = False
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, controller: ControllerDevice, zone: Zone) -> None: def __init__(self, controller: ControllerDevice, zone: Zone) -> None:
"""Initialise ZoneDevice.""" """Initialise ZoneDevice."""
@ -529,11 +526,6 @@ class ZoneDevice(ClimateEntity):
return self._attr_supported_features return self._attr_supported_features
return self._attr_supported_features & ~ClimateEntityFeature.TARGET_TEMPERATURE return self._attr_supported_features & ~ClimateEntityFeature.TARGET_TEMPERATURE
@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
@property @property
def precision(self): def precision(self):
"""Return the precision of the system.""" """Return the precision of the system."""

View File

@ -58,6 +58,7 @@ class MelissaClimate(ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
) )
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, api, serial_number, init_data): def __init__(self, api, serial_number, init_data):
"""Initialize the climate device.""" """Initialize the climate device."""
@ -124,11 +125,6 @@ class MelissaClimate(ClimateEntity):
return None return None
return self._cur_settings[self._api.TEMP] return self._cur_settings[self._api.TEMP]
@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
@property @property
def min_temp(self): def min_temp(self):
"""Return the minimum supported temperature for the thermostat.""" """Return the minimum supported temperature for the thermostat."""

View File

@ -64,6 +64,7 @@ class ThermostatDevice(ClimateEntity):
_attr_hvac_modes = SUPPORT_HVAC _attr_hvac_modes = SUPPORT_HVAC
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, thermostat, name): def __init__(self, thermostat, name):
"""Initialize the device.""" """Initialize the device."""
@ -93,11 +94,6 @@ class ThermostatDevice(ClimateEntity):
"""Return the name of this Thermostat.""" """Return the name of this Thermostat."""
return self._name return self._name
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def hvac_action(self) -> HVACAction: def hvac_action(self) -> HVACAction:
"""Return current hvac i.e. heat, cool, idle.""" """Return current hvac i.e. heat, cool, idle."""

View File

@ -66,6 +66,7 @@ class OpenThermClimate(ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, gw_dev, options): def __init__(self, gw_dev, options):
"""Initialize the device.""" """Initialize the device."""
@ -202,11 +203,6 @@ class OpenThermClimate(ClimateEntity):
return PRECISION_HALVES return PRECISION_HALVES
return PRECISION_WHOLE return PRECISION_WHOLE
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def hvac_action(self) -> HVACAction | None: def hvac_action(self) -> HVACAction | None:
"""Return current HVAC operation.""" """Return current HVAC operation."""

View File

@ -55,6 +55,7 @@ class ProliphixThermostat(ClimateEntity):
"""Representation a Proliphix thermostat.""" """Representation a Proliphix thermostat."""
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_FAHRENHEIT
def __init__(self, pdp): def __init__(self, pdp):
"""Initialize the thermostat.""" """Initialize the thermostat."""
@ -85,11 +86,6 @@ class ProliphixThermostat(ClimateEntity):
"""Return the device specific state attributes.""" """Return the device specific state attributes."""
return {ATTR_FAN: self._pdp.fan_state} return {ATTR_FAN: self._pdp.fan_state}
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_FAHRENHEIT
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -82,6 +82,7 @@ class SchluterThermostat(CoordinatorEntity, ClimateEntity):
_attr_hvac_mode = HVACMode.HEAT _attr_hvac_mode = HVACMode.HEAT
_attr_hvac_modes = [HVACMode.HEAT] _attr_hvac_modes = [HVACMode.HEAT]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, coordinator, serial_number, api, session_id): def __init__(self, coordinator, serial_number, api, session_id):
"""Initialize the thermostat.""" """Initialize the thermostat."""
@ -100,11 +101,6 @@ class SchluterThermostat(CoordinatorEntity, ClimateEntity):
"""Return the name of the thermostat.""" """Return the name of the thermostat."""
return self.coordinator.data[self._serial_number].name return self.coordinator.data[self._serial_number].name
@property
def temperature_unit(self):
"""Schluter API always uses celsius."""
return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -61,16 +61,12 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
) )
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, coordinator, spa): def __init__(self, coordinator, spa):
"""Initialize the entity.""" """Initialize the entity."""
super().__init__(coordinator, spa, "Thermostat") super().__init__(coordinator, spa, "Thermostat")
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def hvac_action(self) -> HVACAction | None: def hvac_action(self) -> HVACAction | None:
"""Return the current running hvac operation.""" """Return the current running hvac operation."""

View File

@ -35,6 +35,8 @@ async def async_setup_entry(
class SpiderThermostat(ClimateEntity): class SpiderThermostat(ClimateEntity):
"""Representation of a thermostat.""" """Representation of a thermostat."""
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, api, thermostat): def __init__(self, api, thermostat):
"""Initialize the thermostat.""" """Initialize the thermostat."""
self.api = api self.api = api
@ -75,11 +77,6 @@ class SpiderThermostat(ClimateEntity):
"""Return the name of the thermostat, if any.""" """Return the name of the thermostat, if any."""
return self.thermostat.name return self.thermostat.name
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -74,6 +74,7 @@ class StiebelEltron(ClimateEntity):
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, name, ste_data): def __init__(self, name, ste_data):
"""Initialize the unit.""" """Initialize the unit."""
@ -112,10 +113,6 @@ class StiebelEltron(ClimateEntity):
return self._name return self._name
# Handle ClimateEntityFeature.TARGET_TEMPERATURE # Handle ClimateEntityFeature.TARGET_TEMPERATURE
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):

View File

@ -213,6 +213,8 @@ 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
def __init__( def __init__(
self, self,
tado, tado,
@ -367,11 +369,6 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
"""Set new preset mode.""" """Set new preset mode."""
self._tado.set_presence(preset_mode) self._tado.set_presence(preset_mode)
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def target_temperature_step(self): def target_temperature_step(self):
"""Return the supported step of target temperature.""" """Return the supported step of target temperature."""

View File

@ -82,6 +82,7 @@ class TfiacClimate(ClimateEntity):
| ClimateEntityFeature.SWING_MODE | ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TARGET_TEMPERATURE
) )
_attr_temperature_unit = TEMP_FAHRENHEIT
def __init__(self, hass, client): def __init__(self, hass, client):
"""Init class.""" """Init class."""
@ -121,11 +122,6 @@ class TfiacClimate(ClimateEntity):
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
return self._client.status["target_temp"] return self._client.status["target_temp"]
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_FAHRENHEIT
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -64,6 +64,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
def __init__(self, touchline_thermostat): def __init__(self, touchline_thermostat):
"""Initialize the Touchline device.""" """Initialize the Touchline device."""
@ -89,11 +90,6 @@ class Touchline(ClimateEntity):
"""Return the name of the climate device.""" """Return the name of the climate device."""
return self._name return self._name
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -145,6 +145,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
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."""
@ -249,11 +250,6 @@ class ViCareClimate(ClimateEntity):
"""Return the name of the climate device.""" """Return the name of the climate device."""
return self._name return self._name
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""

View File

@ -137,6 +137,8 @@ class Thermostat(ZhaEntity, ClimateEntity):
DEFAULT_MAX_TEMP = 35 DEFAULT_MAX_TEMP = 35
DEFAULT_MIN_TEMP = 7 DEFAULT_MIN_TEMP = 7
_attr_temperature_unit = TEMP_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."""
super().__init__(unique_id, zha_device, channels, **kwargs) super().__init__(unique_id, zha_device, channels, **kwargs)
@ -334,11 +336,6 @@ class Thermostat(ZhaEntity, ClimateEntity):
return temp return temp
return round(temp / ZCL_TEMP, 1) return round(temp / ZCL_TEMP, 1)
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def max_temp(self) -> float: def max_temp(self) -> float:
"""Return the maximum temperature.""" """Return the maximum temperature."""

View File

@ -128,6 +128,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
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."""
@ -171,11 +172,6 @@ class ZhongHongClimate(ClimateEntity):
"""Return the unique ID of the HVAC.""" """Return the unique ID of the HVAC."""
return f"zhong_hong_hvac_{self._device.addr_out}_{self._device.addr_in}" return f"zhong_hong_hvac_{self._device.addr_out}_{self._device.addr_in}"
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
@property @property
def hvac_mode(self) -> HVACMode: def hvac_mode(self) -> HVACMode:
"""Return current operation ie. heat, cool, idle.""" """Return current operation ie. heat, cool, idle."""