Deprecate fridge door sensor in SmartThings (#141275)

This commit is contained in:
Joost Lekkerkerker 2025-03-24 15:49:10 +01:00 committed by GitHub
parent 69a375776a
commit 90623bbaff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 8 deletions

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from pysmartthings import Attribute, Capability, Category, SmartThings from pysmartthings import Attribute, Capability, Category, SmartThings, Status
from homeassistant.components.automation import automations_with_entity from homeassistant.components.automation import automations_with_entity
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
@ -38,6 +38,9 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription):
category: set[Category] | None = None category: set[Category] | None = None
exists_fn: Callable[[str], bool] | None = None exists_fn: Callable[[str], bool] | None = None
component_translation_key: dict[str, str] | None = None component_translation_key: dict[str, str] | None = None
deprecated_fn: Callable[
[dict[str, dict[Capability | str, dict[Attribute | str, Status]]]], str | None
] = lambda _: None
CAPABILITY_TO_SENSORS: dict[ CAPABILITY_TO_SENSORS: dict[
@ -66,6 +69,11 @@ CAPABILITY_TO_SENSORS: dict[
"freezer": "freezer_door", "freezer": "freezer_door",
"cooler": "cooler_door", "cooler": "cooler_door",
}, },
deprecated_fn=(
lambda status: "fridge_door"
if "freezer" in status and "cooler" in status
else None
),
) )
}, },
Capability.CUSTOM_DRYER_WRINKLE_PREVENT: { Capability.CUSTOM_DRYER_WRINKLE_PREVENT: {
@ -141,6 +149,7 @@ CAPABILITY_TO_SENSORS: dict[
translation_key="valve", translation_key="valve",
device_class=BinarySensorDeviceClass.OPENING, device_class=BinarySensorDeviceClass.OPENING,
is_on_key="open", is_on_key="open",
deprecated_fn=lambda _: "valve",
) )
}, },
Capability.WATER_SENSOR: { Capability.WATER_SENSOR: {
@ -250,7 +259,7 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity):
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass.""" """Call when entity is added to hass."""
await super().async_added_to_hass() await super().async_added_to_hass()
if self.capability is not Capability.VALVE: if (issue := self.entity_description.deprecated_fn(self.device.status)) is None:
return return
automations = automations_with_entity(self.hass, self.entity_id) automations = automations_with_entity(self.hass, self.entity_id)
scripts = scripts_with_entity(self.hass, self.entity_id) scripts = scripts_with_entity(self.hass, self.entity_id)
@ -281,11 +290,11 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity):
async_create_issue( async_create_issue(
self.hass, self.hass,
DOMAIN, DOMAIN,
f"deprecated_binary_valve_{self.entity_id}", f"deprecated_binary_{issue}_{self.entity_id}",
breaks_in_ha_version="2025.10.0", breaks_in_ha_version="2025.10.0",
is_fixable=False, is_fixable=False,
severity=IssueSeverity.WARNING, severity=IssueSeverity.WARNING,
translation_key="deprecated_binary_valve", translation_key=f"deprecated_binary_{issue}",
translation_placeholders={ translation_placeholders={
"entity": self.entity_id, "entity": self.entity_id,
"items": "\n".join(items_list), "items": "\n".join(items_list),
@ -295,6 +304,8 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity):
async def async_will_remove_from_hass(self) -> None: async def async_will_remove_from_hass(self) -> None:
"""Call when entity will be removed from hass.""" """Call when entity will be removed from hass."""
await super().async_will_remove_from_hass() await super().async_will_remove_from_hass()
if (issue := self.entity_description.deprecated_fn(self.device.status)) is None:
return
async_delete_issue( async_delete_issue(
self.hass, DOMAIN, f"deprecated_binary_valve_{self.entity_id}" self.hass, DOMAIN, f"deprecated_binary_{issue}_{self.entity_id}"
) )

View File

@ -473,6 +473,10 @@
"deprecated_binary_valve": { "deprecated_binary_valve": {
"title": "Deprecated valve binary sensor detected in some automations or scripts", "title": "Deprecated valve binary sensor detected in some automations or scripts",
"description": "The valve binary sensor `{entity}` is deprecated and is used in the following automations or scripts:\n{items}\n\nA valve entity with controls is available and should be used going forward; Please use it on the above automations or scripts to fix this issue." "description": "The valve binary sensor `{entity}` is deprecated and is used in the following automations or scripts:\n{items}\n\nA valve entity with controls is available and should be used going forward; Please use it on the above automations or scripts to fix this issue."
},
"deprecated_binary_fridge_door": {
"title": "Deprecated refrigerator door binary sensor detected in some automations or scripts",
"description": "The refrigerator door binary sensor `{entity}` is deprecated and is used in the following automations or scripts:\n{items}\n\nSeparate entities for cooler and freezer door are available and should be used going forward; Please use it on the above automations or scripts to fix this issue."
} }
} }
} }

View File

@ -59,16 +59,23 @@ async def test_state_update(
@pytest.mark.usefixtures("entity_registry_enabled_by_default") @pytest.mark.usefixtures("entity_registry_enabled_by_default")
@pytest.mark.parametrize("device_fixture", ["virtual_valve"]) @pytest.mark.parametrize(
("device_fixture", "issue_string", "entity_id"),
[
("virtual_valve", "valve", "binary_sensor.volvo_valve"),
("da_ref_normal_000001", "fridge_door", "binary_sensor.refrigerator_door"),
],
)
async def test_create_issue( async def test_create_issue(
hass: HomeAssistant, hass: HomeAssistant,
devices: AsyncMock, devices: AsyncMock,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
issue_registry: ir.IssueRegistry, issue_registry: ir.IssueRegistry,
issue_string: str,
entity_id: str,
) -> None: ) -> None:
"""Test we create an issue when an automation or script is using a deprecated entity.""" """Test we create an issue when an automation or script is using a deprecated entity."""
entity_id = "binary_sensor.volvo_valve" issue_id = f"deprecated_binary_{issue_string}_{entity_id}"
issue_id = f"deprecated_binary_valve_{entity_id}"
assert await async_setup_component( assert await async_setup_component(
hass, hass,