mirror of
https://github.com/home-assistant/core.git
synced 2025-09-11 15:51:47 +02:00
Silence vacuum battery deprecation for built in integrations (#150204)
This commit is contained in:
committed by
Franck Nijhof
parent
4765d9da92
commit
beca01e857
@@ -333,7 +333,7 @@ class StateVacuumEntity(
|
|||||||
f"is setting the {property} which has been deprecated."
|
f"is setting the {property} which has been deprecated."
|
||||||
f" Integration {self.platform.platform_name} should implement a sensor"
|
f" Integration {self.platform.platform_name} should implement a sensor"
|
||||||
" instead with a correct device class and link it to the same device",
|
" instead with a correct device class and link it to the same device",
|
||||||
core_integration_behavior=ReportBehavior.LOG,
|
core_integration_behavior=ReportBehavior.IGNORE,
|
||||||
custom_integration_behavior=ReportBehavior.LOG,
|
custom_integration_behavior=ReportBehavior.LOG,
|
||||||
breaks_in_ha_version="2026.8",
|
breaks_in_ha_version="2026.8",
|
||||||
integration_domain=self.platform.platform_name,
|
integration_domain=self.platform.platform_name,
|
||||||
@@ -358,7 +358,7 @@ class StateVacuumEntity(
|
|||||||
f" Integration {self.platform.platform_name} should remove this as part of migrating"
|
f" Integration {self.platform.platform_name} should remove this as part of migrating"
|
||||||
" the battery level and icon to a sensor",
|
" the battery level and icon to a sensor",
|
||||||
core_behavior=ReportBehavior.LOG,
|
core_behavior=ReportBehavior.LOG,
|
||||||
core_integration_behavior=ReportBehavior.LOG,
|
core_integration_behavior=ReportBehavior.IGNORE,
|
||||||
custom_integration_behavior=ReportBehavior.LOG,
|
custom_integration_behavior=ReportBehavior.LOG,
|
||||||
breaks_in_ha_version="2026.8",
|
breaks_in_ha_version="2026.8",
|
||||||
integration_domain=self.platform.platform_name,
|
integration_domain=self.platform.platform_name,
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
import logging
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -437,11 +438,13 @@ async def test_vacuum_deprecated_state_does_not_break_state(
|
|||||||
assert state.state == "cleaning"
|
assert state.state == "cleaning"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_as_custom_component")
|
@pytest.mark.parametrize(("is_built_in", "log_warnings"), [(True, 0), (False, 3)])
|
||||||
async def test_vacuum_log_deprecated_battery_properties(
|
async def test_vacuum_log_deprecated_battery_using_properties(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_flow_fixture: None,
|
config_flow_fixture: None,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
is_built_in: bool,
|
||||||
|
log_warnings: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test incorrectly using battery properties logs warning."""
|
"""Test incorrectly using battery properties logs warning."""
|
||||||
|
|
||||||
@@ -449,7 +452,7 @@ async def test_vacuum_log_deprecated_battery_properties(
|
|||||||
"""Mocked vacuum entity."""
|
"""Mocked vacuum entity."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def activity(self) -> str:
|
def activity(self) -> VacuumActivity:
|
||||||
"""Return the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
return VacuumActivity.CLEANING
|
return VacuumActivity.CLEANING
|
||||||
|
|
||||||
@@ -477,7 +480,7 @@ async def test_vacuum_log_deprecated_battery_properties(
|
|||||||
async_setup_entry=help_async_setup_entry_init,
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
async_unload_entry=help_async_unload_entry,
|
async_unload_entry=help_async_unload_entry,
|
||||||
),
|
),
|
||||||
built_in=False,
|
built_in=is_built_in,
|
||||||
)
|
)
|
||||||
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
@@ -486,26 +489,27 @@ async def test_vacuum_log_deprecated_battery_properties(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_icon which has been deprecated."
|
len([record for record in caplog.records if record.levelno >= logging.WARNING])
|
||||||
" Integration test should implement a sensor instead with a correct device class and link it"
|
== log_warnings
|
||||||
" to the same device. This will stop working in Home Assistant 2026.8,"
|
|
||||||
" please report it to the author of the 'test' custom integration"
|
|
||||||
in caplog.text
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_level which has been deprecated."
|
"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"
|
|
||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
) != is_built_in
|
||||||
|
assert (
|
||||||
|
"integration 'test' is setting the battery_level which has been deprecated."
|
||||||
|
in caplog.text
|
||||||
|
) != is_built_in
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_as_custom_component")
|
@pytest.mark.parametrize(("is_built_in", "log_warnings"), [(True, 0), (False, 3)])
|
||||||
async def test_vacuum_log_deprecated_battery_properties_using_attr(
|
async def test_vacuum_log_deprecated_battery_using_attr(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_flow_fixture: None,
|
config_flow_fixture: None,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
is_built_in: bool,
|
||||||
|
log_warnings: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test incorrectly using _attr_battery_* attribute does log issue and raise repair."""
|
"""Test incorrectly using _attr_battery_* attribute does log issue and raise repair."""
|
||||||
|
|
||||||
@@ -531,7 +535,7 @@ async def test_vacuum_log_deprecated_battery_properties_using_attr(
|
|||||||
async_setup_entry=help_async_setup_entry_init,
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
async_unload_entry=help_async_unload_entry,
|
async_unload_entry=help_async_unload_entry,
|
||||||
),
|
),
|
||||||
built_in=False,
|
built_in=is_built_in,
|
||||||
)
|
)
|
||||||
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
@@ -541,47 +545,51 @@ async def test_vacuum_log_deprecated_battery_properties_using_attr(
|
|||||||
entity.start()
|
entity.start()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_level which has been deprecated."
|
len([record for record in caplog.records if record.levelno >= logging.WARNING])
|
||||||
" Integration test should implement a sensor instead with a correct device class and link it to"
|
== log_warnings
|
||||||
" the same device. This will stop working in Home Assistant 2026.8,"
|
|
||||||
" please report it to the author of the 'test' custom integration"
|
|
||||||
in caplog.text
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_icon which has been deprecated."
|
"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"
|
|
||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
) != is_built_in
|
||||||
|
assert (
|
||||||
|
"integration 'test' is setting the battery_icon which has been deprecated."
|
||||||
|
in caplog.text
|
||||||
|
) != is_built_in
|
||||||
|
|
||||||
await async_start(hass, entity.entity_id)
|
await async_start(hass, entity.entity_id)
|
||||||
|
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
|
||||||
await async_start(hass, entity.entity_id)
|
await async_start(hass, entity.entity_id)
|
||||||
|
|
||||||
# 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."
|
len([record for record in caplog.records if record.levelno >= logging.WARNING])
|
||||||
not in caplog.text
|
== 0
|
||||||
)
|
|
||||||
assert (
|
|
||||||
"Detected that custom integration 'test' is setting the battery_icon which has been deprecated."
|
|
||||||
not in caplog.text
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_as_custom_component")
|
@pytest.mark.parametrize(("is_built_in", "log_warnings"), [(True, 0), (False, 1)])
|
||||||
async def test_vacuum_log_deprecated_battery_supported_feature(
|
async def test_vacuum_log_deprecated_battery_supported_feature(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_flow_fixture: None,
|
config_flow_fixture: None,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
is_built_in: bool,
|
||||||
|
log_warnings: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test incorrectly setting battery supported feature logs warning."""
|
"""Test incorrectly setting battery supported feature logs warning."""
|
||||||
|
|
||||||
entity = MockVacuum(
|
class MockVacuum(StateVacuumEntity):
|
||||||
name="Testing",
|
"""Mock vacuum class."""
|
||||||
entity_id="vacuum.test",
|
|
||||||
|
_attr_supported_features = (
|
||||||
|
VacuumEntityFeature.STATE | VacuumEntityFeature.BATTERY
|
||||||
)
|
)
|
||||||
|
_attr_name = "Testing"
|
||||||
|
|
||||||
|
entity = MockVacuum()
|
||||||
config_entry = MockConfigEntry(domain="test")
|
config_entry = MockConfigEntry(domain="test")
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@@ -592,7 +600,7 @@ async def test_vacuum_log_deprecated_battery_supported_feature(
|
|||||||
async_setup_entry=help_async_setup_entry_init,
|
async_setup_entry=help_async_setup_entry_init,
|
||||||
async_unload_entry=help_async_unload_entry,
|
async_unload_entry=help_async_unload_entry,
|
||||||
),
|
),
|
||||||
built_in=False,
|
built_in=is_built_in,
|
||||||
)
|
)
|
||||||
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
setup_test_component_platform(hass, DOMAIN, [entity], from_config_entry=True)
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
@@ -601,13 +609,14 @@ async def test_vacuum_log_deprecated_battery_supported_feature(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery supported feature"
|
len([record for record in caplog.records if record.levelno >= logging.WARNING])
|
||||||
" which has been deprecated. Integration test should remove this as part of migrating"
|
== log_warnings
|
||||||
" the battery level and icon to a sensor. This will stop working in Home Assistant 2026.8"
|
|
||||||
", please report it to the author of the 'test' custom integration"
|
|
||||||
in caplog.text
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"integration 'test' is setting the battery supported feature" in caplog.text
|
||||||
|
) != is_built_in
|
||||||
|
|
||||||
|
|
||||||
async def test_vacuum_not_log_deprecated_battery_properties_during_init(
|
async def test_vacuum_not_log_deprecated_battery_properties_during_init(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@@ -624,7 +633,7 @@ async def test_vacuum_not_log_deprecated_battery_properties_during_init(
|
|||||||
self._attr_battery_level = 50
|
self._attr_battery_level = 50
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def activity(self) -> str:
|
def activity(self) -> VacuumActivity:
|
||||||
"""Return the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
return VacuumActivity.CLEANING
|
return VacuumActivity.CLEANING
|
||||||
|
|
||||||
@@ -635,6 +644,6 @@ async def test_vacuum_not_log_deprecated_battery_properties_during_init(
|
|||||||
assert entity.battery_level == 50
|
assert entity.battery_level == 50
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"Detected that custom integration 'test' is setting the battery_level which has been deprecated."
|
len([record for record in caplog.records if record.levelno >= logging.WARNING])
|
||||||
not in caplog.text
|
== 0
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user