From 1ff20a148501798e6641359a19b703fef64ce662 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 22 Jun 2025 12:07:07 +0000 Subject: [PATCH] Deprecate battery supported feature --- homeassistant/components/vacuum/__init__.py | 23 ++++++++++++ tests/components/vacuum/test_init.py | 39 +++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/homeassistant/components/vacuum/__init__.py b/homeassistant/components/vacuum/__init__.py index bb620e057f2..11d13431f9d 100644 --- a/homeassistant/components/vacuum/__init__.py +++ b/homeassistant/components/vacuum/__init__.py @@ -249,6 +249,7 @@ class StateVacuumEntity( __vacuum_legacy_state: bool = False __vacuum_legacy_battery_level: bool = False __vacuum_legacy_battery_icon: bool = False + __vacuum_legacy_battery_feature: bool = False def __init_subclass__(cls, **kwargs: Any) -> None: """Post initialisation processing.""" @@ -331,6 +332,25 @@ class StateVacuumEntity( 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 def battery_level(self) -> int | None: """Return the battery level of the vacuum cleaner.""" @@ -369,6 +389,9 @@ class StateVacuumEntity( supported_features = self.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_ICON] = self.battery_icon diff --git a/tests/components/vacuum/test_init.py b/tests/components/vacuum/test_init.py index 4aefe452166..77debf634ad 100644 --- a/tests/components/vacuum/test_init.py +++ b/tests/components/vacuum/test_init.py @@ -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" 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 + )