| 1 |
import copy |
| 2 |
from typing import Any |
| 3 |
import pyvesync.const as const |
| 4 |
from defaults import TestDefaults |
| 5 |
from pyvesync.device_map import DeviceMapTemplate |
| 6 |
import call_json_switches |
| 7 |
import call_json_outlets |
| 8 |
import call_json_bulbs |
| 9 |
import call_json_fans |
| 10 |
import call_json_humidifiers |
| 11 |
import call_json_purifiers |
| 12 |
|
| 13 |
|
| 14 |
API_BASE_URL = const.API_BASE_URL |
| 15 |
API_TIMEOUT = const.API_TIMEOUT |
| 16 |
DEFAULT_TZ = const.DEFAULT_TZ |
| 17 |
APP_VERSION = const.APP_VERSION |
| 18 |
PHONE_BRAND = const.PHONE_BRAND |
| 19 |
PHONE_OS = const.PHONE_OS |
| 20 |
MOBILE_ID = const.MOBILE_ID |
| 21 |
USER_TYPE = const.USER_TYPE |
| 22 |
|
| 23 |
ALL_DEVICE_MAP_MODULES: list[DeviceMapTemplate] = [ |
| 24 |
*call_json_bulbs.bulb_modules, |
| 25 |
*call_json_fans.fan_modules, |
| 26 |
*call_json_outlets.outlet_modules, |
| 27 |
*call_json_switches.switch_modules, |
| 28 |
*call_json_humidifiers.humidifier_modules, |
| 29 |
*call_json_purifiers.purifier_modules |
| 30 |
] |
| 31 |
|
| 32 |
ALL_DEVICE_MAP_DICT: dict[str, DeviceMapTemplate] = { |
| 33 |
module.setup_entry: module for module in ALL_DEVICE_MAP_MODULES |
| 34 |
} |
| 35 |
"""Contains dictionary of setup_entry: DeviceMapTemplate for all devices.""" |
| 36 |
|
| 37 |
|
| 38 |
""" |
| 39 |
DEFAULT_BODY = Standard body for new device calls |
| 40 |
DEFAULT_HEADER = standard header for most calls |
| 41 |
DEFAULT_HEADER_BYPASS = standard header for most calls api V2 |
| 42 |
ENERGY_HISTORY = standard outlet energy history response |
| 43 |
------------------------------------------------------- |
| 44 |
login_call_body(email, pass) = body of login call |
| 45 |
LOGIN_RET_BODY = return of login call |
| 46 |
------------------------------------------------------- |
| 47 |
get_devices_body() = body of call to get device list |
| 48 |
LIST_CONF_10AEU = device list entry for 10A Europe outlet |
| 49 |
LIST_CONF_10AUS = devlice list entry for 10A US outlet |
| 50 |
LIST_CONF_7A = device list entry for 7A outlet |
| 51 |
LIST_CONF_AIR = device list entry for air purifier |
| 52 |
LIST_CONF_15A = device list entry for 15A outlet |
| 53 |
LIST_CONF_WS = device list entry for wall switch |
| 54 |
LIST_CONF_ESL100 = device list entry for bulb ESL100 |
| 55 |
LIST_CONF_OUTDOOR_1 = devlice list entry for outdoor outlet subDevice 1 |
| 56 |
LIST_CONF_OUTDOOR_2 = devlice list entry for outdoor outlet subDevice 2 |
| 57 |
DEVLIST_ALL = Return tuple for all devices |
| 58 |
DEVLIST_10AEU = device list return for only 10A eu outlet |
| 59 |
DEVLIST_10AUS = device list return for only 10A us outlet |
| 60 |
DEVLIST_7A = device list return for only 7A outlet |
| 61 |
DEVLIST_15A = device list return for only 15A outlet |
| 62 |
DEVLIST_WS = device list return for only wall switch |
| 63 |
DEVLIST_AIR = device list return for just air purifier |
| 64 |
DEVLIST_ESL100 = device list return for just ESL100 bulb |
| 65 |
DEVLIST_OUTDOOR_1 = device list return for outdoor outlet subDevice 1 |
| 66 |
DEVLIST_OUTDOOR_2 = device list return for outdoor outlet subDevice 2 |
| 67 |
--------------------------------------------------------- |
| 68 |
DETAILS_10A = Return for 10A outlet device details |
| 69 |
DETAILS_15A = Return for 15A outlet device details |
| 70 |
DETAILS_7A = Return for 7A outlet device details |
| 71 |
DETAILS_WS = Return for wall switch device details |
| 72 |
DETAILS_AIR = Return for Air Purifier device details |
| 73 |
DETAILS_ESL100 = Return for ESL100 Bulb device details |
| 74 |
DETAILS_OUTDOOR = return for 2 plug outdoor outlet |
| 75 |
|
| 76 |
""" |
| 77 |
|
| 78 |
BULBS = call_json_bulbs.BULBS |
| 79 |
FANS = call_json_fans.FANS |
| 80 |
OUTLETS = call_json_outlets.OUTLETS |
| 81 |
SWITCHES = call_json_switches.SWITCHES |
| 82 |
|
| 83 |
|
| 84 |
DEFAULT_HEADER = { |
| 85 |
'accept-language': 'en', |
| 86 |
'accountId': TestDefaults.account_id, |
| 87 |
'appVersion': APP_VERSION, |
| 88 |
'content-type': 'application/json', |
| 89 |
'tk': TestDefaults.token, |
| 90 |
'tz': DEFAULT_TZ, |
| 91 |
} |
| 92 |
|
| 93 |
DEFAULT_HEADER_BYPASS = { |
| 94 |
'Content-Type': 'application/json; charset=UTF-8', |
| 95 |
'User-Agent': 'okhttp/3.12.1' |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
def response_body(code: int = 0, msg: str | None = 'Success') -> dict[str, Any]: |
| 100 |
"""Return base response dictionary.""" |
| 101 |
return { |
| 102 |
'code': code, |
| 103 |
'traceId': TestDefaults.trace_id, |
| 104 |
'msg': msg |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
class LoginResponses: |
| 109 |
GET_TOKEN_RESPONSE_SUCCESS = { |
| 110 |
"traceId": TestDefaults.trace_id, |
| 111 |
"code": 0, |
| 112 |
"msg": None, |
| 113 |
"result": { |
| 114 |
"accountID": TestDefaults.account_id, |
| 115 |
"avatarIcon": "", |
| 116 |
"nickName": "", |
| 117 |
"mailConfirmation": True, |
| 118 |
"registerSourceDetail": None, |
| 119 |
"verifyEmail": TestDefaults.email, |
| 120 |
"bizToken": None, |
| 121 |
"mfaMethodList": None, |
| 122 |
"authorizeCode": TestDefaults.authorization_code, |
| 123 |
"userType": "1", |
| 124 |
}, |
| 125 |
} |
| 126 |
|
| 127 |
LOGIN_RESPONSE_SUCCESS = { |
| 128 |
"traceId": TestDefaults.trace_id, |
| 129 |
"code": 0, |
| 130 |
"msg": "request success", |
| 131 |
"module": None, |
| 132 |
"stacktrace": None, |
| 133 |
"result": { |
| 134 |
"birthday": "", |
| 135 |
"gender": "", |
| 136 |
"acceptLanguage": "en", |
| 137 |
"measureUnit": "Imperial", |
| 138 |
"weightG": 0.0, |
| 139 |
"heightCm": 0.0, |
| 140 |
"weightTargetSt": 0.0, |
| 141 |
"heightUnit": "FT", |
| 142 |
"heightFt": 0.0, |
| 143 |
"weightTargetKg": 0.0, |
| 144 |
"weightTargetLb": 0.0, |
| 145 |
"weightUnit": "LB", |
| 146 |
"maximalHeartRate": 0, |
| 147 |
"targetBfr": 0.0, |
| 148 |
"displayFlag": [], |
| 149 |
"targetStatus": 0, |
| 150 |
"realWeightKg": 0.0, |
| 151 |
"realWeightLb": 0.0, |
| 152 |
"realWeightUnit": "lb", |
| 153 |
"heartRateZones": 0.0, |
| 154 |
"runStepLongCm": 0.0, |
| 155 |
"walkStepLongCm": 0.0, |
| 156 |
"stepTarget": 0.0, |
| 157 |
"sleepTargetMins": 0.0, |
| 158 |
"regionType": 1, |
| 159 |
"currentRegion": TestDefaults.region, |
| 160 |
"token": TestDefaults.token, |
| 161 |
"countryCode": TestDefaults.country_code, |
| 162 |
"accountID": TestDefaults.account_id, |
| 163 |
"bizToken": None, |
| 164 |
}, |
| 165 |
} |
| 166 |
|
| 167 |
LOGIN_RESPONSE_CROSS_REGION = { |
| 168 |
"traceId": "TRACE_ID", |
| 169 |
"code": -11260022, |
| 170 |
"msg": "login trigger cross region error.", |
| 171 |
"module": None, |
| 172 |
"stacktrace": None, |
| 173 |
"result": { |
| 174 |
"birthday": None, |
| 175 |
"gender": None, |
| 176 |
"acceptLanguage": None, |
| 177 |
"measureUnit": None, |
| 178 |
"weightG": None, |
| 179 |
"heightCm": None, |
| 180 |
"weightTargetSt": None, |
| 181 |
"heightUnit": None, |
| 182 |
"heightFt": None, |
| 183 |
"weightTargetKg": None, |
| 184 |
"weightTargetLb": None, |
| 185 |
"weightUnit": None, |
| 186 |
"maximalHeartRate": None, |
| 187 |
"targetBfr": None, |
| 188 |
"displayFlag": None, |
| 189 |
"targetStatus": None, |
| 190 |
"realWeightKg": None, |
| 191 |
"realWeightLb": None, |
| 192 |
"realWeightUnit": None, |
| 193 |
"heartRateZones": None, |
| 194 |
"runStepLongCm": None, |
| 195 |
"walkStepLongCm": None, |
| 196 |
"stepTarget": None, |
| 197 |
"sleepTargetMins": None, |
| 198 |
"regionType": 1, |
| 199 |
"currentRegion": TestDefaults.region, |
| 200 |
"token": None, |
| 201 |
"countryCode": TestDefaults.country_code, |
| 202 |
"accountID": TestDefaults.account_id, |
| 203 |
"bizToken": TestDefaults.biz_token, |
| 204 |
}, |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
class LoginRequests: |
| 209 |
authentication_success = { |
| 210 |
"acceptLanguage": "en", |
| 211 |
"accountID": "", |
| 212 |
"clientInfo": const.PHONE_BRAND, |
| 213 |
"clientType": const.CLIENT_TYPE, |
| 214 |
"clientVersion": const.APP_VERSION, |
| 215 |
"debugMode": False, |
| 216 |
"method": "authByPWDOrOTM", |
| 217 |
"osInfo": const.PHONE_OS, |
| 218 |
"terminalId": TestDefaults.terminal_id, |
| 219 |
"timeZone": const.DEFAULT_TZ, |
| 220 |
"token": "", |
| 221 |
"traceId": TestDefaults.trace_id, |
| 222 |
"userCountryCode": TestDefaults.country_code, |
| 223 |
"sourceAppID": TestDefaults.app_id, |
| 224 |
"appID": TestDefaults.app_id, |
| 225 |
"authProtocolType": "generic", |
| 226 |
"email": TestDefaults.email, |
| 227 |
"password": TestDefaults.password, |
| 228 |
} |
| 229 |
|
| 230 |
login_success = { |
| 231 |
"acceptLanguage": "en", |
| 232 |
"accountID": "", |
| 233 |
"clientInfo": const.PHONE_BRAND, |
| 234 |
"clientType": const.CLIENT_TYPE, |
| 235 |
"clientVersion": const.APP_VERSION, |
| 236 |
"debugMode": False, |
| 237 |
"method": "loginByAuthorizeCode4Vesync", |
| 238 |
"osInfo": const.PHONE_OS, |
| 239 |
"terminalId": TestDefaults.terminal_id, |
| 240 |
"timeZone": const.DEFAULT_TZ, |
| 241 |
"token": "", |
| 242 |
"traceId": TestDefaults.trace_id, |
| 243 |
"userCountryCode": TestDefaults.country_code, |
| 244 |
"authorizeCode": TestDefaults.authorization_code, |
| 245 |
"emailSubscriptions": False, |
| 246 |
} |
| 247 |
|
| 248 |
login_cross_region = { |
| 249 |
"acceptLanguage": "en", |
| 250 |
"accountID": "", |
| 251 |
"clientInfo": const.PHONE_BRAND, |
| 252 |
"clientType": const.CLIENT_TYPE, |
| 253 |
"clientVersion": const.APP_VERSION, |
| 254 |
"debugMode": False, |
| 255 |
"method": "loginByAuthorizeCode4Vesync", |
| 256 |
"osInfo": const.PHONE_OS, |
| 257 |
"terminalId": "2124569cc4905328aac52b39669b1b15e", |
| 258 |
"timeZone": const.DEFAULT_TZ, |
| 259 |
"token": "", |
| 260 |
"traceId": TestDefaults.trace_id, |
| 261 |
"userCountryCode": TestDefaults.country_code, |
| 262 |
"bizToken": TestDefaults.biz_token, |
| 263 |
"emailSubscriptions": False, |
| 264 |
"regionChange": "lastRegion", |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
def BYPASS_V1_BODY(cid: str, config_module: str, json_cmd: dict): |
| 269 |
return { |
| 270 |
"traceId": TestDefaults.trace_id, |
| 271 |
"method": "bypass", |
| 272 |
"token": TestDefaults.token, |
| 273 |
"accountID": TestDefaults.account_id, |
| 274 |
"timeZone": DEFAULT_TZ, |
| 275 |
"acceptLanguage": "en", |
| 276 |
"appVersion": APP_VERSION, |
| 277 |
"phoneBrand": PHONE_BRAND, |
| 278 |
"phoneOS": PHONE_OS, |
| 279 |
"cid": cid, |
| 280 |
"configModule": config_module, |
| 281 |
"jsonCmd": json_cmd |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
def login_call_body(email, password): |
| 286 |
json_object = { |
| 287 |
'acceptLanguage': 'en', |
| 288 |
'appVersion': APP_VERSION, |
| 289 |
'devToken': '', |
| 290 |
'email': email, |
| 291 |
'method': 'login', |
| 292 |
'password': password, |
| 293 |
'phoneBrand': PHONE_BRAND, |
| 294 |
'phoneOS': PHONE_OS, |
| 295 |
'timeZone': DEFAULT_TZ, |
| 296 |
'traceId': TestDefaults.trace_id, |
| 297 |
'userType': '1', |
| 298 |
} |
| 299 |
return json_object |
| 300 |
|
| 301 |
|
| 302 |
def device_list_item(device_map: DeviceMapTemplate) -> dict: |
| 303 |
"""Create a device list item from a device map. |
| 304 |
|
| 305 |
Parameters |
| 306 |
---------- |
| 307 |
device_map : DeviceMapTemplate |
| 308 |
Device map to create device list item from |
| 309 |
|
| 310 |
Returns |
| 311 |
------- |
| 312 |
dict |
| 313 |
Device list item dictionary |
| 314 |
""" |
| 315 |
return { |
| 316 |
"deviceType": device_map.dev_types[0], |
| 317 |
"isOwner": True, |
| 318 |
"deviceName": TestDefaults.name(device_map.setup_entry), |
| 319 |
"deviceImg": "", |
| 320 |
"cid": TestDefaults.cid(device_map.setup_entry), |
| 321 |
"uuid": TestDefaults.uuid(device_map.setup_entry), |
| 322 |
"macID": TestDefaults.macid(device_map.setup_entry), |
| 323 |
"connectionType": "wifi", |
| 324 |
"type": device_map.product_type, |
| 325 |
"configModule": TestDefaults.config_module(device_map.setup_entry), |
| 326 |
"mode": None, |
| 327 |
"speed": None, |
| 328 |
"currentFirmVersion": None, |
| 329 |
"speed": None, |
| 330 |
"subDeviceNo": None, |
| 331 |
"extension": None, |
| 332 |
"deviceProps": None, |
| 333 |
"deviceStatus": const.DeviceStatus.ON, |
| 334 |
"connectionStatus": const.ConnectionStatus.ONLINE, |
| 335 |
"product_type": device_map.product_type |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
class DeviceList: |
| 340 |
list_response_base: dict[str, Any] = { |
| 341 |
'code': 0, |
| 342 |
'traceId': TestDefaults.trace_id, |
| 343 |
'msg': 'Success', |
| 344 |
'result': { |
| 345 |
'pageNo': 1, |
| 346 |
'pageSize': 100, |
| 347 |
'total': 0, |
| 348 |
'list': [], |
| 349 |
} |
| 350 |
} |
| 351 |
device_list_base: dict[str, Any] = { |
| 352 |
'extension': None, |
| 353 |
'isOwner': True, |
| 354 |
'authKey': None, |
| 355 |
'deviceStatus': 'on', |
| 356 |
'connectionStatus': 'online', |
| 357 |
'connectionType': 'wifi', |
| 358 |
'mode': None, |
| 359 |
'speed': None, |
| 360 |
'deviceProps': None, |
| 361 |
'configModule': 'ConfigModule', |
| 362 |
'deviceRegion': TestDefaults.country_code, |
| 363 |
|
| 364 |
} |
| 365 |
|
| 366 |
bulbs = dict.fromkeys(call_json_bulbs.BULBS, "wifi-light") |
| 367 |
outlets = dict.fromkeys(call_json_outlets.OUTLETS, "wifi-switch") |
| 368 |
fans = dict.fromkeys(call_json_fans.FANS, "wifi-air") |
| 369 |
switches = dict.fromkeys(call_json_switches.SWITCHES, "Switches") |
| 370 |
|
| 371 |
|
| 372 |
@classmethod |
| 373 |
def device_list_item(cls, module: DeviceMapTemplate): |
| 374 |
model_types = {**cls.bulbs, **cls.outlets, **cls.fans, **cls.switches} |
| 375 |
|
| 376 |
device_dict = cls.device_list_base |
| 377 |
model_dict = device_dict.copy() |
| 378 |
|
| 379 |
model_dict['deviceName'] = TestDefaults.name(module.setup_entry) |
| 380 |
model_dict['type'] = model_types.get(module.setup_entry) |
| 381 |
model_dict['cid'] = TestDefaults.cid(module.setup_entry) |
| 382 |
model_dict['uuid'] = TestDefaults.uuid(module.setup_entry) |
| 383 |
model_dict['macID'] = TestDefaults.macid(module.setup_entry) |
| 384 |
model_dict['deviceType'] = module.dev_types[0] |
| 385 |
if module.setup_entry == 'ESO15-TB': |
| 386 |
model_dict['subDeviceNo'] = 1 |
| 387 |
return model_dict |
| 388 |
|
| 389 |
@classmethod |
| 390 |
def device_list_response( |
| 391 |
cls, |
| 392 |
setup_entrys: list[str] | str | None = None, |
| 393 |
): |
| 394 |
"""Class method that returns the api get_devices response |
| 395 |
|
| 396 |
Args: |
| 397 |
setup_entrys (list, str optional): List or string of setup_entry(s) |
| 398 |
to return. Defaults to None. |
| 399 |
""" |
| 400 |
if setup_entrys is None: |
| 401 |
entry_list = ALL_DEVICE_MAP_DICT |
| 402 |
elif isinstance(setup_entrys, str): |
| 403 |
entry_list = { |
| 404 |
k: v for k, v in ALL_DEVICE_MAP_DICT.items() if k == setup_entrys |
| 405 |
} |
| 406 |
elif isinstance(setup_entrys, list): |
| 407 |
entry_list = { |
| 408 |
k: v for k, v in ALL_DEVICE_MAP_DICT.items() if k in setup_entrys |
| 409 |
} |
| 410 |
response_base = copy.deepcopy(cls.list_response_base) |
| 411 |
|
| 412 |
response_base['result']['list'] = [] |
| 413 |
response_base['result']['total'] = 0 |
| 414 |
for module in entry_list.values(): |
| 415 |
response_base['result']['list'].append(cls.device_list_item(module)) |
| 416 |
response_base['result']['total'] += 1 |
| 417 |
return response_base |
| 418 |
|
| 419 |
LIST_CONF_7A = { |
| 420 |
'deviceType': 'wifi-switch-1.3', |
| 421 |
'extension': None, |
| 422 |
'macID': None, |
| 423 |
'type': 'wifi-switch', |
| 424 |
'deviceName': 'Name 7A Outlet', |
| 425 |
'connectionType': 'wifi', |
| 426 |
'uuid': None, |
| 427 |
'speed': None, |
| 428 |
'deviceStatus': 'on', |
| 429 |
'mode': None, |
| 430 |
'configModule': '7AOutlet', |
| 431 |
'currentFirmVersion': '1.95', |
| 432 |
'connectionStatus': 'online', |
| 433 |
'cid': '7A-CID', |
| 434 |
} |
| 435 |
|
| 436 |
LIST_CONF_15A = { |
| 437 |
'deviceType': 'ESW15-USA', |
| 438 |
'extension': None, |
| 439 |
'macID': None, |
| 440 |
'type': 'wifi-switch', |
| 441 |
'deviceName': 'Name 15A Outlet', |
| 442 |
'connectionType': 'wifi', |
| 443 |
'uuid': 'UUID', |
| 444 |
'speed': None, |
| 445 |
'deviceStatus': 'on', |
| 446 |
'mode': None, |
| 447 |
'configModule': '15AOutletNightlight', |
| 448 |
'currentFirmVersion': None, |
| 449 |
'connectionStatus': 'online', |
| 450 |
'cid': '15A-CID', |
| 451 |
} |
| 452 |
|
| 453 |
LIST_CONF_WS = { |
| 454 |
'deviceType': 'ESWL01', |
| 455 |
'extension': None, |
| 456 |
'macID': None, |
| 457 |
'type': 'Switches', |
| 458 |
'deviceName': 'Name Wall Switch', |
| 459 |
'connectionType': 'wifi', |
| 460 |
'uuid': 'UUID', |
| 461 |
'speed': None, |
| 462 |
'deviceStatus': 'on', |
| 463 |
'mode': None, |
| 464 |
'configModule': 'InwallswitchUS', |
| 465 |
'currentFirmVersion': None, |
| 466 |
'connectionStatus': 'online', |
| 467 |
'cid': 'WS-CID', |
| 468 |
} |
| 469 |
|
| 470 |
LIST_CONF_10AEU = { |
| 471 |
'deviceType': 'ESW01-EU', |
| 472 |
'extension': None, |
| 473 |
'macID': None, |
| 474 |
'type': 'wifi-switch', |
| 475 |
'deviceName': 'Name 10A Outlet', |
| 476 |
'connectionType': 'wifi', |
| 477 |
'uuid': 'UUID', |
| 478 |
'speed': None, |
| 479 |
'deviceStatus': 'on', |
| 480 |
'mode': None, |
| 481 |
'configModule': '10AOutletEU', |
| 482 |
'currentFirmVersion': None, |
| 483 |
'connectionStatus': 'online', |
| 484 |
'cid': '10A-CID', |
| 485 |
} |
| 486 |
|
| 487 |
LIST_CONF_10AUS = { |
| 488 |
'deviceType': 'ESW03-USA', |
| 489 |
'extension': None, |
| 490 |
'macID': None, |
| 491 |
'type': 'wifi-switch', |
| 492 |
'deviceName': 'Name 10A Outlet', |
| 493 |
'connectionType': 'wifi', |
| 494 |
'uuid': 'UUID', |
| 495 |
'speed': None, |
| 496 |
'deviceStatus': 'on', |
| 497 |
'mode': None, |
| 498 |
'configModule': '10AOutletUSA', |
| 499 |
'currentFirmVersion': None, |
| 500 |
'connectionStatus': 'online', |
| 501 |
'cid': '10A-CID', |
| 502 |
} |
| 503 |
|
| 504 |
LIST_CONF_OUTDOOR_1 = { |
| 505 |
'deviceRegion': 'US', |
| 506 |
'deviceName': 'Outdoor Socket B', |
| 507 |
'cid': 'OUTDOOR-CID', |
| 508 |
'deviceStatus': 'on', |
| 509 |
'connectionStatus': 'online', |
| 510 |
'connectionType': 'wifi', |
| 511 |
'deviceType': 'ESO15-TB', |
| 512 |
'type': 'wifi-switch', |
| 513 |
'uuid': 'UUID', |
| 514 |
'configModule': 'OutdoorSocket15A', |
| 515 |
'macID': None, |
| 516 |
'mode': None, |
| 517 |
'speed': None, |
| 518 |
'extension': None, |
| 519 |
'currentFirmVersion': None, |
| 520 |
'subDeviceNo': 1, |
| 521 |
} |
| 522 |
|
| 523 |
LIST_CONF_OUTDOOR_2 = { |
| 524 |
'deviceRegion': 'US', |
| 525 |
'deviceName': 'Outdoor Socket B', |
| 526 |
'cid': 'OUTDOOR-CID', |
| 527 |
'deviceStatus': 'on', |
| 528 |
'connectionStatus': 'online', |
| 529 |
'connectionType': 'wifi', |
| 530 |
'deviceType': 'ESO15-TB', |
| 531 |
'type': 'wifi-switch', |
| 532 |
'uuid': 'UUID', |
| 533 |
'configModule': 'OutdoorSocket15A', |
| 534 |
'macID': None, |
| 535 |
'mode': None, |
| 536 |
'speed': None, |
| 537 |
'extension': None, |
| 538 |
'currentFirmVersion': None, |
| 539 |
'subDeviceNo': 2, |
| 540 |
} |
| 541 |
|
| 542 |
LIST_CONF_ESL100 = { |
| 543 |
'deviceRegion': 'US', |
| 544 |
'deviceName': 'Etekcity Soft White Bulb', |
| 545 |
'cid': 'ESL100-CID', |
| 546 |
'deviceStatus': 'on', |
| 547 |
'connectionStatus': 'online', |
| 548 |
'connectionType': 'wifi', |
| 549 |
'deviceType': 'ESL100', |
| 550 |
'type': 'Wifi-light', |
| 551 |
'uuid': 'UUID', |
| 552 |
'configModule': 'WifiSmartBulb', |
| 553 |
'macID': None, |
| 554 |
'mode': None, |
| 555 |
'speed': None, |
| 556 |
'extension': None, |
| 557 |
'currentFirmVersion': None, |
| 558 |
'subDeviceNo': None, |
| 559 |
} |
| 560 |
|
| 561 |
LIST_CONF_ESL100CW = { |
| 562 |
'deviceRegion': 'US', |
| 563 |
'deviceName': 'ESL100CW NAME', |
| 564 |
'cid': 'ESL100CW-CID', |
| 565 |
'deviceStatus': 'on', |
| 566 |
'connectionStatus': 'online', |
| 567 |
'connectionType': 'wifi', |
| 568 |
'deviceType': 'ESL100CW', |
| 569 |
'type': 'Wifi-light', |
| 570 |
'uuid': 'ESL100CW-UUID', |
| 571 |
'configModule': 'WifiSmartBulb', |
| 572 |
'macID': None, |
| 573 |
'mode': None, |
| 574 |
'speed': None, |
| 575 |
'extension': None, |
| 576 |
'currentFirmVersion': None, |
| 577 |
'subDeviceNo': None, |
| 578 |
} |
| 579 |
|
| 580 |
LIST_CONF_AIR = { |
| 581 |
'deviceName': 'Name Air Purifier', |
| 582 |
'cid': 'AIRPUR-CID', |
| 583 |
'deviceStatus': 'on', |
| 584 |
'connectionStatus': 'online', |
| 585 |
'connectionType': 'wifi', |
| 586 |
'deviceType': 'LV-PUR131S', |
| 587 |
'type': 'wifi-air', |
| 588 |
'uuid': 'UUID', |
| 589 |
'configModule': 'AirPurifier131', |
| 590 |
'macID': None, |
| 591 |
'mode': 'manual', |
| 592 |
'speed': 'low', |
| 593 |
'extension': None, |
| 594 |
'currentFirmVersion': None, |
| 595 |
} |
| 596 |
|
| 597 |
LIST_CONF_DUAL200S = { |
| 598 |
'deviceRegion': 'EU', |
| 599 |
'isOwner': True, |
| 600 |
'authKey': None, |
| 601 |
'deviceName': '200S NAME', |
| 602 |
'cid': 'CID-200S', |
| 603 |
'deviceStatus': 'on', |
| 604 |
'connectionStatus': 'online', |
| 605 |
'connectionType': 'WiFi+BTOnboarding+BTNotify', |
| 606 |
'deviceType': 'LUH-D301S-WEU', |
| 607 |
'type': 'wifi-air', |
| 608 |
'uuid': 'UUID-200S', |
| 609 |
'configModule': 'WFON_AHM_LUH-D301S-WEU_EU', |
| 610 |
'macID': None, |
| 611 |
'mode': None, |
| 612 |
'speed': None, |
| 613 |
'extension': None, |
| 614 |
'currentFirmVersion': None, |
| 615 |
'subDeviceNo': None, |
| 616 |
'subDeviceType': None, |
| 617 |
} |
| 618 |
|
| 619 |
LIST_CONF_DIMMER = { |
| 620 |
"deviceRegion": "US", |
| 621 |
"deviceName": "Etekcity Dimmer Switch", |
| 622 |
"cid": "DIM-CID", |
| 623 |
"deviceStatus": "on", |
| 624 |
"connectionStatus": "online", |
| 625 |
"connectionType": "wifi", |
| 626 |
"deviceType": "ESWD16", |
| 627 |
"type": "Switches", |
| 628 |
"uuid": "DIM-UUID", |
| 629 |
"configModule": "WifiWallDimmer" |
| 630 |
} |
| 631 |
|
| 632 |
LIST_CONF_600S = { |
| 633 |
'deviceRegion': 'US', |
| 634 |
'deviceName': 'Bedroom Humidifier', |
| 635 |
'deviceImg': '', |
| 636 |
'cid': 'CID-600S', |
| 637 |
'deviceStatus': 'on', |
| 638 |
'connectionStatus': 'online', |
| 639 |
'connectionType': 'WiFi+BTOnboarding+BTNotify', |
| 640 |
'deviceType': 'LUH-A602S-WUS', |
| 641 |
'type': 'wifi-air', |
| 642 |
'uuid': 'UUID-600S', |
| 643 |
'configModule': 'WFON_AHM_LUH-A602S-WUS_US', |
| 644 |
'macID': None, |
| 645 |
'subDeviceNo': None, |
| 646 |
'subDeviceType': None, |
| 647 |
'deviceProp': None |
| 648 |
} |
| 649 |
|
| 650 |
LIST_CONF_ESL100MC = { |
| 651 |
"cid": "CID-ESL100MC", |
| 652 |
"uuid": "UUID-ESL100MC", |
| 653 |
"macID": None, |
| 654 |
"subDeviceNo": 0, |
| 655 |
"subDeviceType": None, |
| 656 |
"deviceName": "ESL100MC NAME", |
| 657 |
"configModule": "WiFi_Bulb_MulticolorBulb_US", |
| 658 |
"type": "Wifi-light", |
| 659 |
"deviceType": "ESL100MC", |
| 660 |
"deviceStatus": "on", |
| 661 |
"connectionType": "wifi", |
| 662 |
"currentFirmVersion": "1.0.12", |
| 663 |
"connectionStatus": "online", |
| 664 |
"speed": None, |
| 665 |
"extension": None, |
| 666 |
"deviceProp": None |
| 667 |
} |
| 668 |
|
| 669 |
LIST_CONF_LV131S = { |
| 670 |
'deviceName': 'LV131S NAME', |
| 671 |
'cid': 'CID-LV131S', |
| 672 |
'deviceStatus': 'on', |
| 673 |
'connectionStatus': 'online', |
| 674 |
'connectionType': 'wifi', |
| 675 |
'deviceType': 'LV-PUR131S', |
| 676 |
'type': 'wifi-air', |
| 677 |
'uuid': 'UUID-LV131S', |
| 678 |
'configModule': 'AirPurifier131', |
| 679 |
'macID': None, |
| 680 |
'mode': 'auto', |
| 681 |
'speed': None, |
| 682 |
'extension': None, |
| 683 |
'currentFirmVersion': None, |
| 684 |
'subDeviceNo': None, |
| 685 |
'subDeviceType': None |
| 686 |
} |
| 687 |
|
| 688 |
LIST_CONF_VALCENO = { |
| 689 |
"deviceName": "VALCENO NAME", |
| 690 |
"cid": "CID-VALCENO", |
| 691 |
"deviceStatus": "on", |
| 692 |
"connectionStatus": "online", |
| 693 |
"connectionType": "WiFi+BTOnboarding+BTNotify", |
| 694 |
"deviceType": "XYD0001", |
| 695 |
"type": "Wifi-light", |
| 696 |
"uuid": "UUID-VALCENO", |
| 697 |
"configModule": "VC_WFON_BLB_A19-MC_US", |
| 698 |
"macID": None, |
| 699 |
"subDeviceNo": None, |
| 700 |
"subDeviceType": None |
| 701 |
} |
| 702 |
|
| 703 |
API_URL = '/cloud/v1/deviceManaged/devices' |
| 704 |
|
| 705 |
METHOD = 'POST' |
| 706 |
|
| 707 |
FULL_DEV_LIST = [ |
| 708 |
LIST_CONF_10AEU, |
| 709 |
LIST_CONF_10AUS, |
| 710 |
LIST_CONF_15A, |
| 711 |
LIST_CONF_7A, |
| 712 |
LIST_CONF_AIR, |
| 713 |
LIST_CONF_WS, |
| 714 |
LIST_CONF_ESL100, |
| 715 |
LIST_CONF_OUTDOOR_1, |
| 716 |
LIST_CONF_OUTDOOR_2, |
| 717 |
LIST_CONF_DIMMER, |
| 718 |
LIST_CONF_600S, |
| 719 |
LIST_CONF_LV131S, |
| 720 |
LIST_CONF_DUAL200S, |
| 721 |
LIST_CONF_ESL100CW, |
| 722 |
LIST_CONF_ESL100MC, |
| 723 |
LIST_CONF_VALCENO |
| 724 |
|
| 725 |
] |
| 726 |
|
| 727 |
@classmethod |
| 728 |
def DEVICE_LIST_RETURN(cls, dev_conf: dict) -> tuple: |
| 729 |
"""Test the fan.""" |
| 730 |
return ( |
| 731 |
{ |
| 732 |
'code': 0, |
| 733 |
'result': |
| 734 |
{ |
| 735 |
'list': [dev_conf] |
| 736 |
} |
| 737 |
}, |
| 738 |
200 |
| 739 |
) |
| 740 |
|
| 741 |
FAN_TEST = ({'code': 0, 'result': {'list': [LIST_CONF_600S, LIST_CONF_LV131S, |
| 742 |
LIST_CONF_DUAL200S]}}, 200) |
| 743 |
|
| 744 |
DEVLIST_ALL = ({'code': 0, 'result': {'list': FULL_DEV_LIST}}, 200) |
| 745 |
|
| 746 |
DEVLIST_7A = ({'code': 0, 'result': {'list': [LIST_CONF_7A]}}, 200) |
| 747 |
|
| 748 |
DEVLIST_15A = ({'code': 0, 'result': {'list': [LIST_CONF_15A]}}, 200) |
| 749 |
|
| 750 |
DEVLIST_10AEU = ({'code': 0, 'result': {'list': [LIST_CONF_10AEU]}}, 200) |
| 751 |
|
| 752 |
DEVLIST_10AUS = ({'code': 0, 'result': {'list': [LIST_CONF_10AUS]}}, 200) |
| 753 |
|
| 754 |
DEVLIST_WS = ({'code': 0, 'result': {'list': [LIST_CONF_WS]}}, 200) |
| 755 |
|
| 756 |
DEVLIST_DIMMER = ({'code': 0, 'result': {'list': [LIST_CONF_DIMMER]}}, 200) |
| 757 |
|
| 758 |
DEVLIST_AIR = ({'code': 0, 'result': {'list': [LIST_CONF_AIR]}}, 200) |
| 759 |
|
| 760 |
DEVLIST_ESL100 = ({'code': 0, 'result': {'list': [LIST_CONF_ESL100]}}, 200) |
| 761 |
|
| 762 |
DEVLIST_DUAL200S = ({'code': 0, 'result': {'list': [LIST_CONF_DUAL200S]}}, 200) |
| 763 |
|
| 764 |
DEVLIST_OUTDOOR = ( |
| 765 |
{'code': 0, 'result': {'list': [LIST_CONF_OUTDOOR_1, LIST_CONF_OUTDOOR_2]}}, |
| 766 |
200, |
| 767 |
) |
| 768 |
|
| 769 |
|
| 770 |
class DeviceDetails: |
| 771 |
"""Responses for get_details() method for all devices. |
| 772 |
|
| 773 |
class attributes: |
| 774 |
outlets : dict |
| 775 |
Dictionary of outlet responses for each device type. |
| 776 |
switches : dict |
| 777 |
Dictionary of switch responses for each device type. |
| 778 |
bulbs : dict |
| 779 |
Dictionary of bulb responses for each device type. |
| 780 |
fans : dict |
| 781 |
Dictionary of humidifier & air pur responses for each device type. |
| 782 |
all_devices : dict |
| 783 |
Dictionary of all device responses for each device type. |
| 784 |
|
| 785 |
Example |
| 786 |
------- |
| 787 |
outlets = {'ESW01-EU': {'switches': [{'outlet': 0, 'switch': 'on'}]}} |
| 788 |
""" |
| 789 |
|
| 790 |
outlets = call_json_outlets.DETAILS_RESPONSES |
| 791 |
switches = call_json_switches.DETAILS_RESPONSES |
| 792 |
fans = call_json_fans.DETAILS_RESPONSES |
| 793 |
bulbs = call_json_bulbs.DETAILS_RESPONSES |
| 794 |
all_devices = { |
| 795 |
'outlets': outlets, |
| 796 |
'switches': switches, |
| 797 |
'fans': fans, |
| 798 |
'bulbs': bulbs |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
DETAILS_BADCODE = { |
| 803 |
"code": 1000, |
| 804 |
"deviceImg": "", |
| 805 |
"activeTime": 1, |
| 806 |
"energy": 1, |
| 807 |
"power": "1", |
| 808 |
"voltage": "1", |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
STATUS_BODY = { |
| 813 |
'accountID': TestDefaults.account_id, |
| 814 |
'token': TestDefaults.token, |
| 815 |
'uuid': 'UUID', |
| 816 |
'timeZone': DEFAULT_TZ, |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
def off_body(): |
| 821 |
body = STATUS_BODY |
| 822 |
body['status'] = 'off' |
| 823 |
return body, 200 |
| 824 |
|
| 825 |
|
| 826 |
def on_body(): |
| 827 |
body = STATUS_BODY |
| 828 |
body['status'] = 'on' |
| 829 |
return body, 200 |