Add lock switch to Midea (#181184)

This commit is contained in:
Simone Chemelli
2026-09-03 14:42:34 +02:00
committed by GitHub
parent 7639813247
commit 566f257c2d
5 changed files with 120 additions and 0 deletions
@@ -79,6 +79,9 @@
"aux_heating": {
"default": "mdi:radiator"
},
"child_lock": {
"default": "mdi:lock"
},
"disinfect": {
"default": "mdi:bacteria"
},
@@ -671,6 +671,9 @@
"aux_heating": {
"name": "Auxiliary heating"
},
"child_lock": {
"name": "Child lock"
},
"disinfect": {
"name": "Disinfect"
},
+15
View File
@@ -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",
@@ -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': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.toilet_child_lock',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'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({
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Toilet Child lock',
}),
'context': <ANY>,
'entity_id': 'switch.toilet_child_lock',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switch_state_snapshot[c3][switch.heat_pump_wi_fi_controller_disinfect-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
+49
View File
@@ -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],