Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate SmartThings media player switch #141467

Merged
merged 8 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions homeassistant/components/smartthings/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,23 +481,27 @@
"issues": {
"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 in 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 the new valve entity in 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 them in the above automations or scripts to fix this issue."
},
"deprecated_machine_state": {
"title": "Deprecated machine state sensor detected in some automations or scripts",
"description": "The machine state sensor `{entity}` is deprecated and is used in the following automations or scripts:\n{items}\n\nA select entity is now available for the machine state and should be used going forward. Please use them in the above automations or scripts to fix this issue."
"description": "The machine state sensor `{entity}` is deprecated and is used in the following automations or scripts:\n{items}\n\nA select entity is now available for the machine state and should be used going forward. Please use the new select entity in the above automations or scripts to fix this issue."
},
"deprecated_switch_appliance": {
"title": "Deprecated switch detected in some automations or scripts",
"description": "The switch `{entity}` is deprecated because the actions did not work, so it has been replaced with a binary sensor instead.\n\nThe switch was used in the following automations or scripts:\n{items}\n\nPlease use them in the above automations or scripts to fix this issue."
"description": "The switch `{entity}` is deprecated because the actions did not work, so it has been replaced with a binary sensor instead.\n\nThe switch was used in the following automations or scripts:\n{items}\n\nPlease use the new binary sensor in the above automations or scripts to fix this issue."
},
"deprecated_switch_media_player": {
"title": "[%key:component::smartthings::issues::deprecated_switch_appliance::title%]",
"description": "The switch `{entity}` is deprecated and a media player entity has been added to replace it.\n\nThe switch was used in the following automations or scripts:\n{items}\n\nPlease use the new media player entity in the above automations or scripts to fix this issue."
},
"deprecated_media_player": {
"title": "Deprecated sensor detected in some automations or scripts",
"description": "The sensor `{entity}` is deprecated because it has been replaced with a media player entity.\n\nThe sensor was used in the following automations or scripts:\n{items}\n\nPlease use the media player entity in the above automations or scripts to fix this issue."
"description": "The sensor `{entity}` is deprecated because it has been replaced with a media player entity.\n\nThe sensor was used in the following automations or scripts:\n{items}\n\nPlease use the new media player entity in the above automations or scripts to fix this issue."
}
}
}
47 changes: 26 additions & 21 deletions homeassistant/components/smartthings/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity):
"""Define a SmartThings switch."""

entity_description: SmartThingsSwitchEntityDescription
created_issue: bool = False

def __init__(
self,
Expand Down Expand Up @@ -184,16 +185,26 @@ def is_on(self) -> bool:
async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass."""
await super().async_added_to_hass()
if self.entity_description != SWITCH or self.device.device.components[
MAIN
].manufacturer_category not in {
Category.CLOTHING_CARE_MACHINE,
Category.COOKTOP,
Category.DRYER,
Category.WASHER,
Category.MICROWAVE,
Category.DISHWASHER,
}:
media_player = all(
capability in self.device.status[MAIN]
for capability in (
Capability.AUDIO_MUTE,
Capability.AUDIO_VOLUME,
Capability.MEDIA_PLAYBACK,
)
)
if (
self.entity_description != SWITCH
and self.device.device.components[MAIN].manufacturer_category
not in {
Category.CLOTHING_CARE_MACHINE,
Category.COOKTOP,
Category.DRYER,
Category.WASHER,
Category.MICROWAVE,
Category.DISHWASHER,
}
) or (self.entity_description != SWITCH and not media_player):
return
automations = automations_with_entity(self.hass, self.entity_id)
scripts = scripts_with_entity(self.hass, self.entity_id)
Expand All @@ -211,14 +222,17 @@ async def async_added_to_hass(self) -> None:
if (item := entity_reg.async_get(entity_id))
]

identifier = "media_player" if media_player else "appliance"

self.created_issue = True
async_create_issue(
self.hass,
DOMAIN,
f"deprecated_switch_{self.entity_id}",
breaks_in_ha_version="2025.10.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_switch_appliance",
translation_key=f"deprecated_switch_{identifier}",
translation_placeholders={
"entity": self.entity_id,
"items": "\n".join(items_list),
Expand All @@ -228,16 +242,7 @@ async def async_added_to_hass(self) -> None:
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 self.entity_description != SWITCH or self.device.device.components[
MAIN
].manufacturer_category not in {
Category.CLOTHING_CARE_MACHINE,
Category.COOKTOP,
Category.DRYER,
Category.WASHER,
Category.MICROWAVE,
Category.DISHWASHER,
}:
if not self.created_issue:
return
async_delete_issue(self.hass, DOMAIN, f"deprecated_switch_{self.entity_id}")

Expand Down
10 changes: 6 additions & 4 deletions tests/components/smartthings/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ async def test_state_update(

@pytest.mark.usefixtures("entity_registry_enabled_by_default")
@pytest.mark.parametrize(
("device_fixture", "entity_id"),
("device_fixture", "entity_id", "translation_key"),
[
("da_wm_wm_000001", "switch.washer"),
("da_wm_wd_000001", "switch.dryer"),
("da_wm_wm_000001", "switch.washer", "deprecated_switch_appliance"),
("da_wm_wd_000001", "switch.dryer", "deprecated_switch_appliance"),
("hw_q80r_soundbar", "switch.soundbar", "deprecated_switch_media_player"),
],
)
async def test_create_issue(
Expand All @@ -140,6 +141,7 @@ async def test_create_issue(
mock_config_entry: MockConfigEntry,
issue_registry: ir.IssueRegistry,
entity_id: str,
translation_key: str,
) -> None:
"""Test we create an issue when an automation or script is using a deprecated entity."""
issue_id = f"deprecated_switch_{entity_id}"
Expand Down Expand Up @@ -187,7 +189,7 @@ async def test_create_issue(
assert len(issue_registry.issues) == 1
issue = issue_registry.async_get_issue(DOMAIN, issue_id)
assert issue is not None
assert issue.translation_key == "deprecated_switch_appliance"
assert issue.translation_key == translation_key
assert issue.translation_placeholders == {
"entity": entity_id,
"items": "- [test](/config/automation/edit/test)\n- [test](/config/script/edit/test)",
Expand Down
Loading