66import json
77import colorsys
88from dataclasses import dataclass , field , InitVar
9- from typing import NamedTuple , Optional , Union
9+ from typing import Any , Dict , NamedTuple , Optional , Union
1010import re
1111import requests
1212
@@ -38,7 +38,7 @@ class Helpers:
3838 """VeSync Helper Functions."""
3939
4040 @staticmethod
41- def req_headers (manager ) -> dict :
41+ def req_headers (manager ) -> Dict [ str , str ] :
4242 """Build header for api requests."""
4343 headers = {
4444 'accept-language' : 'en' ,
@@ -51,25 +51,25 @@ def req_headers(manager) -> dict:
5151 return headers
5252
5353 @staticmethod
54- def req_header_bypass () -> dict :
54+ def req_header_bypass () -> Dict [ str , str ] :
5555 """Build header for api requests on 'bypass' endpoint."""
5656 return {
5757 'Content-Type' : 'application/json; charset=UTF-8' ,
5858 'User-Agent' : 'okhttp/3.12.1' ,
5959 }
6060
6161 @staticmethod
62- def req_body_base (manager ) -> dict :
62+ def req_body_base (manager ) -> Dict [ str , str ] :
6363 """Return universal keys for body of api requests."""
6464 return {'timeZone' : manager .time_zone , 'acceptLanguage' : 'en' }
6565
6666 @staticmethod
67- def req_body_auth (manager ) -> dict :
67+ def req_body_auth (manager ) -> Dict [ str , str ] :
6868 """Keys for authenticating api requests."""
6969 return {'accountID' : manager .account_id , 'token' : manager .token }
7070
7171 @staticmethod
72- def req_body_details () -> dict :
72+ def req_body_details () -> Dict [ str , str ] :
7373 """Detail keys for api requests."""
7474 return {
7575 'appVersion' : APP_VERSION ,
@@ -79,83 +79,57 @@ def req_body_details() -> dict:
7979 }
8080
8181 @classmethod
82- def req_body (cls , manager , type_ ) -> dict :
82+ def req_body (cls , manager , type_ ) -> Dict [ str , Any ] :
8383 """Builder for body of api requests."""
84- body = {}
84+ body = cls . req_body_base ( manager )
8585
8686 if type_ == 'login' :
87- body = {** cls .req_body_base (manager ),
88- ** cls .req_body_details ()}
89- body ['email' ] = manager .username
90- body ['password' ] = cls .hash_password (manager .password )
91- body ['devToken' ] = ''
92- body ['userType' ] = USER_TYPE
93- body ['method' ] = 'login'
94- elif type_ == 'devicedetail' :
95- body = {
96- ** cls .req_body_base (manager ),
97- ** cls .req_body_auth (manager ),
98- ** cls .req_body_details (),
99- }
100- body ['method' ] = 'devicedetail'
101- body ['mobileId' ] = MOBILE_ID
102- elif type_ == 'devicelist' :
103- body = {
104- ** cls .req_body_base (manager ),
105- ** cls .req_body_auth (manager ),
106- ** cls .req_body_details (),
107- }
87+ body |= cls .req_body_details () # type: ignore
88+ body |= {
89+ 'email' : manager .username ,
90+ 'password' : cls .hash_password (manager .password ),
91+ 'devToken' : '' ,
92+ 'userType' : USER_TYPE ,
93+ 'method' : 'login'
94+ } # type: ignore
95+ return body
96+
97+ body |= cls .req_body_auth (manager ) # type: ignore
98+
99+ if type_ == 'devicestatus' :
100+ return body
101+
102+ body |= cls .req_body_details () # type: ignore
103+
104+ if type_ == 'devicelist' :
108105 body ['method' ] = 'devices'
109106 body ['pageNo' ] = '1'
110107 body ['pageSize' ] = '100'
111- elif type_ == 'devicestatus' :
112- body = {** cls .req_body_base (manager ),
113- ** cls .req_body_auth (manager )}
108+
109+ elif type_ == 'devicedetail' :
110+ body ['method' ] = 'devicedetail'
111+ body ['mobileId' ] = MOBILE_ID
112+
114113 elif type_ == 'energy_week' :
115- body = {
116- ** cls .req_body_base (manager ),
117- ** cls .req_body_auth (manager ),
118- ** cls .req_body_details (),
119- }
120114 body ['method' ] = 'energyweek'
121115 body ['mobileId' ] = MOBILE_ID
116+
122117 elif type_ == 'energy_month' :
123- body = {
124- ** cls .req_body_base (manager ),
125- ** cls .req_body_auth (manager ),
126- ** cls .req_body_details (),
127- }
128118 body ['method' ] = 'energymonth'
129119 body ['mobileId' ] = MOBILE_ID
120+
130121 elif type_ == 'energy_year' :
131- body = {
132- ** cls .req_body_base (manager ),
133- ** cls .req_body_auth (manager ),
134- ** cls .req_body_details (),
135- }
136122 body ['method' ] = 'energyyear'
137123 body ['mobileId' ] = MOBILE_ID
124+
138125 elif type_ == 'bypass' :
139- body = {
140- ** cls .req_body_base (manager ),
141- ** cls .req_body_auth (manager ),
142- ** cls .req_body_details (),
143- }
144126 body ['method' ] = 'bypass'
127+
145128 elif type_ == 'bypassV2' :
146- body = {
147- ** cls .req_body_base (manager ),
148- ** cls .req_body_auth (manager ),
149- ** cls .req_body_details (),
150- }
151129 body ['deviceRegion' ] = DEFAULT_REGION
152130 body ['method' ] = 'bypassV2'
131+
153132 elif type_ == 'bypass_config' :
154- body = {
155- ** cls .req_body_base (manager ),
156- ** cls .req_body_auth (manager ),
157- ** cls .req_body_details (),
158- }
159133 body ['method' ] = 'firmwareUpdateInfo'
160134
161135 return body
0 commit comments