Skip to content

Commit 90623bb

Browse files
authored
Deprecate fridge door sensor in SmartThings (#141275)
1 parent 69a3757 commit 90623bb

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

homeassistant/components/smartthings/binary_sensor.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Callable
66
from dataclasses import dataclass
77

8-
from pysmartthings import Attribute, Capability, Category, SmartThings
8+
from pysmartthings import Attribute, Capability, Category, SmartThings, Status
99

1010
from homeassistant.components.automation import automations_with_entity
1111
from homeassistant.components.binary_sensor import (
@@ -38,6 +38,9 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription):
3838
category: set[Category] | None = None
3939
exists_fn: Callable[[str], bool] | None = None
4040
component_translation_key: dict[str, str] | None = None
41+
deprecated_fn: Callable[
42+
[dict[str, dict[Capability | str, dict[Attribute | str, Status]]]], str | None
43+
] = lambda _: None
4144

4245

4346
CAPABILITY_TO_SENSORS: dict[
@@ -66,6 +69,11 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription):
6669
"freezer": "freezer_door",
6770
"cooler": "cooler_door",
6871
},
72+
deprecated_fn=(
73+
lambda status: "fridge_door"
74+
if "freezer" in status and "cooler" in status
75+
else None
76+
),
6977
)
7078
},
7179
Capability.CUSTOM_DRYER_WRINKLE_PREVENT: {
@@ -141,6 +149,7 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription):
141149
translation_key="valve",
142150
device_class=BinarySensorDeviceClass.OPENING,
143151
is_on_key="open",
152+
deprecated_fn=lambda _: "valve",
144153
)
145154
},
146155
Capability.WATER_SENSOR: {
@@ -250,7 +259,7 @@ def is_on(self) -> bool:
250259
async def async_added_to_hass(self) -> None:
251260
"""Call when entity is added to hass."""
252261
await super().async_added_to_hass()
253-
if self.capability is not Capability.VALVE:
262+
if (issue := self.entity_description.deprecated_fn(self.device.status)) is None:
254263
return
255264
automations = automations_with_entity(self.hass, self.entity_id)
256265
scripts = scripts_with_entity(self.hass, self.entity_id)
@@ -281,11 +290,11 @@ async def async_added_to_hass(self) -> None:
281290
async_create_issue(
282291
self.hass,
283292
DOMAIN,
284-
f"deprecated_binary_valve_{self.entity_id}",
293+
f"deprecated_binary_{issue}_{self.entity_id}",
285294
breaks_in_ha_version="2025.10.0",
286295
is_fixable=False,
287296
severity=IssueSeverity.WARNING,
288-
translation_key="deprecated_binary_valve",
297+
translation_key=f"deprecated_binary_{issue}",
289298
translation_placeholders={
290299
"entity": self.entity_id,
291300
"items": "\n".join(items_list),
@@ -295,6 +304,8 @@ async def async_added_to_hass(self) -> None:
295304
async def async_will_remove_from_hass(self) -> None:
296305
"""Call when entity will be removed from hass."""
297306
await super().async_will_remove_from_hass()
307+
if (issue := self.entity_description.deprecated_fn(self.device.status)) is None:
308+
return
298309
async_delete_issue(
299-
self.hass, DOMAIN, f"deprecated_binary_valve_{self.entity_id}"
310+
self.hass, DOMAIN, f"deprecated_binary_{issue}_{self.entity_id}"
300311
)

homeassistant/components/smartthings/strings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@
473473
"deprecated_binary_valve": {
474474
"title": "Deprecated valve binary sensor detected in some automations or scripts",
475475
"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."
476+
},
477+
"deprecated_binary_fridge_door": {
478+
"title": "Deprecated refrigerator door binary sensor detected in some automations or scripts",
479+
"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."
476480
}
477481
}
478482
}

tests/components/smartthings/test_binary_sensor.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,23 @@ async def test_state_update(
5959

6060

6161
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
62-
@pytest.mark.parametrize("device_fixture", ["virtual_valve"])
62+
@pytest.mark.parametrize(
63+
("device_fixture", "issue_string", "entity_id"),
64+
[
65+
("virtual_valve", "valve", "binary_sensor.volvo_valve"),
66+
("da_ref_normal_000001", "fridge_door", "binary_sensor.refrigerator_door"),
67+
],
68+
)
6369
async def test_create_issue(
6470
hass: HomeAssistant,
6571
devices: AsyncMock,
6672
mock_config_entry: MockConfigEntry,
6773
issue_registry: ir.IssueRegistry,
74+
issue_string: str,
75+
entity_id: str,
6876
) -> None:
6977
"""Test we create an issue when an automation or script is using a deprecated entity."""
70-
entity_id = "binary_sensor.volvo_valve"
71-
issue_id = f"deprecated_binary_valve_{entity_id}"
78+
issue_id = f"deprecated_binary_{issue_string}_{entity_id}"
7279

7380
assert await async_setup_component(
7481
hass,

0 commit comments

Comments
 (0)