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

Extended Air Conditioning Companion support #169

Merged
merged 8 commits into from
Jan 26, 2018
Merged
Changes from 7 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
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, t1t, t4t and t7t are markers which will be replaced
DEVICE_COMMAND_TEMPLATES = {
'fallback': {
'deviceType': 'generic',
'base': 'pomowiswtta0'
},
'0180111111': {
'deviceType': 'media_1',
'base': 'pomowiswtt02'
},
'0180222221': {
'deviceType': 'gree_1',
'base': 'pomowiswtt02'
},
'0100010727': {
'deviceType': 'gree_2',
'base': 'pomowiswtt1100190t1t205002102000t7t0190t1t207002000000t4t0',
'off': '01011101004000205002112000D04000207002000000A0'
},
'0100004795': {
'deviceType': 'gree_8',
'base': 'pomowiswtt0100090900005002'
},
'0180333331': {
'deviceType': 'haier_1',
'base': 'pomowiswtt12'
},
'0180666661': {
'deviceType': 'aux_1',
'base': 'pomowiswtt12'
},
'0180777771': {
'deviceType': 'chigo_1',
'base': 'pomowiswtt12'
}
}


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']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)


configuration = configuration.replace('po', power.value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion, would it be better to replace placeholders with something like [PO] to make it more clear that they are placeholders? Just a thought though, otherwise this seems fine to me so please feel to merge when you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

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('t1t', temperature)

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

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

return self.send_command(configuration)