mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Add pump switch for Midea dehumidifiers (#181257)
This commit is contained in:
@@ -94,6 +94,9 @@
|
||||
"prompt_tone": {
|
||||
"default": "mdi:bullhorn"
|
||||
},
|
||||
"pump": {
|
||||
"default": "mdi:water-pump"
|
||||
},
|
||||
"screen_display": {
|
||||
"default": "mdi:monitor"
|
||||
},
|
||||
|
||||
@@ -692,6 +692,9 @@
|
||||
"prompt_tone": {
|
||||
"name": "Prompt tone"
|
||||
},
|
||||
"pump": {
|
||||
"name": "Pump"
|
||||
},
|
||||
"screen_display": {
|
||||
"name": "Screen display"
|
||||
},
|
||||
|
||||
@@ -19,9 +19,16 @@ class MideaSwitchEntityDescription(SwitchEntityDescription):
|
||||
"""Description for a Midea switch entity."""
|
||||
|
||||
models: list[DeviceType]
|
||||
capability: str | None = None
|
||||
|
||||
|
||||
SWITCHES: list[MideaSwitchEntityDescription] = [
|
||||
MideaSwitchEntityDescription(
|
||||
key="pump",
|
||||
translation_key="pump",
|
||||
models=[DeviceType.A1],
|
||||
capability="pump",
|
||||
),
|
||||
MideaSwitchEntityDescription(
|
||||
key="aux_heating",
|
||||
translation_key="aux_heating",
|
||||
@@ -118,6 +125,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.capability is None
|
||||
or (getattr(device, "capabilities", None) or {}).get(
|
||||
description.capability, False
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ class DummyDevice:
|
||||
device_type: DeviceType,
|
||||
*,
|
||||
attributes: dict | None = None,
|
||||
capabilities: dict | None = None,
|
||||
) -> None:
|
||||
"""Initialize fake device."""
|
||||
self.device_type = device_type
|
||||
@@ -46,6 +47,7 @@ class DummyDevice:
|
||||
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
|
||||
|
||||
@@ -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([
|
||||
|
||||
@@ -4,6 +4,7 @@ from collections.abc import Callable
|
||||
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
|
||||
@@ -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,
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user