diff --git a/miio/airconditioningcompanion.py b/miio/airconditioningcompanion.py index 4539f48d4..210ce57e9 100644 --- a/miio/airconditioningcompanion.py +++ b/miio/airconditioningcompanion.py @@ -1,4 +1,5 @@ import enum +import logging from typing import Optional import click @@ -6,6 +7,8 @@ from .click_common import command, format_output, EnumType from .device import Device +_LOGGER = logging.getLogger(__name__) + class OperationMode(enum.Enum): Heat = 0 @@ -25,6 +28,7 @@ class FanSpeed(enum.Enum): class SwingMode(enum.Enum): On = 0 Off = 1 + Unknown = 2 class Power(enum.Enum): @@ -97,17 +101,73 @@ def load_power(self) -> int: @property def air_condition_model(self) -> str: """Model of the air conditioner.""" - return str(self.data[0]) + return self.data[0] + + @property + def model_format(self) -> int: + """Version number of the model format.""" + return int(self.air_condition_model[0:2]) + + @property + def device_type(self) -> int: + """Device type identifier.""" + return int(self.air_condition_model[2:4]) + + @property + def air_condition_brand(self) -> int: + """ + Brand of the air conditioner. + + Known brand ids (int) are 0182, 0097, 0037, 0202, 02782, 0197, 0192. + """ + return int(self.air_condition_model[4:8]) + + @property + def air_condition_remote(self) -> int: + """ + Known remote ids (int): + + 80111111, 80111112 (brand: 182) + 80222221 (brand: 97) + 80333331 (brand: 37) + 80444441 (brand: 202) + 80555551 (brand: 2782) + 80777771 (brand: 197) + 80666661 (brand: 192) + + """ + return int(self.air_condition_model[8:16]) + + @property + def state_format(self) -> int: + """ + Version number of the state format. + + Known values (int) are: 01, 02, 03 + """ + return int(self.air_condition_model[16:18]) + + @property + def air_condition_configuration(self) -> int: + return self.data[1][2:10] @property def power(self) -> str: """Current power state.""" - return 'on' if (int(self.data[1][2:3]) == Power.On.value) else 'off' + return 'on' if int(self.data[1][2:3]) == Power.On.value else 'off' @property - def led(self) -> str: + def led(self) -> Optional[bool]: """Current LED state.""" - return 'on' if (self.data[1][8:9] == Led.On.value) else 'off' + state = self.data[1][8:9] + if state == Led.On.value: + return True + + if state == Led.Off.value: + return False + + _LOGGER.info("Unsupported LED state: %s", state) + return None @property def is_on(self) -> bool: @@ -154,6 +214,12 @@ def __repr__(self) -> str: "power=%s, " \ "load_power=%s, " \ "air_condition_model=%s, " \ + "model_format=%s, " \ + "device_type=%s," \ + "air_condition_brand=%s," \ + "air_condition_remote=%s," \ + "state_format=%s," \ + "air_condition_configuration=%s," \ "led=%s, " \ "target_temperature=%s, " \ "swing_mode=%s, " \ @@ -162,6 +228,12 @@ def __repr__(self) -> str: (self.power, self.load_power, self.air_condition_model, + self.model_format, + self.device_type, + self.air_condition_brand, + self.air_condition_remote, + self.state_format, + self.air_condition_configuration, self.led, self.target_temperature, self.swing_mode, diff --git a/miio/tests/test_airconditioningcompanion.py b/miio/tests/test_airconditioningcompanion.py index 2a60cc657..caffba66e 100644 --- a/miio/tests/test_airconditioningcompanion.py +++ b/miio/tests/test_airconditioningcompanion.py @@ -87,11 +87,17 @@ def test_status(self): assert self.is_on() is False assert self.state().load_power == 2 assert self.state().air_condition_model == '010500978022222102' + assert self.state().model_format == 1 + assert self.state().device_type == 5 + assert self.state().air_condition_brand == 97 + assert self.state().air_condition_remote == 80222221 + assert self.state().state_format == 2 + assert self.state().air_condition_configuration == '020119A2' assert self.state().target_temperature == 25 assert self.state().swing_mode == SwingMode.Off assert self.state().fan_speed == FanSpeed.Low assert self.state().mode == OperationMode.Auto - assert self.state().led == 'off' + assert self.state().led is False def test_status_without_target_temperature(self): self.device._reset_state()