1- from enum import IntEnum
2- from homeassistant .components .vacuum import VacuumEntityFeature
1+ from .vacuums .base import RobovacCommand
32from .tuyalocalapi import TuyaDevice
4-
5-
6- class RoboVacEntityFeature (IntEnum ):
7- """Supported features of the RoboVac entity."""
8-
9- EDGE = 1
10- SMALL_ROOM = 2
11- CLEANING_TIME = 4
12- CLEANING_AREA = 8
13- DO_NOT_DISTURB = 16
14- AUTO_RETURN = 32
15- CONSUMABLES = 64
16- ROOM = 128
17- ZONE = 256
18- MAP = 512
19- BOOST_IQ = 1024
20-
21-
22- ROBOVAC_SERIES = {
23- "C" : [
24- "T2103" ,
25- "T2117" ,
26- "T2118" ,
27- "T2119" ,
28- "T2120" ,
29- "T2123" ,
30- "T2128" ,
31- "T2130" ,
32- "T2132" ,
33- ],
34- "G" : [
35- "T1250" ,
36- "T2250" ,
37- "T2251" ,
38- "T2252" ,
39- "T2253" ,
40- "T2254" ,
41- "T2150" ,
42- "T2255" ,
43- "T2256" ,
44- "T2257" ,
45- "T2258" ,
46- "T2259" ,
47- "T2270" ,
48- "T2272" ,
49- "T2273" ,
50- ],
51- "L" : ["T2181" , "T2182" , "T2190" , "T2192" , "T2193" , "T2194" ],
52- "X" : ["T2261" , "T2262" , "T2320" ],
53- }
54-
55- HAS_MAP_FEATURE = ["T2253" , * ROBOVAC_SERIES ["L" ], * ROBOVAC_SERIES ["X" ]]
56-
57- HAS_CONSUMABLES = [
58- "T1250" ,
59- "T2181" ,
60- "T2182" ,
61- "T2190" ,
62- "T2193" ,
63- "T2194" ,
64- "T2253" ,
65- "T2256" ,
66- "T2258" ,
67- "T2261" ,
68- "T2273" ,
69- "T2320" ,
70- ]
71-
72- ROBOVAC_SERIES_FEATURES = {
73- "C" : RoboVacEntityFeature .EDGE | RoboVacEntityFeature .SMALL_ROOM ,
74- "G" : RoboVacEntityFeature .CLEANING_TIME
75- | RoboVacEntityFeature .CLEANING_AREA
76- | RoboVacEntityFeature .DO_NOT_DISTURB
77- | RoboVacEntityFeature .AUTO_RETURN ,
78- "L" : RoboVacEntityFeature .CLEANING_TIME
79- | RoboVacEntityFeature .CLEANING_AREA
80- | RoboVacEntityFeature .DO_NOT_DISTURB
81- | RoboVacEntityFeature .AUTO_RETURN
82- | RoboVacEntityFeature .ROOM
83- | RoboVacEntityFeature .ZONE
84- | RoboVacEntityFeature .BOOST_IQ ,
85- "X" : RoboVacEntityFeature .CLEANING_TIME
86- | RoboVacEntityFeature .CLEANING_AREA
87- | RoboVacEntityFeature .DO_NOT_DISTURB
88- | RoboVacEntityFeature .AUTO_RETURN
89- | RoboVacEntityFeature .ROOM
90- | RoboVacEntityFeature .ZONE
91- | RoboVacEntityFeature .BOOST_IQ ,
92- }
93-
94- ROBOVAC_SERIES_FAN_SPEEDS = {
95- "C" : ["No Suction" , "Standard" , "Boost IQ" , "Max" ],
96- "G" : ["Standard" , "Turbo" , "Max" , "Boost IQ" ],
97- "L" : ["Quiet" , "Standard" , "Turbo" , "Max" ],
98- "X" : ["Pure" , "Standard" , "Turbo" , "Max" ],
99- }
100-
101-
102- SUPPORTED_ROBOVAC_MODELS = list (
103- set ([item for sublist in ROBOVAC_SERIES .values () for item in sublist ])
104- )
3+ from .vacuums import ROBOVAC_MODELS
1054
1065
1076class ModelNotSupportedException (Exception ):
@@ -112,48 +11,35 @@ class RoboVac(TuyaDevice):
11211 """"""
11312
11413 def __init__ (self , model_code , * args , ** kwargs ):
115- super ().__init__ (* args , ** kwargs )
116- self .model_code = model_code
117-
118- if self .model_code not in SUPPORTED_ROBOVAC_MODELS :
14+ if model_code not in ROBOVAC_MODELS [model_code ] is None :
11915 raise ModelNotSupportedException (
120- "Model {} is not supported" .format (self . model_code )
16+ "Model {} is not supported" .format (model_code )
12117 )
12218
123- def getHomeAssistantFeatures (self ):
124- supportedFeatures = (
125- VacuumEntityFeature .BATTERY
126- | VacuumEntityFeature .CLEAN_SPOT
127- | VacuumEntityFeature .FAN_SPEED
128- | VacuumEntityFeature .LOCATE
129- | VacuumEntityFeature .PAUSE
130- | VacuumEntityFeature .RETURN_HOME
131- | VacuumEntityFeature .SEND_COMMAND
132- | VacuumEntityFeature .START
133- | VacuumEntityFeature .STATE
134- | VacuumEntityFeature .STOP
135- )
136-
137- if self .model_code in HAS_MAP_FEATURE :
138- supportedFeatures |= VacuumEntityFeature .MAP
19+ self .model_details = ROBOVAC_MODELS [model_code ]
20+ super ().__init__ (self .model_details , * args , ** kwargs )
13921
140- return supportedFeatures
22+ def getHomeAssistantFeatures (self ):
23+ return self .model_details .homeassistant_features
14124
14225 def getRoboVacFeatures (self ):
143- supportedFeatures = ROBOVAC_SERIES_FEATURES [ self .getRoboVacSeries ()]
26+ return self .model_details . robovac_features
14427
145- if self . model_code in HAS_MAP_FEATURE :
146- supportedFeatures |= RoboVacEntityFeature . MAP
28+ def getFanSpeeds ( self ) :
29+ return self . model_details . commands [ RobovacCommand . FAN_SPEED ]. values
14730
148- if self . model_code in HAS_CONSUMABLES :
149- supportedFeatures |= RoboVacEntityFeature . CONSUMABLES
31+ def getModes ( self ) :
32+ return self . model_details . commands [ RobovacCommand . MODE ]. values
15033
151- return supportedFeatures
34+ def getSupportedCommands (self ):
35+ return list (self .model_details .commands .keys ())
15236
153- def getRoboVacSeries (self ):
154- for series , models in ROBOVAC_SERIES .items ():
155- if self .model_code in models :
156- return series
37+ def getCommandCodes (self ):
38+ command_codes = {}
39+ for key , value in self .model_details .commands :
40+ if isinstance (value , dict ):
41+ command_codes [key ] = value .code
42+ else :
43+ command_codes [key ] = value
15744
158- def getFanSpeeds (self ):
159- return ROBOVAC_SERIES_FAN_SPEEDS [self .getRoboVacSeries ()]
45+ return command_codes
0 commit comments