Deprecate Homee valve sensor (#139578)

* remove valve sensor

* deprecate valve sensor

* fix

* Add deprecation issue test

* Add test for deleting disabled deprecated entities

* parametrize issue test

* eliminate one if iteration

* review change 1

* review change 2

* add info where to find valve

* Update homeassistant/components/homee/sensor.py

---------

Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Markus Adrario
2025-05-09 15:37:23 +02:00
committed by GitHub
parent bd28452807
commit 75b8cb19cf
4 changed files with 155 additions and 64 deletions

View File

@@ -6,16 +6,19 @@ import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.homee.const import (
DOMAIN,
OPEN_CLOSE_MAP,
OPEN_CLOSE_MAP_REVERSED,
WINDOW_MAP,
WINDOW_MAP_REVERSED,
)
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import entity_registry as er, issue_registry as ir
from . import async_update_attribute_value, build_mock_node, setup_integration
from .conftest import HOMEE_ID
from tests.common import MockConfigEntry, snapshot_platform
@@ -25,15 +28,22 @@ def enable_all_entities(entity_registry_enabled_by_default: None) -> None:
"""Make sure all entities are enabled."""
async def setup_sensor(
hass: HomeAssistant, mock_homee: MagicMock, mock_config_entry: MockConfigEntry
) -> None:
"""Setups the integration for sensor tests."""
mock_homee.nodes = [build_mock_node("sensors.json")]
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
await setup_integration(hass, mock_config_entry)
async def test_up_down_values(
hass: HomeAssistant,
mock_homee: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test values for up/down sensor."""
mock_homee.nodes = [build_mock_node("sensors.json")]
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
await setup_integration(hass, mock_config_entry)
await setup_sensor(hass, mock_homee, mock_config_entry)
assert hass.states.get("sensor.test_multisensor_state").state == OPEN_CLOSE_MAP[0]
@@ -60,9 +70,7 @@ async def test_window_position(
mock_config_entry: MockConfigEntry,
) -> None:
"""Test values for window handle position."""
mock_homee.nodes = [build_mock_node("sensors.json")]
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
await setup_integration(hass, mock_config_entry)
await setup_sensor(hass, mock_homee, mock_config_entry)
assert (
hass.states.get("sensor.test_multisensor_window_position").state
@@ -87,6 +95,79 @@ async def test_window_position(
)
@pytest.mark.parametrize(
("disabler", "expected_entity", "expected_issue"),
[
(None, False, False),
(er.RegistryEntryDisabler.USER, True, True),
],
)
async def test_sensor_deprecation(
hass: HomeAssistant,
mock_homee: MagicMock,
mock_config_entry: MockConfigEntry,
issue_registry: ir.IssueRegistry,
entity_registry: er.EntityRegistry,
disabler: er.RegistryEntryDisabler,
expected_entity: bool,
expected_issue: bool,
) -> None:
"""Test sensor deprecation issue."""
entity_uid = f"{HOMEE_ID}-1-9"
entity_id = "test_multisensor_valve_position"
entity_registry.async_get_or_create(
SENSOR_DOMAIN,
DOMAIN,
entity_uid,
suggested_object_id=entity_id,
disabled_by=disabler,
)
with patch(
"homeassistant.components.homee.sensor.entity_used_in", return_value=True
):
await setup_sensor(hass, mock_homee, mock_config_entry)
assert (entity_registry.async_get(f"sensor.{entity_id}") is None) is expected_entity
assert (
issue_registry.async_get_issue(
domain=DOMAIN,
issue_id=f"deprecated_entity_{entity_uid}",
)
is None
) is expected_issue
async def test_sensor_deprecation_unused_entity(
hass: HomeAssistant,
mock_homee: MagicMock,
mock_config_entry: MockConfigEntry,
issue_registry: ir.IssueRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test sensor deprecation issue."""
entity_uid = f"{HOMEE_ID}-1-9"
entity_id = "test_multisensor_valve_position"
entity_registry.async_get_or_create(
SENSOR_DOMAIN,
DOMAIN,
entity_uid,
suggested_object_id=entity_id,
disabled_by=None,
)
await setup_sensor(hass, mock_homee, mock_config_entry)
assert entity_registry.async_get(f"sensor.{entity_id}") is not None
assert (
issue_registry.async_get_issue(
domain=DOMAIN,
issue_id=f"deprecated_entity_{entity_uid}",
)
is None
)
async def test_sensor_snapshot(
hass: HomeAssistant,
mock_homee: MagicMock,