From 2d33b775c015c99cad0a2d916a5be85690225132 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 17 Sep 2026 19:48:36 +0200 Subject: [PATCH] Add AI switch to Midea (#182433) --- homeassistant/components/midea/strings.json | 3 ++ homeassistant/components/midea/switch.py | 5 ++ .../midea/snapshots/test_switch.ambr | 50 +++++++++++++++++++ tests/components/midea/test_switch.py | 39 +++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/homeassistant/components/midea/strings.json b/homeassistant/components/midea/strings.json index ab5d24699a4e..fc64be64d832 100644 --- a/homeassistant/components/midea/strings.json +++ b/homeassistant/components/midea/strings.json @@ -677,6 +677,9 @@ } }, "switch": { + "ai_switch": { + "name": "AI switch" + }, "anion": { "name": "Anion" }, diff --git a/homeassistant/components/midea/switch.py b/homeassistant/components/midea/switch.py index e2ea81e11f3f..7ec118b048c6 100644 --- a/homeassistant/components/midea/switch.py +++ b/homeassistant/components/midea/switch.py @@ -109,6 +109,11 @@ SWITCHES: list[MideaSwitchEntityDescription] = [ translation_key="night_light", models=[DeviceType.CC], ), + MideaSwitchEntityDescription( + key="ai_switch", + translation_key="ai_switch", + models=[DeviceType.DC], + ), ] diff --git a/tests/components/midea/snapshots/test_switch.ambr b/tests/components/midea/snapshots/test_switch.ambr index 34df594b5eb2..1c358daa2026 100644 --- a/tests/components/midea/snapshots/test_switch.ambr +++ b/tests/components/midea/snapshots/test_switch.ambr @@ -849,3 +849,53 @@ 'state': 'on', }) # --- +# name: test_switch_state_snapshot[dc][switch.clothes_dryer_ai_switch-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.clothes_dryer_ai_switch', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'AI switch', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'AI switch', + 'platform': 'midea', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'ai_switch', + 'unique_id': '12345678_ai_switch', + 'unit_of_measurement': None, + }) +# --- +# name: test_switch_state_snapshot[dc][switch.clothes_dryer_ai_switch-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'Clothes Dryer AI switch', + }), + 'context': , + 'entity_id': 'switch.clothes_dryer_ai_switch', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- diff --git a/tests/components/midea/test_switch.py b/tests/components/midea/test_switch.py index a34aeb2f7088..ef3851810c98 100644 --- a/tests/components/midea/test_switch.py +++ b/tests/components/midea/test_switch.py @@ -9,6 +9,7 @@ from midealocal.devices.ac import DeviceAttributes as ACAttributes from midealocal.devices.c3 import DeviceAttributes as C3Attributes from midealocal.devices.cc import DeviceAttributes as CCAttributes from midealocal.devices.cf import DeviceAttributes as CFAttributes +from midealocal.devices.dc import DeviceAttributes as DCAttributes from midealocal.exceptions import SocketException import pytest from syrupy.assertion import SnapshotAssertion @@ -134,6 +135,10 @@ async def _assert_service_call( DummyDevice(DeviceType.C2, attributes={"child_lock": True}), id="c2", ), + pytest.param( + DummyDevice(DeviceType.DC, attributes={DCAttributes.ai_switch: False}), + id="dc", + ), ], ) @pytest.mark.usefixtures("entity_registry_enabled_by_default") @@ -192,6 +197,40 @@ async def test_ac_switch_services( ) +async def test_dc_ai_switch_services( + hass: HomeAssistant, + mock_config_entry: Callable[[DummyDevice], MockConfigEntry], +) -> None: + """Test DC ai_switch service calls reach the device.""" + device = DummyDevice( + DeviceType.DC, + attributes={DCAttributes.ai_switch: False}, + ) + config_entry = mock_config_entry(device) + with patch("homeassistant.components.midea._PLATFORMS", [Platform.SWITCH]): + await setup_integration(hass, config_entry, device) + + entity_entry = entity_entries(hass, config_entry)[f"{TEST_DEVICE_ID}_ai_switch"] + + assert (state := hass.states.get(entity_entry.entity_id)) is not None + assert state.state == "off" + + await _assert_service_call( + hass, + entity_entry.entity_id, + SERVICE_TURN_ON, + [("set_attribute", DCAttributes.ai_switch, True)], + device, + ) + await _assert_service_call( + hass, + entity_entry.entity_id, + SERVICE_TURN_OFF, + [("set_attribute", DCAttributes.ai_switch, False)], + device, + ) + + CHILD_LOCK_DEVICE_TYPES = [ DeviceType.X34, DeviceType.A1,