Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 11 additions & 4 deletions midealocal/devices/a1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
DeviceAttributes.filter_cleaning_reminder: False,
},
)
self._pump_enable = False
self._capabilities: dict[str, bool] = {}
self._speeds = self._default_speeds
self._modes = self._default_modes
self.set_customize(customize)
Expand All @@ -101,6 +101,11 @@ def water_level_sets(self) -> list[str]:
"""Midea A1 device water level options."""
return MideaA1Device._water_level_sets

@property
def capabilities(self) -> dict[str, bool]:
"""Return the capabilities reported by the device."""
return dict(self._capabilities)

def build_query(self) -> list[MessageQuery]:
"""Midea A1 device build query."""
return [MessageQuery(self._message_protocol_version)]
Expand All @@ -109,9 +114,10 @@ def process_message(self, msg: bytes) -> dict[str, Any]:
"""Midea A1 device process message."""
message = MessageA1Response(bytearray(msg))
self._message_protocol_version = message.protocol_version
# Preserve the hidden pump capability bit for future set packets.
# Preserve the pump capability bit for future set packets and expose it
# through the capability map.
if hasattr(message, "pump_enable"):
self._pump_enable = message.pump_enable
self._capabilities["pump"] = message.pump_enable
_LOGGER.debug("[%s] Received: %s", self.device_id, message)
new_status = self.update_attributes_from_message(
message,
Expand All @@ -130,6 +136,7 @@ def process_message(self, msg: bytes) -> dict[str, Any]:
if self._attributes[DeviceAttributes.tank_full] != tank_full_calculated:
self._attributes[DeviceAttributes.tank_full] = tank_full_calculated
new_status[DeviceAttributes.tank_full.value] = tank_full_calculated
new_status["capabilities"] = dict(self._capabilities)
return new_status

def make_message_set(self) -> MessageSet:
Expand All @@ -154,7 +161,7 @@ def make_message_set(self) -> MessageSet:
message.swing = self._attributes[DeviceAttributes.swing]
message.anion = self._attributes[DeviceAttributes.anion]
message.pump = self._attributes[DeviceAttributes.pump]
message.pump_enable = self._pump_enable
message.pump_enable = self._capabilities.get("pump", False)
message.water_level_set = int(
self._attributes[DeviceAttributes.water_level_set],
)
Expand Down
7 changes: 7 additions & 0 deletions tests/devices/a1/device_a1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ def test_process_message(self) -> None:
assert new_status[DeviceAttributes.pump.value]
assert new_status[DeviceAttributes.tank_full.value]
assert new_status[DeviceAttributes.mode.value] == "manual"
assert self.device.capabilities == {"pump": True}

capabilities = self.device.capabilities
capabilities["pump"] = False
assert self.device.capabilities == {"pump": True}

mock_message.mode = 10
mock_message.fan_speed = 99
mock_message.pump_enable = False
mock_message.tank = 30
new_status = self.device.process_message(b"")
assert new_status[DeviceAttributes.mode.value] is None
assert new_status[DeviceAttributes.fan_speed.value] is None
assert not new_status[DeviceAttributes.tank_full.value]
assert self.device.capabilities == {"pump": False}

def test_build_query(self) -> None:
"""Test build query."""
Expand Down