mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Add washing machine controls to Midea (#184228)
This commit is contained in:
@@ -103,6 +103,9 @@
|
||||
"pump": {
|
||||
"default": "mdi:water-pump"
|
||||
},
|
||||
"running": {
|
||||
"default": "mdi:play"
|
||||
},
|
||||
"screen_display": {
|
||||
"default": "mdi:monitor"
|
||||
},
|
||||
|
||||
@@ -715,12 +715,18 @@
|
||||
"out_silent": {
|
||||
"name": "Outdoor silent mode"
|
||||
},
|
||||
"power": {
|
||||
"name": "Power"
|
||||
},
|
||||
"prompt_tone": {
|
||||
"name": "Prompt tone"
|
||||
},
|
||||
"pump": {
|
||||
"name": "Pump"
|
||||
},
|
||||
"running": {
|
||||
"name": "Running"
|
||||
},
|
||||
"screen_display": {
|
||||
"name": "Screen display"
|
||||
},
|
||||
|
||||
@@ -5,7 +5,11 @@ from typing import Any, override
|
||||
|
||||
from midealocal.const import DeviceType
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||
from homeassistant.components.switch import (
|
||||
SwitchDeviceClass,
|
||||
SwitchEntity,
|
||||
SwitchEntityDescription,
|
||||
)
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
@@ -124,6 +128,18 @@ SWITCHES: list[MideaSwitchEntityDescription] = [
|
||||
models=[DeviceType.CC],
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
MideaSwitchEntityDescription(
|
||||
key="power",
|
||||
translation_key="power",
|
||||
models=[DeviceType.DA, DeviceType.DB, DeviceType.DC],
|
||||
device_class=SwitchDeviceClass.SWITCH,
|
||||
),
|
||||
MideaSwitchEntityDescription(
|
||||
key="start",
|
||||
translation_key="running",
|
||||
models=[DeviceType.DA, DeviceType.DB, DeviceType.DC],
|
||||
device_class=SwitchDeviceClass.SWITCH,
|
||||
),
|
||||
MideaSwitchEntityDescription(
|
||||
key="ai_switch",
|
||||
translation_key="ai_switch",
|
||||
|
||||
@@ -849,6 +849,210 @@
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[da][switch.top_load_washer_power-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.top_load_washer_power',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Power',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Power',
|
||||
'platform': 'midea',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'power',
|
||||
'unique_id': '12345678_power',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[da][switch.top_load_washer_power-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'switch',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Top Load Washer Power',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.top_load_washer_power',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[da][switch.top_load_washer_running-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.top_load_washer_running',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Running',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Running',
|
||||
'platform': 'midea',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'running',
|
||||
'unique_id': '12345678_start',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[da][switch.top_load_washer_running-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'switch',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Top Load Washer Running',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.top_load_washer_running',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[db][switch.front_load_washer_power-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.front_load_washer_power',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Power',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Power',
|
||||
'platform': 'midea',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'power',
|
||||
'unique_id': '12345678_power',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[db][switch.front_load_washer_power-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'switch',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Front Load Washer Power',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.front_load_washer_power',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[db][switch.front_load_washer_running-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.front_load_washer_running',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Running',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Running',
|
||||
'platform': 'midea',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'running',
|
||||
'unique_id': '12345678_start',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[db][switch.front_load_washer_running-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'switch',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Front Load Washer Running',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.front_load_washer_running',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[dc][switch.clothes_dryer_ai_switch-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
@@ -899,3 +1103,105 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[dc][switch.clothes_dryer_power-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_power',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Power',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Power',
|
||||
'platform': 'midea',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'power',
|
||||
'unique_id': '12345678_power',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[dc][switch.clothes_dryer_power-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'switch',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Clothes Dryer Power',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.clothes_dryer_power',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[dc][switch.clothes_dryer_running-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_running',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Running',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Running',
|
||||
'platform': 'midea',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'running',
|
||||
'unique_id': '12345678_start',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_state_snapshot[dc][switch.clothes_dryer_running-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'switch',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Clothes Dryer Running',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.clothes_dryer_running',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -9,6 +9,8 @@ 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.da import DeviceAttributes as DAAttributes
|
||||
from midealocal.devices.db import DeviceAttributes as DBAttributes
|
||||
from midealocal.devices.dc import DeviceAttributes as DCAttributes
|
||||
from midealocal.exceptions import SocketException
|
||||
import pytest
|
||||
@@ -19,7 +21,13 @@ from homeassistant.components.switch import (
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@@ -136,7 +144,28 @@ async def _assert_service_call(
|
||||
id="c2",
|
||||
),
|
||||
pytest.param(
|
||||
DummyDevice(DeviceType.DC, attributes={DCAttributes.ai_switch: False}),
|
||||
DummyDevice(
|
||||
DeviceType.DA,
|
||||
attributes={DAAttributes.power: False, DAAttributes.start: False},
|
||||
),
|
||||
id="da",
|
||||
),
|
||||
pytest.param(
|
||||
DummyDevice(
|
||||
DeviceType.DB,
|
||||
attributes={DBAttributes.power: False, DBAttributes.start: False},
|
||||
),
|
||||
id="db",
|
||||
),
|
||||
pytest.param(
|
||||
DummyDevice(
|
||||
DeviceType.DC,
|
||||
attributes={
|
||||
DCAttributes.power: False,
|
||||
DCAttributes.start: False,
|
||||
DCAttributes.ai_switch: False,
|
||||
},
|
||||
),
|
||||
id="dc",
|
||||
),
|
||||
],
|
||||
@@ -276,6 +305,61 @@ async def test_child_lock_switch_created_and_services(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("device_type", "switch"),
|
||||
[
|
||||
(DeviceType.DA, "power"),
|
||||
(DeviceType.DA, "start"),
|
||||
(DeviceType.DB, "power"),
|
||||
(DeviceType.DB, "start"),
|
||||
(DeviceType.DC, "power"),
|
||||
(DeviceType.DC, "start"),
|
||||
],
|
||||
)
|
||||
async def test_washing_machine_switch_services(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
|
||||
device_type: DeviceType,
|
||||
switch: str,
|
||||
) -> None:
|
||||
"""Test the washing machine start switch service calls reach the device."""
|
||||
|
||||
device = DummyDevice(
|
||||
device_type,
|
||||
attributes={"power": False, "start": 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}_{switch}"]
|
||||
|
||||
assert (state := hass.states.get(entity_entry.entity_id)) is not None
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
await _assert_service_call(
|
||||
hass,
|
||||
entity_entry.entity_id,
|
||||
SERVICE_TURN_ON,
|
||||
[("set_attribute", switch, True)],
|
||||
device,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (state := hass.states.get(entity_entry.entity_id)) is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
await _assert_service_call(
|
||||
hass,
|
||||
entity_entry.entity_id,
|
||||
SERVICE_TURN_OFF,
|
||||
[("set_attribute", switch, False)],
|
||||
device,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (state := hass.states.get(entity_entry.entity_id)) is not None
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_a1_pump_services(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
|
||||
@@ -293,7 +377,7 @@ async def test_a1_pump_services(
|
||||
entity_entry = entity_entries(hass, config_entry)[f"{TEST_DEVICE_ID}_pump"]
|
||||
|
||||
assert (state := hass.states.get(entity_entry.entity_id)) is not None
|
||||
assert state.state == "off"
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
await _assert_service_call(
|
||||
hass,
|
||||
@@ -304,7 +388,7 @@ async def test_a1_pump_services(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (state := hass.states.get(entity_entry.entity_id)) is not None
|
||||
assert state.state == "on"
|
||||
assert state.state == STATE_ON
|
||||
|
||||
await _assert_service_call(
|
||||
hass,
|
||||
@@ -315,7 +399,7 @@ async def test_a1_pump_services(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (state := hass.states.get(entity_entry.entity_id)) is not None
|
||||
assert state.state == "off"
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_a1_pump_not_created_without_capability(
|
||||
@@ -356,21 +440,21 @@ async def test_switch_unknown_when_attribute_becomes_non_bool(
|
||||
|
||||
entity_entry = entity_entries(hass, config_entry)[f"{TEST_DEVICE_ID}_aux_heating"]
|
||||
assert (state := hass.states.get(entity_entry.entity_id))
|
||||
assert state.state == "off"
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
device.attributes[ACAttributes.aux_heating] = True
|
||||
device.notify_update({ACAttributes.aux_heating: True})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get(entity_entry.entity_id))
|
||||
assert state.state == "on"
|
||||
assert state.state == STATE_ON
|
||||
|
||||
device.attributes[ACAttributes.aux_heating] = None
|
||||
device.notify_update({ACAttributes.aux_heating: None})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get(entity_entry.entity_id))
|
||||
assert state.state == "unknown"
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_switch_turn_on_raises_on_device_communication_error(
|
||||
|
||||
Reference in New Issue
Block a user