Skip to content

Commit

Permalink
fix(ac): correct attributes based on msg type (#251)
Browse files Browse the repository at this point in the history
This reverts commit 75fbd8e

Fix #249 

@linkser Can you help with a test?

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced message handling in AC device control, allowing for a broader
range of message types when setting attributes.
- Improved handling of swing settings with refined checks based on
message types, ensuring correct attribute modifications.

- **Bug Fixes**
- Fixed conditional logic in attribute setting, ensuring attributes are
only set when appropriate message types are received.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
caibinqing authored Jul 29, 2024
1 parent 8f5ec79 commit fada9bc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions midealocal/devices/ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ def set_attribute(self, attr: str, value: bool | int | str) -> None:
"""Midea AC device set attribute."""
# if nat a sensor
message: (
MessageToggleDisplay | MessageNewProtocolSet | MessageGeneralSet | None
MessageToggleDisplay
| MessageNewProtocolSet
| MessageSubProtocolSet
| MessageGeneralSet
| None
) = None
if attr not in [
DeviceAttributes.indoor_temperature,
Expand Down Expand Up @@ -355,7 +359,7 @@ def set_attribute(self, attr: str, value: bool | int | str) -> None:
)
setattr(message, str(self._fresh_air_version), fresh_air)
elif attr in self._attributes:
message = self.make_message_set()
message = self.make_message_uniq_set()
if attr in [
DeviceAttributes.boost_mode,
DeviceAttributes.sleep_mode,
Expand All @@ -365,9 +369,10 @@ def set_attribute(self, attr: str, value: bool | int | str) -> None:
]:
message.boost_mode = False
message.sleep_mode = False
message.comfort_mode = False
message.eco_mode = False
message.frost_protect = False
if not isinstance(message, MessageSubProtocolSet):
message.comfort_mode = False
message.frost_protect = False
setattr(message, str(attr), value)
if attr == DeviceAttributes.mode:
setattr(message, str(DeviceAttributes.power.value), True)
Expand All @@ -392,9 +397,12 @@ def set_target_temperature(

def set_swing(self, swing_vertical: bool, swing_horizontal: bool) -> None:
"""Midea AC device set swing."""
message: MessageGeneralSet = self.make_message_set()
message.swing_vertical = swing_vertical
message.swing_horizontal = swing_horizontal
message: MessageSubProtocolSet | MessageGeneralSet = (
self.make_message_uniq_set()
)
if isinstance(message, MessageGeneralSet):
message.swing_vertical = swing_vertical
message.swing_horizontal = swing_horizontal
self.build_send(message)

def set_customize(self, customize: str) -> None:
Expand Down

0 comments on commit fada9bc

Please sign in to comment.