11from __future__ import annotations
22
3- from typing import TYPE_CHECKING
3+ from typing import TYPE_CHECKING , Generic , Optional , TypeVar
44
55from switchbot_client .enums import ControlCommand , RemoteType
66from switchbot_client .types import APIRemoteDeviceObject
77
88from .base import SwitchBotCommandResult , SwitchBotDevice
9- from .status import PseudoRemoteDeviceStatus
9+ from .status import PseudoAirConditionerStatus , PseudoRemoteDeviceStatus
1010
1111if TYPE_CHECKING :
1212 from switchbot_client import SwitchBotClient
1313
14+ AnyRemoteDeviceStatus = TypeVar ("AnyRemoteDeviceStatus" , bound = PseudoRemoteDeviceStatus )
1415
15- class SwitchBotRemoteDevice (SwitchBotDevice ):
16+
17+ class SwitchBotRemoteDevice (SwitchBotDevice , Generic [AnyRemoteDeviceStatus ]):
1618 def __init__ (
1719 self ,
1820 client : SwitchBotClient ,
1921 device : APIRemoteDeviceObject ,
20- pseudo_status : PseudoRemoteDeviceStatus ,
22+ pseudo_status : AnyRemoteDeviceStatus ,
2123 ):
2224 super ().__init__ (
2325 client ,
@@ -41,7 +43,7 @@ def turn_off(self) -> SwitchBotCommandResult:
4143 self .pseudo_status .set_power ("off" )
4244 return response
4345
44- def status (self ) -> PseudoRemoteDeviceStatus :
46+ def status (self ) -> AnyRemoteDeviceStatus :
4547 return self .pseudo_status
4648
4749 @staticmethod
@@ -116,7 +118,7 @@ def _validate_pseudo_status(self):
116118 )
117119
118120
119- class AirConditioner (SwitchBotRemoteDevice ):
121+ class AirConditioner (SwitchBotRemoteDevice [ PseudoAirConditionerStatus ] ):
120122 class Parameters :
121123 MODE_AUTO = 1
122124 MODE_COOL = 2
@@ -131,40 +133,46 @@ class Parameters:
131133 POWER_OFF = "off"
132134
133135 def __init__ (self , client : SwitchBotClient , device : APIRemoteDeviceObject ):
134- pseudo_status = PseudoRemoteDeviceStatus (
136+ pseudo_status = PseudoAirConditionerStatus (
135137 device_id = device ["deviceId" ],
136138 device_type = device ["remoteType" ],
137139 device_name = device ["deviceName" ],
138140 hub_device_id = device ["hubDeviceId" ],
139141 power = None ,
140142 raw_data = {},
143+ temperature = 25.0 ,
144+ mode = AirConditioner .Parameters .MODE_AUTO ,
145+ fan_speed = AirConditioner .Parameters .FAN_SPEED_AUTO ,
141146 )
142147 super ().__init__ (client , device , pseudo_status )
143148 self ._check_remote_type (RemoteType .AIR_CONDITIONER )
144149
145- # remote devices don't have status fetch commands
146- # we can only memorize recently applied parameter and use it
147- self .temperature_memory = 25.0
148- self .mode_memory = AirConditioner .Parameters .MODE_AUTO
149- self .fan_speed_memory = AirConditioner .Parameters .FAN_SPEED_AUTO
150-
151150 @staticmethod
152151 def create_by_id (client : SwitchBotClient , device_id : str ) -> AirConditioner :
153152 device = SwitchBotRemoteDevice .get_device_by_id (client , device_id )
154153 return AirConditioner (client , device )
155154
156155 def set_all (
157- self , temperature : float , mode : int , fan_speed : int , power : str
156+ self ,
157+ temperature : Optional [float ],
158+ mode : Optional [int ],
159+ fan_speed : Optional [int ],
160+ power : Optional [str ],
158161 ) -> SwitchBotCommandResult :
159162 """
160163 temperature: temperature in celsius
161164 mode(Parameters.MODE_XXX): 1(auto), 2(cool), 3(dry), 4(fan), 5(heat)
162165 fan_speed(Parameters.FAN_SPEED_XXX): 1(auto), 2(low), 3(medium), 4(high)
163166 power(Parameters.POWER_XXX): on, off
164167 """
165- self .temperature_memory = temperature
166- self .mode_memory = mode
167- self .fan_speed_memory = fan_speed
168+ if temperature is not None :
169+ self .pseudo_status .set_temperature (temperature )
170+ if mode is not None :
171+ self .pseudo_status .set_mode (mode )
172+ if fan_speed is not None :
173+ self .pseudo_status .set_fan_speed (fan_speed )
174+ if power is not None :
175+ self .pseudo_status .set_power (power )
168176 return self .command (
169177 ControlCommand .VirtualInfrared .SET_ALL ,
170178 parameter = f"{ temperature } ,{ mode } ,{ fan_speed } ,{ power } " ,
@@ -182,7 +190,9 @@ def set_temperature(self, temperature: float) -> SwitchBotCommandResult:
182190 It is recommended to turn on AirConditioner with the set_all
183191 with all values specified before use this function.
184192 """
185- return self .set_all (temperature , self .mode_memory , self .fan_speed_memory , "on" )
193+ return self .set_all (
194+ temperature , self .pseudo_status .mode , self .pseudo_status .fan_speed , "on"
195+ )
186196
187197 def set_mode (self , mode : int ) -> SwitchBotCommandResult :
188198 """
@@ -196,7 +206,9 @@ def set_mode(self, mode: int) -> SwitchBotCommandResult:
196206 It is recommended to turn on AirConditioner with the set_all
197207 with all values specified before use this function.
198208 """
199- return self .set_all (self .temperature_memory , mode , self .fan_speed_memory , "on" )
209+ return self .set_all (
210+ self .pseudo_status .temperature , mode , self .pseudo_status .fan_speed , "on"
211+ )
200212
201213 def set_fan_speed (self , fan_speed : int ) -> SwitchBotCommandResult :
202214 """
@@ -210,7 +222,9 @@ def set_fan_speed(self, fan_speed: int) -> SwitchBotCommandResult:
210222 It is recommended to turn on AirConditioner with the set_all
211223 with all values specified before use this function.
212224 """
213- return self .set_all (self .temperature_memory , self .mode_memory , fan_speed , "on" )
225+ return self .set_all (
226+ self .pseudo_status .temperature , self .pseudo_status .mode , fan_speed , "on"
227+ )
214228
215229
216230class TV (SwitchBotRemoteDevice ):
0 commit comments