From 566f257c2d7ba95addfeb2c12dec84d9a0e66c90 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 3 Sep 2026 14:42:34 +0200 Subject: [PATCH] Add lock switch to Midea (#181184) --- homeassistant/components/midea/icons.json | 3 ++ homeassistant/components/midea/strings.json | 3 ++ homeassistant/components/midea/switch.py | 15 ++++++ .../midea/snapshots/test_switch.ambr | 50 +++++++++++++++++++ tests/components/midea/test_switch.py | 49 ++++++++++++++++++ 5 files changed, 120 insertions(+) diff --git a/homeassistant/components/midea/icons.json b/homeassistant/components/midea/icons.json index a1bf5b192437..e23b7129ba94 100644 --- a/homeassistant/components/midea/icons.json +++ b/homeassistant/components/midea/icons.json @@ -79,6 +79,9 @@ "aux_heating": { "default": "mdi:radiator" }, + "child_lock": { + "default": "mdi:lock" + }, "disinfect": { "default": "mdi:bacteria" }, diff --git a/homeassistant/components/midea/strings.json b/homeassistant/components/midea/strings.json index 5cc48f523a16..5d2b52ca4eb7 100644 --- a/homeassistant/components/midea/strings.json +++ b/homeassistant/components/midea/strings.json @@ -671,6 +671,9 @@ "aux_heating": { "name": "Auxiliary heating" }, + "child_lock": { + "name": "Child lock" + }, "disinfect": { "name": "Disinfect" }, diff --git a/homeassistant/components/midea/switch.py b/homeassistant/components/midea/switch.py index b459aebd7004..f9ae21c5d85a 100644 --- a/homeassistant/components/midea/switch.py +++ b/homeassistant/components/midea/switch.py @@ -27,6 +27,21 @@ SWITCHES: list[MideaSwitchEntityDescription] = [ translation_key="aux_heating", models=[DeviceType.AC, DeviceType.CC, DeviceType.CF], ), + MideaSwitchEntityDescription( + key="child_lock", + translation_key="child_lock", + models=[ + DeviceType.X34, + DeviceType.A1, + DeviceType.C2, + DeviceType.CE, + DeviceType.E1, + DeviceType.ED, + DeviceType.FA, + DeviceType.FB, + DeviceType.FC, + ], + ), MideaSwitchEntityDescription( key="prompt_tone", translation_key="prompt_tone", diff --git a/tests/components/midea/snapshots/test_switch.ambr b/tests/components/midea/snapshots/test_switch.ambr index 7fe32a5b9e58..dbf7c45a891e 100644 --- a/tests/components/midea/snapshots/test_switch.ambr +++ b/tests/components/midea/snapshots/test_switch.ambr @@ -399,6 +399,56 @@ 'state': 'on', }) # --- +# name: test_switch_state_snapshot[c2][switch.toilet_child_lock-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.toilet_child_lock', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Child lock', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Child lock', + 'platform': 'midea', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'child_lock', + 'unique_id': '12345678_child_lock', + 'unit_of_measurement': None, + }) +# --- +# name: test_switch_state_snapshot[c2][switch.toilet_child_lock-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'Toilet Child lock', + }), + 'context': , + 'entity_id': 'switch.toilet_child_lock', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- # name: test_switch_state_snapshot[c3][switch.heat_pump_wi_fi_controller_disinfect-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/midea/test_switch.py b/tests/components/midea/test_switch.py index 2d36ef24286f..dc1c51773ba7 100644 --- a/tests/components/midea/test_switch.py +++ b/tests/components/midea/test_switch.py @@ -121,6 +121,10 @@ async def _assert_service_call( DummyDevice(DeviceType.CF, attributes={CFAttributes.aux_heating: True}), id="cf", ), + pytest.param( + DummyDevice(DeviceType.C2, attributes={"child_lock": True}), + id="c2", + ), ], ) @pytest.mark.usefixtures("entity_registry_enabled_by_default") @@ -179,6 +183,51 @@ async def test_ac_switch_services( ) +CHILD_LOCK_DEVICE_TYPES = [ + DeviceType.X34, + DeviceType.A1, + DeviceType.C2, + DeviceType.CE, + DeviceType.E1, + DeviceType.ED, + DeviceType.FA, + DeviceType.FB, + DeviceType.FC, +] + + +@pytest.mark.parametrize("device_type", CHILD_LOCK_DEVICE_TYPES) +async def test_child_lock_switch_created_and_services( + hass: HomeAssistant, + mock_config_entry: Callable[[DummyDevice], MockConfigEntry], + device_type: DeviceType, +) -> None: + """Test the child lock switch is created and its services reach the device.""" + device = DummyDevice(device_type, attributes={"child_lock": True}) + 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}_child_lock"] + assert (state := hass.states.get(entity_entry.entity_id)) is not None + assert state.state == "on" + + await _assert_service_call( + hass, + entity_entry.entity_id, + SERVICE_TURN_OFF, + [("set_attribute", "child_lock", False)], + device, + ) + await _assert_service_call( + hass, + entity_entry.entity_id, + SERVICE_TURN_ON, + [("set_attribute", "child_lock", True)], + device, + ) + + async def test_switch_unknown_when_attribute_becomes_non_bool( hass: HomeAssistant, mock_config_entry: Callable[[DummyDevice], MockConfigEntry],