Skip to content

Commit

Permalink
Remove deprecated supported features warning in ClimateEntity (#132206
Browse files Browse the repository at this point in the history
)

* Remove deprecated features from ClimateEntity

* Remove not needed tests

* Remove add_to_platform_start
  • Loading branch information
gjohansson-ST authored Dec 5, 2024
1 parent 17afe1a commit c41cf57
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 402 deletions.
111 changes: 0 additions & 111 deletions homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import asyncio
from datetime import timedelta
import functools as ft
import logging
Expand All @@ -28,7 +27,6 @@
from homeassistant.helpers import config_validation as cv, issue_registry as ir
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.helpers.temperature import display_temp as show_temp
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_issue_tracker, async_suggest_report_issue
Expand Down Expand Up @@ -303,115 +301,6 @@ class ClimateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):

__climate_reported_legacy_aux = False

__mod_supported_features: ClimateEntityFeature = ClimateEntityFeature(0)
# Integrations should set `_enable_turn_on_off_backwards_compatibility` to False
# once migrated and set the feature flags TURN_ON/TURN_OFF as needed.
_enable_turn_on_off_backwards_compatibility: bool = True

def __getattribute__(self, name: str, /) -> Any:
"""Get attribute.
Modify return of `supported_features` to
include `_mod_supported_features` if attribute is set.
"""
if name != "supported_features":
return super().__getattribute__(name)

# Convert the supported features to ClimateEntityFeature.
# Remove this compatibility shim in 2025.1 or later.
_supported_features: ClimateEntityFeature = super().__getattribute__(
"supported_features"
)
_mod_supported_features: ClimateEntityFeature = super().__getattribute__(
"_ClimateEntity__mod_supported_features"
)
if type(_supported_features) is int: # noqa: E721
_features = ClimateEntityFeature(_supported_features)
self._report_deprecated_supported_features_values(_features)
else:
_features = _supported_features

if not _mod_supported_features:
return _features

# Add automatically calculated ClimateEntityFeature.TURN_OFF/TURN_ON to
# supported features and return it
return _features | _mod_supported_features

@callback
def add_to_platform_start(
self,
hass: HomeAssistant,
platform: EntityPlatform,
parallel_updates: asyncio.Semaphore | None,
) -> None:
"""Start adding an entity to a platform."""
super().add_to_platform_start(hass, platform, parallel_updates)

def _report_turn_on_off(feature: str, method: str) -> None:
"""Log warning not implemented turn on/off feature."""
report_issue = self._suggest_report_issue()
if feature.startswith("TURN"):
message = (
"Entity %s (%s) does not set ClimateEntityFeature.%s"
" but implements the %s method. Please %s"
)
else:
message = (
"Entity %s (%s) implements HVACMode(s): %s and therefore implicitly"
" supports the %s methods without setting the proper"
" ClimateEntityFeature. Please %s"
)
_LOGGER.warning(
message,
self.entity_id,
type(self),
feature,
method,
report_issue,
)

# Adds ClimateEntityFeature.TURN_OFF/TURN_ON depending on service calls implemented
# This should be removed in 2025.1.
if self._enable_turn_on_off_backwards_compatibility is False:
# Return if integration has migrated already
return

supported_features = self.supported_features
if supported_features & CHECK_TURN_ON_OFF_FEATURE_FLAG:
# The entity supports both turn_on and turn_off, the backwards compatibility
# checks are not needed
return

if not supported_features & ClimateEntityFeature.TURN_OFF and (
type(self).async_turn_off is not ClimateEntity.async_turn_off
or type(self).turn_off is not ClimateEntity.turn_off
):
# turn_off implicitly supported by implementing turn_off method
_report_turn_on_off("TURN_OFF", "turn_off")
self.__mod_supported_features |= ( # pylint: disable=unused-private-member
ClimateEntityFeature.TURN_OFF
)

if not supported_features & ClimateEntityFeature.TURN_ON and (
type(self).async_turn_on is not ClimateEntity.async_turn_on
or type(self).turn_on is not ClimateEntity.turn_on
):
# turn_on implicitly supported by implementing turn_on method
_report_turn_on_off("TURN_ON", "turn_on")
self.__mod_supported_features |= ( # pylint: disable=unused-private-member
ClimateEntityFeature.TURN_ON
)

if (modes := self.hvac_modes) and len(modes) >= 2 and HVACMode.OFF in modes:
# turn_on/off implicitly supported by including more modes than 1 and one of these
# are HVACMode.OFF
_modes = [_mode for _mode in modes if _mode is not None]
_report_turn_on_off(", ".join(_modes or []), "turn_on/turn_off")
self.__mod_supported_features |= ( # pylint: disable=unused-private-member
ClimateEntityFeature.TURN_ON | ClimateEntityFeature.TURN_OFF
)

def _report_legacy_aux(self) -> None:
"""Log warning and create an issue if the entity implements legacy auxiliary heater."""

Expand Down
Loading

0 comments on commit c41cf57

Please sign in to comment.