mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Humidifier platform back-compat for custom components without HumidifierEntityFeature (#106613)
This commit is contained in:
parent
aa6e904e86
commit
f03bb4a2da
@ -185,7 +185,7 @@ class HumidifierEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_AT
|
||||
ATTR_MAX_HUMIDITY: self.max_humidity,
|
||||
}
|
||||
|
||||
if HumidifierEntityFeature.MODES in self.supported_features:
|
||||
if HumidifierEntityFeature.MODES in self.supported_features_compat:
|
||||
data[ATTR_AVAILABLE_MODES] = self.available_modes
|
||||
|
||||
return data
|
||||
@ -280,3 +280,16 @@ class HumidifierEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_AT
|
||||
def supported_features(self) -> HumidifierEntityFeature:
|
||||
"""Return the list of supported features."""
|
||||
return self._attr_supported_features
|
||||
|
||||
@property
|
||||
def supported_features_compat(self) -> HumidifierEntityFeature:
|
||||
"""Return the supported features as HumidifierEntityFeature.
|
||||
|
||||
Remove this compatibility shim in 2025.1 or later.
|
||||
"""
|
||||
features = self.supported_features
|
||||
if type(features) is int: # noqa: E721
|
||||
new_features = HumidifierEntityFeature(features)
|
||||
self._report_deprecated_supported_features_values(new_features)
|
||||
return new_features
|
||||
return features
|
||||
|
@ -6,7 +6,10 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import humidifier
|
||||
from homeassistant.components.humidifier import HumidifierEntity
|
||||
from homeassistant.components.humidifier import (
|
||||
HumidifierEntity,
|
||||
HumidifierEntityFeature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import import_and_test_deprecated_constant_enum
|
||||
@ -66,3 +69,23 @@ def test_deprecated_constants(
|
||||
import_and_test_deprecated_constant_enum(
|
||||
caplog, module, enum, constant_prefix, "2025.1"
|
||||
)
|
||||
|
||||
|
||||
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test deprecated supported features ints."""
|
||||
|
||||
class MockHumidifierEntity(HumidifierEntity):
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return supported features."""
|
||||
return 1
|
||||
|
||||
entity = MockHumidifierEntity()
|
||||
assert entity.supported_features_compat is HumidifierEntityFeature(1)
|
||||
assert "MockHumidifierEntity" in caplog.text
|
||||
assert "is using deprecated supported features values" in caplog.text
|
||||
assert "Instead it should use" in caplog.text
|
||||
assert "HumidifierEntityFeature.MODES" in caplog.text
|
||||
caplog.clear()
|
||||
assert entity.supported_features_compat is HumidifierEntityFeature(1)
|
||||
assert "is using deprecated supported features values" not in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user