Enforce ClimateEntityFeature (#82329)

This commit is contained in:
epenet 2022-11-22 07:08:53 +01:00 committed by GitHub
parent 8b54a0679f
commit 48cc3071bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 18 additions and 19 deletions

View file

@ -225,7 +225,7 @@ class ClimateEntity(Entity):
_attr_precision: float
_attr_preset_mode: str | None
_attr_preset_modes: list[str] | None
_attr_supported_features: ClimateEntityFeature | int = 0
_attr_supported_features: ClimateEntityFeature = ClimateEntityFeature(0)
_attr_swing_mode: str | None
_attr_swing_modes: list[str] | None
_attr_target_humidity: int | None = None
@ -552,7 +552,7 @@ class ClimateEntity(Entity):
await self.async_set_hvac_mode(HVACMode.OFF)
@property
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
return self._attr_supported_features

View file

@ -20,7 +20,7 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import DOMAIN
SUPPORT_FLAGS = 0
SUPPORT_FLAGS = ClimateEntityFeature(0)
async def async_setup_platform(

View file

@ -197,9 +197,9 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
return self._static_info.visual_max_temperature
@property
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
features = 0
features = ClimateEntityFeature(0)
if self._static_info.supports_two_point_target_temperature:
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
else:

View file

@ -148,9 +148,9 @@ class HomeKitBaseClimateEntity(HomeKitEntity, ClimateEntity):
)
@property
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
features = 0
features = ClimateEntityFeature(0)
if self.service.has(CharacteristicsTypes.FAN_STATE_TARGET):
features |= ClimateEntityFeature.FAN_MODE
@ -368,7 +368,7 @@ class HomeKitHeaterCoolerEntity(HomeKitBaseClimateEntity):
)
@property
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
features = super().supported_features
@ -602,7 +602,7 @@ class HomeKitClimateEntity(HomeKitBaseClimateEntity):
return [MODE_HOMEKIT_TO_HASS[mode] for mode in valid_values]
@property
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
features = super().supported_features

View file

@ -517,7 +517,7 @@ class ZoneDevice(ClimateEntity):
@property
@_return_on_connection_error(0)
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
if self._zone.mode == Zone.Mode.AUTO:
return self._attr_supported_features

View file

@ -456,7 +456,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
config.get(key), entity=self
).async_render
support: ClimateEntityFeature | int = 0
support = ClimateEntityFeature(0)
if (self._topic[CONF_TEMP_STATE_TOPIC] is not None) or (
self._topic[CONF_TEMP_COMMAND_TOPIC] is not None
):

View file

@ -77,9 +77,9 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
_attr_hvac_modes = OPERATION_LIST
@property
def supported_features(self) -> ClimateEntityFeature | int:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
features = 0
features = ClimateEntityFeature(0)
set_req = self.gateway.const.SetReq
if set_req.V_HVAC_SPEED in self._values:
features = features | ClimateEntityFeature.FAN_MODE

View file

@ -104,7 +104,6 @@ class ThermostatEntity(ClimateEntity):
"""Initialize ThermostatEntity."""
self._device = device
self._device_info = NestDeviceInfo(device)
self._attr_supported_features = 0
@property
def unique_id(self) -> str | None:
@ -266,9 +265,9 @@ class ThermostatEntity(ClimateEntity):
return FAN_INV_MODES
return []
def _get_supported_features(self) -> int:
def _get_supported_features(self) -> ClimateEntityFeature:
"""Compute the bitmap of supported features from the current state."""
features = 0
features = ClimateEntityFeature(0)
if HVACMode.HEAT_COOL in self.hvac_modes:
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
if HVACMode.HEAT in self.hvac_modes or HVACMode.COOL in self.hvac_modes:

View file

@ -176,9 +176,9 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
self._attr_supported_features = self.get_features()
self._attr_precision = PRECISION_TENTHS
def get_features(self) -> ClimateEntityFeature | int:
def get_features(self) -> ClimateEntityFeature:
"""Get supported features."""
features = 0
features = ClimateEntityFeature(0)
for key in self.device_data.full_features:
if key in FIELD_TO_FLAG:
features |= FIELD_TO_FLAG[key]

View file

@ -1055,7 +1055,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
),
TypeHintMatch(
function_name="supported_features",
return_type=["ClimateEntityFeature", "int"],
return_type="ClimateEntityFeature",
),
TypeHintMatch(
function_name="min_temp",