diff --git a/homeassistant/components/smartthings/binary_sensor.py b/homeassistant/components/smartthings/binary_sensor.py index 6d07a735127..24249345080 100644 --- a/homeassistant/components/smartthings/binary_sensor.py +++ b/homeassistant/components/smartthings/binary_sensor.py @@ -5,7 +5,7 @@ from __future__ import annotations from collections.abc import Callable 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.binary_sensor import ( @@ -38,6 +38,9 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription): category: set[Category] | None = None exists_fn: Callable[[str], bool] | 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[ @@ -66,6 +69,11 @@ CAPABILITY_TO_SENSORS: dict[ "freezer": "freezer_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: { @@ -141,6 +149,7 @@ CAPABILITY_TO_SENSORS: dict[ translation_key="valve", device_class=BinarySensorDeviceClass.OPENING, is_on_key="open", + deprecated_fn=lambda _: "valve", ) }, Capability.WATER_SENSOR: { @@ -250,7 +259,7 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity): async def async_added_to_hass(self) -> None: """Call when entity is 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 automations = automations_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( self.hass, DOMAIN, - f"deprecated_binary_valve_{self.entity_id}", + f"deprecated_binary_{issue}_{self.entity_id}", breaks_in_ha_version="2025.10.0", is_fixable=False, severity=IssueSeverity.WARNING, - translation_key="deprecated_binary_valve", + translation_key=f"deprecated_binary_{issue}", translation_placeholders={ "entity": self.entity_id, "items": "\n".join(items_list), @@ -295,6 +304,8 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity): async def async_will_remove_from_hass(self) -> None: """Call when entity will be removed 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( - self.hass, DOMAIN, f"deprecated_binary_valve_{self.entity_id}" + self.hass, DOMAIN, f"deprecated_binary_{issue}_{self.entity_id}" ) diff --git a/homeassistant/components/smartthings/strings.json b/homeassistant/components/smartthings/strings.json index 4f667121448..d97a51a9b5d 100644 --- a/homeassistant/components/smartthings/strings.json +++ b/homeassistant/components/smartthings/strings.json @@ -473,6 +473,10 @@ "deprecated_binary_valve": { "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." + }, + "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." } } } diff --git a/tests/components/smartthings/test_binary_sensor.py b/tests/components/smartthings/test_binary_sensor.py index 4d58b5ddd48..517de034613 100644 --- a/tests/components/smartthings/test_binary_sensor.py +++ b/tests/components/smartthings/test_binary_sensor.py @@ -59,16 +59,23 @@ async def test_state_update( @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( hass: HomeAssistant, devices: AsyncMock, mock_config_entry: MockConfigEntry, issue_registry: ir.IssueRegistry, + issue_string: str, + entity_id: str, ) -> None: """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_valve_{entity_id}" + issue_id = f"deprecated_binary_{issue_string}_{entity_id}" assert await async_setup_component( hass,