From 2e3853dd7d1ba07c1b9cf538f6b519b19b7e6b47 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 26 Mar 2025 18:40:11 +0100 Subject: [PATCH] Deprecate SmartThings media player switch (#141467) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Deprecate SmartThings media player switch * Fix * Fix * Update homeassistant/components/smartthings/strings.json Co-authored-by: Abílio Costa * Fix --------- Co-authored-by: Abílio Costa --- .../components/smartthings/strings.json | 12 +++-- .../components/smartthings/switch.py | 47 ++++++++++--------- tests/components/smartthings/test_switch.py | 10 ++-- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/smartthings/strings.json b/homeassistant/components/smartthings/strings.json index 7e812845839..e4cf03178fd 100644 --- a/homeassistant/components/smartthings/strings.json +++ b/homeassistant/components/smartthings/strings.json @@ -481,7 +481,7 @@ "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", @@ -489,15 +489,19 @@ }, "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." } } } diff --git a/homeassistant/components/smartthings/switch.py b/homeassistant/components/smartthings/switch.py index dab944bb663..e5b74de3241 100644 --- a/homeassistant/components/smartthings/switch.py +++ b/homeassistant/components/smartthings/switch.py @@ -136,6 +136,7 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity): """Define a SmartThings switch.""" entity_description: SmartThingsSwitchEntityDescription + created_issue: bool = False def __init__( self, @@ -184,16 +185,26 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity): 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) @@ -211,6 +222,9 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity): 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, @@ -218,7 +232,7 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity): 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), @@ -228,16 +242,7 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchEntity): 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}") diff --git a/tests/components/smartthings/test_switch.py b/tests/components/smartthings/test_switch.py index d3908ed10f5..2e360ff68e3 100644 --- a/tests/components/smartthings/test_switch.py +++ b/tests/components/smartthings/test_switch.py @@ -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( @@ -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}" @@ -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)",