diff --git a/homeassistant/components/midea/switch.py b/homeassistant/components/midea/switch.py index e9040cc74568..f85bcddd5a20 100644 --- a/homeassistant/components/midea/switch.py +++ b/homeassistant/components/midea/switch.py @@ -101,7 +101,7 @@ SWITCHES: list[MideaSwitchEntityDescription] = [ MideaSwitchEntityDescription( key="anion", translation_key="anion", - models=[DeviceType.AC], + models=[DeviceType.AC, DeviceType.A1], entity_category=EntityCategory.CONFIG, ), MideaSwitchEntityDescription( diff --git a/tests/components/midea/snapshots/test_switch.ambr b/tests/components/midea/snapshots/test_switch.ambr index 432a13857582..5e243d4c3312 100644 --- a/tests/components/midea/snapshots/test_switch.ambr +++ b/tests/components/midea/snapshots/test_switch.ambr @@ -1,4 +1,54 @@ # serializer version: 1 +# name: test_switch_state_snapshot[a1][switch.dehumidifier_anion-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': , + 'entity_id': 'switch.dehumidifier_anion', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Anion', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Anion', + 'platform': 'midea', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'anion', + 'unique_id': '12345678_anion', + 'unit_of_measurement': None, + }) +# --- +# name: test_switch_state_snapshot[a1][switch.dehumidifier_anion-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'Dehumidifier Anion', + }), + 'context': , + 'entity_id': 'switch.dehumidifier_anion', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- # name: test_switch_state_snapshot[a1][switch.dehumidifier_pump-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/midea/test_switch.py b/tests/components/midea/test_switch.py index fbf54fb05b7f..a139abf86434 100644 --- a/tests/components/midea/test_switch.py +++ b/tests/components/midea/test_switch.py @@ -127,7 +127,10 @@ def _set_attribute_calls(device: DummyDevice) -> list[tuple]: pytest.param( DummyDevice( DeviceType.A1, - attributes={A1Attributes.pump: False}, + attributes={ + A1Attributes.anion: True, + A1Attributes.pump: False, + }, capabilities={"pump": True}, ), id="a1", @@ -685,6 +688,46 @@ async def test_a1_pump_services( assert state.state == STATE_OFF +async def test_a1_anion_services( + hass: HomeAssistant, + mock_config_entry: Callable[[DummyDevice], MockConfigEntry], +) -> None: + """Test the A1 dehumidifier anion switch.""" + device = DummyDevice( + DeviceType.A1, + attributes={A1Attributes.anion: 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}_anion"] + + 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", A1Attributes.anion, 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", A1Attributes.anion, 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_not_created_without_capability( hass: HomeAssistant, mock_config_entry: Callable[[DummyDevice], MockConfigEntry],