Skip to content

Commit

Permalink
Extended Air Conditioning Companion support (#169)
Browse files Browse the repository at this point in the history
* OperatinModes renamed.
* Send configuration method introduced.
  • Loading branch information
syssi authored Jan 26, 2018
1 parent 79c2904 commit e9ce9e0
Showing 1 changed file with 90 additions and 2 deletions.
92 changes: 90 additions & 2 deletions miio/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@


class OperationMode(enum.Enum):
Heating = 0
Cooling = 1
Heat = 0
Cool = 1
Auto = 2
Dehumidify = 3
Ventilate = 4


class FanSpeed(enum.Enum):
Expand All @@ -16,7 +18,56 @@ class FanSpeed(enum.Enum):
Auto = 3


class SwingMode(enum.Enum):
On = 0
Off = 1


class Power(enum.Enum):
On = 1
Off = 0


STORAGE_SLOT_ID = 30
POWER_OFF = 'off'

# Command templates per model number (f.e. 0180111111)
# [po], [mo], [wi], [sw], [tt], [tt1], [tt4] and [tt7] are markers which will be replaced
DEVICE_COMMAND_TEMPLATES = {
'fallback': {
'deviceType': 'generic',
'base': '[po][mo][wi][sw][tt]a0'
},
'0180111111': {
'deviceType': 'media_1',
'base': '[po][mo][wi][sw][tt]02'
},
'0180222221': {
'deviceType': 'gree_1',
'base': '[po][mo][wi][sw][tt]02'
},
'0100010727': {
'deviceType': 'gree_2',
'base': '[po][mo][wi][sw][tt]1100190[tt1]205002102000t7t0190[tt1]207002000000[tt4]0',
'off': '01011101004000205002112000D04000207002000000A0'
},
'0100004795': {
'deviceType': 'gree_8',
'base': '[po][mo][wi][sw][tt]0100090900005002'
},
'0180333331': {
'deviceType': 'haier_1',
'base': '[po][mo][wi][sw][tt]12'
},
'0180666661': {
'deviceType': 'aux_1',
'base': '[po][mo][wi][sw][tt]12'
},
'0180777771': {
'deviceType': 'chigo_1',
'base': '[po][mo][wi][sw][tt]12'
}
}


class AirConditioningCompanionStatus:
Expand Down Expand Up @@ -109,3 +160,40 @@ def send_command(self, command: str):
:param str command: Command to execute"""
return self.send("send_cmd", [str(command)])

def send_configuration(self, model: str, power: Power,
operation_mode: OperationMode,
target_temperature: float, fan_speed: FanSpeed,
swing_mode: SwingMode):

# Static turn off command available?
if (power is False) and (model in DEVICE_COMMAND_TEMPLATES) and \
(POWER_OFF in DEVICE_COMMAND_TEMPLATES[model]):
return self.send_command(
model + DEVICE_COMMAND_TEMPLATES[model][POWER_OFF])

if model in DEVICE_COMMAND_TEMPLATES:
configuration = model + DEVICE_COMMAND_TEMPLATES[model]['base']
else:
configuration = model + DEVICE_COMMAND_TEMPLATES['fallback']['base']

configuration = configuration.replace('[po]', power.value)
configuration = configuration.replace('[mo]', operation_mode.value)
configuration = configuration.replace('[wi]', fan_speed.value)
configuration = configuration.replace('[sw]', swing_mode.value)
configuration = configuration.replace(
'[tt]', hex(int(target_temperature))[2:])

temperature = (1 + int(target_temperature) - 17) % 16
temperature = hex(temperature)[2:].upper()
configuration = configuration.replace('[[tt1]]', temperature)

temperature = (4 + int(target_temperature) - 17) % 16
temperature = hex(temperature)[2:].upper()
configuration = configuration.replace('[tt4]', temperature)

temperature = (7 + int(target_temperature) - 17) % 16
temperature = hex(temperature)[2:].upper()
configuration = configuration.replace('[tt7]', temperature)

return self.send_command(configuration)

0 comments on commit e9ce9e0

Please sign in to comment.