mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Don't log deprecation warning in vacuum until after entity added to hass (#147959)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
This commit is contained in:
parent
8007bf1c31
commit
a46cc82916
@ -321,16 +321,18 @@ class StateVacuumEntity(
|
|||||||
|
|
||||||
Integrations should implement a sensor instead.
|
Integrations should implement a sensor instead.
|
||||||
"""
|
"""
|
||||||
report_usage(
|
if self.platform:
|
||||||
f"is setting the {property} which has been deprecated."
|
# Don't report usage until after entity added to hass, after init
|
||||||
f" Integration {self.platform.platform_name} should implement a sensor"
|
report_usage(
|
||||||
" instead with a correct device class and link it to the same device",
|
f"is setting the {property} which has been deprecated."
|
||||||
core_integration_behavior=ReportBehavior.LOG,
|
f" Integration {self.platform.platform_name} should implement a sensor"
|
||||||
custom_integration_behavior=ReportBehavior.LOG,
|
" instead with a correct device class and link it to the same device",
|
||||||
breaks_in_ha_version="2026.8",
|
core_integration_behavior=ReportBehavior.LOG,
|
||||||
integration_domain=self.platform.platform_name if self.platform else None,
|
custom_integration_behavior=ReportBehavior.LOG,
|
||||||
exclude_integrations={DOMAIN},
|
breaks_in_ha_version="2026.8",
|
||||||
)
|
integration_domain=self.platform.platform_name,
|
||||||
|
exclude_integrations={DOMAIN},
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _report_deprecated_battery_feature(self) -> None:
|
def _report_deprecated_battery_feature(self) -> None:
|
||||||
@ -339,17 +341,19 @@ class StateVacuumEntity(
|
|||||||
Integrations should remove the battery supported feature when migrating
|
Integrations should remove the battery supported feature when migrating
|
||||||
battery level and icon to a sensor.
|
battery level and icon to a sensor.
|
||||||
"""
|
"""
|
||||||
report_usage(
|
if self.platform:
|
||||||
f"is setting the battery supported feature which has been deprecated."
|
# Don't report usage until after entity added to hass, after init
|
||||||
f" Integration {self.platform.platform_name} should remove this as part of migrating"
|
report_usage(
|
||||||
" the battery level and icon to a sensor",
|
f"is setting the battery supported feature which has been deprecated."
|
||||||
core_behavior=ReportBehavior.LOG,
|
f" Integration {self.platform.platform_name} should remove this as part of migrating"
|
||||||
core_integration_behavior=ReportBehavior.LOG,
|
" the battery level and icon to a sensor",
|
||||||
custom_integration_behavior=ReportBehavior.LOG,
|
core_behavior=ReportBehavior.LOG,
|
||||||
breaks_in_ha_version="2026.8",
|
core_integration_behavior=ReportBehavior.LOG,
|
||||||
integration_domain=self.platform.platform_name if self.platform else None,
|
custom_integration_behavior=ReportBehavior.LOG,
|
||||||
exclude_integrations={DOMAIN},
|
breaks_in_ha_version="2026.8",
|
||||||
)
|
integration_domain=self.platform.platform_name,
|
||||||
|
exclude_integrations={DOMAIN},
|
||||||
|
)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def battery_level(self) -> int | None:
|
def battery_level(self) -> int | None:
|
||||||
|
@ -562,16 +562,10 @@ async def test_vacuum_log_deprecated_battery_properties_using_attr(
|
|||||||
# Test we only log once
|
# Test we only log once
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_level which has been deprecated."
|
"Detected that custom integration 'test' is setting the battery_level which has been deprecated."
|
||||||
" Integration test should implement a sensor instead with a correct device class and link it to"
|
|
||||||
" the same device. This will stop working in Home Assistant 2026.8,"
|
|
||||||
" please report it to the author of the 'test' custom integration"
|
|
||||||
not in caplog.text
|
not in caplog.text
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_icon which has been deprecated."
|
"Detected that custom integration 'test' is setting the battery_icon which has been deprecated."
|
||||||
" Integration test should implement a sensor instead with a correct device class and link it to"
|
|
||||||
" the same device. This will stop working in Home Assistant 2026.8,"
|
|
||||||
" please report it to the author of the 'test' custom integration"
|
|
||||||
not in caplog.text
|
not in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -613,3 +607,34 @@ async def test_vacuum_log_deprecated_battery_supported_feature(
|
|||||||
", please report it to the author of the 'test' custom integration"
|
", please report it to the author of the 'test' custom integration"
|
||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_vacuum_not_log_deprecated_battery_properties_during_init(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
|
"""Test not logging deprecation until after added to hass."""
|
||||||
|
|
||||||
|
class MockLegacyVacuum(MockVacuum):
|
||||||
|
"""Mocked vacuum entity."""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs: Any) -> None:
|
||||||
|
"""Initialize a mock vacuum entity."""
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self._attr_battery_level = 50
|
||||||
|
|
||||||
|
@property
|
||||||
|
def activity(self) -> str:
|
||||||
|
"""Return the state of the entity."""
|
||||||
|
return VacuumActivity.CLEANING
|
||||||
|
|
||||||
|
entity = MockLegacyVacuum(
|
||||||
|
name="Testing",
|
||||||
|
entity_id="vacuum.test",
|
||||||
|
)
|
||||||
|
assert entity.battery_level == 50
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"Detected that custom integration 'test' is setting the battery_level which has been deprecated."
|
||||||
|
not in caplog.text
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user