forked from home-assistant/core
Deprecate battery supported feature
This commit is contained in:
@@ -249,6 +249,7 @@ class StateVacuumEntity(
|
|||||||
__vacuum_legacy_state: bool = False
|
__vacuum_legacy_state: bool = False
|
||||||
__vacuum_legacy_battery_level: bool = False
|
__vacuum_legacy_battery_level: bool = False
|
||||||
__vacuum_legacy_battery_icon: bool = False
|
__vacuum_legacy_battery_icon: bool = False
|
||||||
|
__vacuum_legacy_battery_feature: bool = False
|
||||||
|
|
||||||
def __init_subclass__(cls, **kwargs: Any) -> None:
|
def __init_subclass__(cls, **kwargs: Any) -> None:
|
||||||
"""Post initialisation processing."""
|
"""Post initialisation processing."""
|
||||||
@@ -331,6 +332,25 @@ class StateVacuumEntity(
|
|||||||
exclude_integrations={DOMAIN},
|
exclude_integrations={DOMAIN},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _report_deprecated_battery_feature(self) -> None:
|
||||||
|
"""Report on deprecated use of battery supported features.
|
||||||
|
|
||||||
|
Integrations should remove the battery supported feature when migrating
|
||||||
|
battery level and icon to a sensor.
|
||||||
|
"""
|
||||||
|
report_usage(
|
||||||
|
f"is setting the battery supported feature which has been deprecated."
|
||||||
|
f" Integration {self.platform.platform_name} should remove this as part of migrating"
|
||||||
|
" the battery level and icon to a sensor",
|
||||||
|
core_behavior=ReportBehavior.LOG,
|
||||||
|
core_integration_behavior=ReportBehavior.LOG,
|
||||||
|
custom_integration_behavior=ReportBehavior.LOG,
|
||||||
|
breaks_in_ha_version="2026.7",
|
||||||
|
integration_domain=self.platform.platform_name if self.platform else None,
|
||||||
|
exclude_integrations={DOMAIN},
|
||||||
|
)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def battery_level(self) -> int | None:
|
def battery_level(self) -> int | None:
|
||||||
"""Return the battery level of the vacuum cleaner."""
|
"""Return the battery level of the vacuum cleaner."""
|
||||||
@@ -369,6 +389,9 @@ class StateVacuumEntity(
|
|||||||
supported_features = self.supported_features
|
supported_features = self.supported_features
|
||||||
|
|
||||||
if VacuumEntityFeature.BATTERY in supported_features:
|
if VacuumEntityFeature.BATTERY in supported_features:
|
||||||
|
if self.__vacuum_legacy_battery_feature is False:
|
||||||
|
self._report_deprecated_battery_feature()
|
||||||
|
self.__vacuum_legacy_battery_feature = True
|
||||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||||
data[ATTR_BATTERY_ICON] = self.battery_icon
|
data[ATTR_BATTERY_ICON] = self.battery_icon
|
||||||
|
|
||||||
|
@@ -574,3 +574,42 @@ async def test_vacuum_log_deprecated_battery_properties_using_attr(
|
|||||||
" please report it to the author of the 'test' custom integration"
|
" please report it to the author of the 'test' custom integration"
|
||||||
not in caplog.text
|
not in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_as_custom_component")
|
||||||
|
async def test_vacuum_log_deprecated_battery_supported_feature(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_flow_fixture: None,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
|
"""Test incorrectly setting battery supported feature logs warning."""
|
||||||
|
|
||||||
|
entity = MockVacuum(
|
||||||
|
name="Testing",
|
||||||
|
entity_id="vacuum.test",
|
||||||
|
)
|
||||||
|
config_entry = MockConfigEntry(domain="test")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
mock_integration(
|
||||||
|
hass,
|
||||||
|
MockModule(
|
||||||
|
"test",
|
||||||
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
|
async_unload_entry=help_async_unload_entry,
|
||||||
|
),
|
||||||
|
built_in=False,
|
||||||
|
)
|
||||||
|
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
|
||||||
|
state = hass.states.get(entity.entity_id)
|
||||||
|
assert state is not None
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"Detected that custom integration 'test' is setting the battery supported feature"
|
||||||
|
" which has been deprecated. Integration test should remove this as part of migrating"
|
||||||
|
" the battery level and icon to a sensor. This will stop working in Home Assistant 2026.7"
|
||||||
|
", please report it to the author of the 'test' custom integration"
|
||||||
|
in caplog.text
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user