Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions homeassistant/components/midea/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"prompt_tone": {
"default": "mdi:bullhorn"
},
"pump": {
"default": "mdi:water-pump"
},
"screen_display": {
"default": "mdi:monitor"
},
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/midea/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@
"prompt_tone": {
"name": "Prompt tone"
},
"pump": {
"name": "Pump"
},
Comment thread
mattrossman marked this conversation as resolved.
"screen_display": {
"name": "Screen display"
},
Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/midea/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class MideaSwitchEntityDescription(SwitchEntityDescription):


SWITCHES: list[MideaSwitchEntityDescription] = [
MideaSwitchEntityDescription(
Comment thread
mattrossman marked this conversation as resolved.
key="pump",
translation_key="pump",
models=[DeviceType.A1],
Comment thread
Copilot marked this conversation as resolved.
),
MideaSwitchEntityDescription(
key="aux_heating",
translation_key="aux_heating",
Expand Down Expand Up @@ -118,6 +123,12 @@ async def async_setup_entry(
for description in SWITCHES
if device.device_type in description.models
and description.key in device.attributes
and (
description.key != "pump"
or (getattr(device, "capabilities", None) or {}).get(
description.key, False
)
)
Comment thread
Copilot marked this conversation as resolved.
Comment thread
mattrossman marked this conversation as resolved.
)


Expand Down
2 changes: 2 additions & 0 deletions tests/components/midea/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
device_type: DeviceType,
*,
attributes: dict | None = None,
capabilities: dict | None = None,
) -> None:
"""Initialize fake device."""
self.device_type = device_type
Expand All @@ -46,6 +47,7 @@ def __init__(
self.subtype = TEST_SUBTYPE
self.available = False
self.attributes = attributes or {}
self.capabilities: dict[str, Any] = capabilities or {}
self._callbacks: list[Callable] = []
self.calls: list[tuple] = []
self.temperature_step = 1
Expand Down
50 changes: 50 additions & 0 deletions tests/components/midea/snapshots/test_switch.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
# serializer version: 1
# name: test_switch_state_snapshot[a1][switch.dehumidifier_pump-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.dehumidifier_pump',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Pump',
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Pump',
'platform': 'midea',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'pump',
'unique_id': '12345678_pump',
'unit_of_measurement': None,
})
# ---
# name: test_switch_state_snapshot[a1][switch.dehumidifier_pump-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Dehumidifier Pump',
}),
'context': <ANY>,
'entity_id': 'switch.dehumidifier_pump',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_switch_state_snapshot[ac][switch.air_conditioner_anion-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
Expand Down
68 changes: 68 additions & 0 deletions tests/components/midea/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch

from midealocal.const import DeviceType
from midealocal.devices.a1 import DeviceAttributes as A1Attributes
from midealocal.devices.ac import DeviceAttributes as ACAttributes
from midealocal.devices.c3 import DeviceAttributes as C3Attributes
from midealocal.devices.cc import DeviceAttributes as CCAttributes
Expand Down Expand Up @@ -102,6 +103,14 @@ async def _assert_service_call(
),
id="c3",
),
pytest.param(
DummyDevice(
DeviceType.A1,
attributes={A1Attributes.pump: False},
capabilities={"pump": True},
),
id="a1",
),
pytest.param(
DummyDevice(
DeviceType.CC,
Expand Down Expand Up @@ -228,6 +237,65 @@ async def test_child_lock_switch_created_and_services(
)


async def test_a1_pump_services(
hass: HomeAssistant,
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
) -> None:
"""Test the A1 dehumidifier pump switch."""
device = DummyDevice(
DeviceType.A1,
attributes={A1Attributes.pump: False},
capabilities={"pump": 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}_pump"]

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", A1Attributes.pump, True)],
device,
)
await hass.async_block_till_done()
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", A1Attributes.pump, False)],
device,
)
await hass.async_block_till_done()
assert (state := hass.states.get(entity_entry.entity_id)) is not None
assert state.state == "off"


async def test_a1_pump_not_created_without_capability(
hass: HomeAssistant,
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
) -> None:
"""Test that unsupported A1 pump switches are not created."""
device = DummyDevice(
DeviceType.A1,
attributes={A1Attributes.pump: False},
capabilities={"pump": False},
)
config_entry = mock_config_entry(device)
with patch("homeassistant.components.midea._PLATFORMS", [Platform.SWITCH]):
await setup_integration(hass, config_entry, device)

assert f"{TEST_DEVICE_ID}_pump" not in entity_entries(hass, config_entry)


async def test_switch_unknown_when_attribute_becomes_non_bool(
hass: HomeAssistant,
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
Expand Down
Loading