mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Add AI switch to Midea (#182433)
This commit is contained in:
@@ -677,6 +677,9 @@
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"ai_switch": {
|
||||
"name": "AI switch"
|
||||
},
|
||||
"anion": {
|
||||
"name": "Anion"
|
||||
},
|
||||
|
||||
@@ -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],
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -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': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'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': <ANY>,
|
||||
'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({
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Clothes Dryer AI switch',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.clothes_dryer_ai_switch',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user