Skip to content

Commit

Permalink
Air Conditioning Companion: Extended parsing of model and state (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored May 10, 2018
1 parent 5649ea4 commit 551687b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 5 deletions.
80 changes: 76 additions & 4 deletions miio/airconditioningcompanion.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import enum
import logging
from typing import Optional

import click

from .click_common import command, format_output, EnumType
from .device import Device

_LOGGER = logging.getLogger(__name__)


class OperationMode(enum.Enum):
Heat = 0
Expand All @@ -25,6 +28,7 @@ class FanSpeed(enum.Enum):
class SwingMode(enum.Enum):
On = 0
Off = 1
Unknown = 2


class Power(enum.Enum):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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, " \
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion miio/tests/test_airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 551687b

Please sign in to comment.