From df2a81e6341e161c0f88d50ffcd26584cf4a08b6 Mon Sep 17 00:00:00 2001 From: kyokuheishin Date: Sat, 6 May 2023 01:51:05 +0900 Subject: [PATCH 1/4] add class AirConditionerMode, AirConditionerFanSpeed, AirConditionerPowerState in enums.py --- switchbot/enums.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 switchbot/enums.py diff --git a/switchbot/enums.py b/switchbot/enums.py new file mode 100644 index 0000000..f258794 --- /dev/null +++ b/switchbot/enums.py @@ -0,0 +1,18 @@ +from enum import Enum + +class AirConditionerMode(Enum): + AUTO = 1 + COOL = 2 + DRY = 3 + FAN = 4 + HEAT = 5 + +class AirConditionerFanSpeed(Enum): + AUTO = 1 + LOW = 2 + MEDIUM = 3 + HIGH = 4 + +class AirConditionerPowerState(Enum): + ON = "on" + OFF = "off" \ No newline at end of file From d5c2a4164b7502ef4b916aff40f422962f0d09fb Mon Sep 17 00:00:00 2001 From: kyokuheishin Date: Sat, 6 May 2023 01:52:24 +0900 Subject: [PATCH 2/4] add class AirConditioner and set_all method in remotes.py --- switchbot/remotes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/switchbot/remotes.py b/switchbot/remotes.py index 5ac1145..6418c5f 100644 --- a/switchbot/remotes.py +++ b/switchbot/remotes.py @@ -5,6 +5,7 @@ import humps from switchbot.client import SwitchBotClient +from switchbot.enums import AirConditionerMode, AirConditionerFanSpeed, AirConditionerPowerState class Remote: @@ -62,6 +63,12 @@ def turn(self, state: str): assert state in ("on", "off") self.command(f"turn_{state}") +class AirConditioner(SupportedRemote): + remote_type_for = "Air Conditioner" + def set_all(self, temperature: int, mode: AirConditionerMode, fan_speed: AirConditionerFanSpeed, power_state: AirConditionerPowerState): + assert type(temperature) is int + self.command(f"{temperature},{mode},{fan_speed},{power_state}") + class OtherRemote(Remote): remote_type_for = "Others" From ec7aa126993df4cf6e968b4e048584028371809f Mon Sep 17 00:00:00 2001 From: kyokuheishin Date: Sat, 6 May 2023 10:01:06 +0900 Subject: [PATCH 3/4] update format --- switchbot/remotes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/switchbot/remotes.py b/switchbot/remotes.py index 6418c5f..9a6acb1 100644 --- a/switchbot/remotes.py +++ b/switchbot/remotes.py @@ -65,6 +65,7 @@ def turn(self, state: str): class AirConditioner(SupportedRemote): remote_type_for = "Air Conditioner" + def set_all(self, temperature: int, mode: AirConditionerMode, fan_speed: AirConditionerFanSpeed, power_state: AirConditionerPowerState): assert type(temperature) is int self.command(f"{temperature},{mode},{fan_speed},{power_state}") From b9dd715dba82f7ac9790c3dfa94d1373b0bd1d9c Mon Sep 17 00:00:00 2001 From: kyokuheishin Date: Sat, 6 May 2023 11:53:38 +0900 Subject: [PATCH 4/4] fix the way for calling self.command --- switchbot/remotes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/switchbot/remotes.py b/switchbot/remotes.py index 9a6acb1..05f0033 100644 --- a/switchbot/remotes.py +++ b/switchbot/remotes.py @@ -68,7 +68,7 @@ class AirConditioner(SupportedRemote): def set_all(self, temperature: int, mode: AirConditionerMode, fan_speed: AirConditionerFanSpeed, power_state: AirConditionerPowerState): assert type(temperature) is int - self.command(f"{temperature},{mode},{fan_speed},{power_state}") + self.command(action="setAll", parameter=f"{temperature},{mode.value},{fan_speed.value},{power_state.value}") class OtherRemote(Remote):