Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor preset properties to avoid "_mode" prefix which may have been conflatable with operational modes #171

Merged
merged 4 commits into from
Aug 30, 2024
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
8 changes: 4 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async def main():
'operational_mode': device.operational_mode,
'fan_speed': device.fan_speed,
'swing_mode': device.swing_mode,
'eco_mode': device.eco_mode,
'turbo_mode': device.turbo_mode,
'eco': device.eco,
'turbo': device.turbo,
'fahrenheit': device.fahrenheit,
'indoor_temperature': device.indoor_temperature,
'outdoor_temperature': device.outdoor_temperature
Expand All @@ -74,8 +74,8 @@ async def main():
'operational_mode': device.operational_mode,
'fan_speed': device.fan_speed,
'swing_mode': device.swing_mode,
'eco_mode': device.eco_mode,
'turbo_mode': device.turbo_mode,
'eco': device.eco,
'turbo': device.turbo,
'fahrenheit': device.fahrenheit,
'indoor_temperature': device.indoor_temperature,
'outdoor_temperature': device.outdoor_temperature
Expand Down
6 changes: 3 additions & 3 deletions msmart/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ async def _query(args) -> None:
"supported_swing_modes": device.supported_swing_modes,
"supported_fan_speeds": device.supported_fan_speeds,
"supports_custom_fan_speed": device.supports_custom_fan_speed,
"supports_eco_mode": device.supports_eco_mode,
"supports_turbo_mode": device.supports_turbo_mode,
"supports_freeze_protection_mode": device.supports_freeze_protection_mode,
"supports_eco": device.supports_eco,
"supports_turbo": device.supports_turbo,
"supports_freeze_protection": device.supports_freeze_protection,
"supports_display_control": device.supports_display_control,
"supports_filter_reminder": device.supports_filter_reminder,
"max_target_temperature": device.max_target_temperature,
Expand Down
64 changes: 32 additions & 32 deletions msmart/device/AC/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ def __init__(self) -> None:
self.target_temperature = 25.0
self.operational_mode = 0
self.fan_speed = 0
self.eco_mode = True
self.eco = True
self.swing_mode = 0
self.turbo_mode = False
self.turbo = False
self.fahrenheit = True
self.sleep_mode = False
self.freeze_protection_mode = False
self.sleep = False
self.freeze_protection = False
self.follow_me = False
self.purifier = False
self.target_humidity = 40
Expand Down Expand Up @@ -286,23 +286,23 @@ def tobytes(self) -> bytes: # pyright: ignore[reportIncompatibleMethodOverride]
swing_mode = 0x30 | (self.swing_mode & 0x3F)

# Build eco mode and purifier byte
eco_mode = 0x80 if self.eco_mode else 0
eco = 0x80 if self.eco else 0
purifier = 0x20 if self.purifier else 0

# Build sleep, turbo and fahrenheit byte
sleep = 0x01 if self.sleep_mode else 0
turbo = 0x02 if self.turbo_mode else 0
sleep = 0x01 if self.sleep else 0
turbo = 0x02 if self.turbo else 0
fahrenheit = 0x04 if self.fahrenheit else 0

# Build alternate turbo byte
turbo_alt = 0x20 if self.turbo_mode else 0
turbo_alt = 0x20 if self.turbo else 0
follow_me = 0x80 if self.follow_me else 0

# Build target humidity byte
humidity = self.target_humidity & 0x7F

# Build freeze protection byte
freeze_protect = 0x80 if self.freeze_protection_mode else 0
freeze_protect = 0x80 if self.freeze_protection else 0

return super().tobytes(bytes([
# Set state
Expand All @@ -320,7 +320,7 @@ def tobytes(self) -> bytes: # pyright: ignore[reportIncompatibleMethodOverride]
# Follow me and alternate turbo mode
follow_me | turbo_alt,
# ECO mode and purifier/anion
eco_mode | purifier,
eco | purifier,
# Sleep mode, turbo mode and fahrenheit
sleep | turbo | fahrenheit,
# Unknown
Expand Down Expand Up @@ -512,6 +512,11 @@ def get_value(w) -> Callable[[int], bool]: return lambda v: v == w
CapabilityId.BREEZELESS: reader("breezeless", get_value(1)),
CapabilityId.BUZZER: reader("buzzer", get_value(1)),
CapabilityId.DISPLAY_CONTROL: reader("display_control", lambda v: v in [1, 2, 100]),
CapabilityId.ENERGY: [
reader("energy_stats", lambda v: v in [2, 3, 4, 5]),
reader("energy_setting", lambda v: v in [3, 5]),
reader("energy_bcd", lambda v: v in [2, 3]),
],
CapabilityId.FAHRENHEIT: reader("fahrenheit", get_value(0)),
CapabilityId.FAN_SPEED_CONTROL: [
reader("fan_silent", get_value(6)),
Expand All @@ -530,20 +535,15 @@ def get_value(w) -> Callable[[int], bool]: return lambda v: v == w
reader("humidity_auto_set", lambda v: v in [1, 2]),
reader("humidity_manual_set", lambda v: v in [2, 3]),
],
CapabilityId.PRESET_IECO: reader("ieco", get_value(1)),
CapabilityId.MODES: [
reader("heat_mode", lambda v: v in [1, 2, 4, 6, 7, 9]),
reader("cool_mode", lambda v: v != 2),
reader("dry_mode", lambda v: v in [0, 1, 5, 6, 9]),
reader("auto_mode", lambda v: v in [0, 1, 2, 7, 8, 9]),
],
CapabilityId.ENERGY: [
reader("energy_stats", lambda v: v in [2, 3, 4, 5]),
reader("energy_setting", lambda v: v in [3, 5]),
reader("energy_bcd", lambda v: v in [2, 3]),
],
CapabilityId.PRESET_ECO: reader("eco_mode", lambda v: v in [1, 2]),
CapabilityId.PRESET_ECO: reader("eco", lambda v: v in [1, 2]),
CapabilityId.PRESET_FREEZE_PROTECTION: reader("freeze_protection", get_value(1)),
CapabilityId.PRESET_IECO: reader("ieco", get_value(1)),
CapabilityId.PRESET_TURBO: [
reader("turbo_heat", lambda v: v in [1, 3]),
reader("turbo_cool", lambda v: v < 2),
Expand Down Expand Up @@ -742,20 +742,20 @@ def auto_mode(self) -> bool:
return self._capabilities.get("auto_mode", False)

@property
def eco_mode(self) -> bool:
return self._capabilities.get("eco_mode", False)
def eco(self) -> bool:
return self._capabilities.get("eco", False)

@property
def ieco_mode(self) -> bool:
def ieco(self) -> bool:
return self._capabilities.get("ieco", False)

@property
def turbo_mode(self) -> bool:
def turbo(self) -> bool:
return (self._capabilities.get("turbo_heat", False)
or self._capabilities.get("turbo_cool", False))

@property
def freeze_protection_mode(self) -> bool:
def freeze_protection(self) -> bool:
return self._capabilities.get("freeze_protection", False)

@property
Expand Down Expand Up @@ -816,15 +816,15 @@ def __init__(self, payload: memoryview) -> None:
self.operational_mode = None
self.fan_speed = None
self.swing_mode = None
self.turbo_mode = None
self.eco_mode = None
self.sleep_mode = None
self.turbo = None
self.eco = None
self.sleep = None
self.fahrenheit = None
self.indoor_temperature = None
self.outdoor_temperature = None
self.filter_alert = None
self.display_on = None
self.freeze_protection_mode = None
self.freeze_protection = None
self.follow_me = None
self.purifier = None
self.target_humidity = None
Expand Down Expand Up @@ -872,19 +872,19 @@ def _parse(self, payload: memoryview) -> None:
# self.cozy_sleep = payload[8] & 0x03
# self.save = (payload[8] & 0x08) > 0
# self.low_frequency_fan = (payload[8] & 0x10) > 0
self.turbo_mode = bool(payload[8] & 0x20)
self.turbo = bool(payload[8] & 0x20)
self.follow_me = bool(payload[8] & 0x80)

self.eco_mode = bool(payload[9] & 0x10)
self.eco = bool(payload[9] & 0x10)
self.purifier = bool(payload[9] & 0x20)
# self.child_sleep_mode = (payload[9] & 0x01) > 0
# self.child_sleep = (payload[9] & 0x01) > 0
# self.exchange_air = (payload[9] & 0x02) > 0
# self.dry_clean = (payload[9] & 0x04) > 0
# self.aux_heat = (payload[9] & 0x08) > 0
# self.temp_unit = (payload[9] & 0x80) > 0

self.sleep_mode = bool(payload[10] & 0x1)
self.turbo_mode |= bool(payload[10] & 0x2)
self.sleep = bool(payload[10] & 0x1)
self.turbo |= bool(payload[10] & 0x2)
self.fahrenheit = bool(payload[10] & 0x4)
# self.catch_cold = (payload[10] & 0x08) > 0
# self.night_light = (payload[10] & 0x10) > 0
Expand Down Expand Up @@ -926,7 +926,7 @@ def decode_temp(d: int) -> Optional[float]:
if len(payload) < 22:
return

self.freeze_protection_mode = bool(payload[21] & 0x80)
self.freeze_protection = bool(payload[21] & 0x80)


class PropertiesResponse(Response):
Expand Down
Loading
Loading