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

chore: typing AC #33

Merged
merged 2 commits into from
Jun 4, 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
58 changes: 34 additions & 24 deletions midealocal/devices/ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging
import sys

from typing import Any

from .message import (
MessageACResponse,
MessageGeneralSet,
Expand Down Expand Up @@ -83,7 +85,7 @@ def __init__(
model: str,
subtype: int,
customize: str,
):
) -> None:
super().__init__(
name=name,
device_id=device_id,
Expand Down Expand Up @@ -131,25 +133,32 @@ def __init__(
DeviceAttributes.fresh_air_2: None,
},
)
self._fresh_air_version = None
self._default_temperature_step = 0.5
self._temperature_step = None
self._used_subprotocol = False
self._bb_sn8_flag = False
self._bb_timer = False
self._power_analysis_method = None
self._default_power_analysis_method = 1
self._fresh_air_version: DeviceAttributes | None = None
self._default_temperature_step: float = 0.5
self._temperature_step: float = 0.5
self._used_subprotocol: bool = False
self._bb_sn8_flag: bool = False
self._bb_timer: bool = False
self._power_analysis_method: int = 1
self._default_power_analysis_method: int = 1
self.set_customize(customize)

@property
def temperature_step(self):
def temperature_step(self) -> float | None:
return self._temperature_step

@property
def fresh_air_fan_speeds(self):
def fresh_air_fan_speeds(self) -> list[str]:
return list(MideaACDevice._fresh_air_fan_speeds.values())

def build_query(self):
def build_query(
self,
) -> list[
MessageSubProtocolQuery
| MessageQuery
| MessageNewProtocolQuery
| MessagePowerQuery
]:
if self._used_subprotocol:
return [
MessageSubProtocolQuery(self._protocol_version, 0x10),
Expand All @@ -162,8 +171,8 @@ def build_query(self):
MessagePowerQuery(self._protocol_version),
]

def process_message(self, msg):
message = MessageACResponse(msg, self._power_analysis_method)
def process_message(self, msg: bytes) -> dict[str, Any]:
message = MessageACResponse(bytearray(msg), self._power_analysis_method)
_LOGGER.debug(f"[{self.device_id}] Received: {message}")
new_status = {}
has_fresh_air = False
Expand Down Expand Up @@ -207,7 +216,7 @@ def process_message(self, msg):
self._fresh_air_version = DeviceAttributes.fresh_air_2
return new_status

def make_message_set(self):
def make_message_set(self) -> MessageGeneralSet:
message = MessageGeneralSet(self._protocol_version)
message.power = self._attributes[DeviceAttributes.power]
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
Expand All @@ -230,7 +239,7 @@ def make_message_set(self):
message.comfort_mode = self._attributes[DeviceAttributes.comfort_mode]
return message

def make_subptotocol_message_set(self):
def make_subptotocol_message_set(self) -> MessageSubProtocolSet:
message = MessageSubProtocolSet(self._protocol_version)
message.power = self._attributes[DeviceAttributes.power]
message.prompt_tone = self._attributes[DeviceAttributes.prompt_tone]
Expand All @@ -248,16 +257,17 @@ def make_subptotocol_message_set(self):
message.timer = self._bb_timer
return message

def make_message_uniq_set(self):
def make_message_uniq_set(self) -> MessageSubProtocolSet | MessageGeneralSet:
message: MessageSubProtocolSet | MessageGeneralSet
if self._used_subprotocol:
message = self.make_subptotocol_message_set()
else:
message = self.make_message_set()
return message

def set_attribute(self, attr, value):
def set_attribute(self, attr: str, value: Any) -> None:
# if nat a sensor
message = None
message: MessageToggleDisplay | MessageNewProtocolSet | None = None
if attr not in [
DeviceAttributes.indoor_temperature,
DeviceAttributes.outdoor_temperature,
Expand Down Expand Up @@ -343,21 +353,21 @@ def set_attribute(self, attr, value):
if message is not None:
self.build_send(message)

def set_target_temperature(self, target_temperature, mode):
message = self.make_message_uniq_set()
def set_target_temperature(self, target_temperature: float, mode: int) -> None:
message: MessageGeneralSet = self.make_message_uniq_set()
message.target_temperature = target_temperature
if mode is not None:
message.power = True
message.mode = mode
self.build_send(message)

def set_swing(self, swing_vertical, swing_horizontal):
message = self.make_message_uniq_set()
def set_swing(self, swing_vertical: bool, swing_horizontal: bool) -> None:
message: MessageGeneralSet = self.make_message_uniq_set()
message.swing_vertical = swing_vertical
message.swing_horizontal = swing_horizontal
self.build_send(message)

def set_customize(self, customize):
def set_customize(self, customize: str) -> None:
self._temperature_step = self._default_temperature_step
self._power_analysis_method = self._default_power_analysis_method
if customize and len(customize) > 0:
Expand Down
Loading
Loading