wyzeapy 0.5.21__py3-none-any.whl → 0.5.23__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wyzeapy/__init__.py +2 -3
- wyzeapy/services/base_service.py +18 -18
- wyzeapy/utils.py +15 -9
- wyzeapy/wyze_auth_lib.py +7 -5
- {wyzeapy-0.5.21.dist-info → wyzeapy-0.5.23.dist-info}/METADATA +1 -1
- {wyzeapy-0.5.21.dist-info → wyzeapy-0.5.23.dist-info}/RECORD +8 -8
- {wyzeapy-0.5.21.dist-info → wyzeapy-0.5.23.dist-info}/LICENSES/GPL-3.0-only.txt +0 -0
- {wyzeapy-0.5.21.dist-info → wyzeapy-0.5.23.dist-info}/WHEEL +0 -0
wyzeapy/__init__.py
CHANGED
|
@@ -20,7 +20,6 @@ from .services.sensor_service import SensorService
|
|
|
20
20
|
from .services.switch_service import SwitchService, SwitchUsageService
|
|
21
21
|
from .services.thermostat_service import ThermostatService
|
|
22
22
|
from .services.wall_switch_service import WallSwitchService
|
|
23
|
-
from .utils import check_for_errors_standard
|
|
24
23
|
from .wyze_auth_lib import WyzeAuthLib, Token
|
|
25
24
|
|
|
26
25
|
_LOGGER = logging.getLogger(__name__)
|
|
@@ -84,8 +83,8 @@ class Wyzeapy:
|
|
|
84
83
|
email, password, key_id, api_key, token, self.execute_token_callbacks
|
|
85
84
|
)
|
|
86
85
|
if token:
|
|
87
|
-
# User token supplied,
|
|
88
|
-
await self._auth_lib.
|
|
86
|
+
# User token supplied, refresh on startup
|
|
87
|
+
await self._auth_lib.refresh()
|
|
89
88
|
else:
|
|
90
89
|
await self._auth_lib.get_token_with_username_password(
|
|
91
90
|
email, password, key_id, api_key
|
wyzeapy/services/base_service.py
CHANGED
|
@@ -73,7 +73,7 @@ class BaseService:
|
|
|
73
73
|
|
|
74
74
|
response_json = await self._auth_lib.post(url, json=payload)
|
|
75
75
|
|
|
76
|
-
check_for_errors_standard(response_json)
|
|
76
|
+
check_for_errors_standard(self, response_json)
|
|
77
77
|
|
|
78
78
|
async def get_user_profile(self) -> Dict[Any, Any]:
|
|
79
79
|
await self._auth_lib.refresh_if_should()
|
|
@@ -119,7 +119,7 @@ class BaseService:
|
|
|
119
119
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/home_page/get_object_list",
|
|
120
120
|
json=payload)
|
|
121
121
|
|
|
122
|
-
check_for_errors_standard(response_json)
|
|
122
|
+
check_for_errors_standard(self, response_json)
|
|
123
123
|
|
|
124
124
|
# Cache the devices so that update calls can pull more recent device_params
|
|
125
125
|
BaseService._devices = [Device(device) for device in response_json['data']['device_list']]
|
|
@@ -164,7 +164,7 @@ class BaseService:
|
|
|
164
164
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/device/get_property_list",
|
|
165
165
|
json=payload)
|
|
166
166
|
|
|
167
|
-
check_for_errors_standard(response_json)
|
|
167
|
+
check_for_errors_standard(self, response_json)
|
|
168
168
|
properties = response_json['data']['property_list']
|
|
169
169
|
|
|
170
170
|
property_list = []
|
|
@@ -209,7 +209,7 @@ class BaseService:
|
|
|
209
209
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/device/set_property_list",
|
|
210
210
|
json=payload)
|
|
211
211
|
|
|
212
|
-
check_for_errors_standard(response_json)
|
|
212
|
+
check_for_errors_standard(self, response_json)
|
|
213
213
|
|
|
214
214
|
async def _run_action_list(self, device: Device, plist: List[Dict[Any, Any]]) -> None:
|
|
215
215
|
"""
|
|
@@ -250,7 +250,7 @@ class BaseService:
|
|
|
250
250
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/auto/run_action_list",
|
|
251
251
|
json=payload)
|
|
252
252
|
|
|
253
|
-
check_for_errors_standard(response_json)
|
|
253
|
+
check_for_errors_standard(self, response_json)
|
|
254
254
|
|
|
255
255
|
async def _get_event_list(self, count: int) -> Dict[Any, Any]:
|
|
256
256
|
"""
|
|
@@ -291,7 +291,7 @@ class BaseService:
|
|
|
291
291
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/device/get_event_list",
|
|
292
292
|
json=payload)
|
|
293
293
|
|
|
294
|
-
check_for_errors_standard(response_json)
|
|
294
|
+
check_for_errors_standard(self, response_json)
|
|
295
295
|
return response_json
|
|
296
296
|
|
|
297
297
|
async def _run_action(self, device: Device, action: str) -> None:
|
|
@@ -325,7 +325,7 @@ class BaseService:
|
|
|
325
325
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/auto/run_action",
|
|
326
326
|
json=payload)
|
|
327
327
|
|
|
328
|
-
check_for_errors_standard(response_json)
|
|
328
|
+
check_for_errors_standard(self, response_json)
|
|
329
329
|
|
|
330
330
|
async def _set_property(self, device: Device, pid: str, pvalue: str) -> None:
|
|
331
331
|
"""
|
|
@@ -356,7 +356,7 @@ class BaseService:
|
|
|
356
356
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/device/set_property",
|
|
357
357
|
json=payload)
|
|
358
358
|
|
|
359
|
-
check_for_errors_standard(response_json)
|
|
359
|
+
check_for_errors_standard(self, response_json)
|
|
360
360
|
|
|
361
361
|
async def _monitoring_profile_active(self, hms_id: str, home: int, away: int) -> None:
|
|
362
362
|
"""
|
|
@@ -393,7 +393,7 @@ class BaseService:
|
|
|
393
393
|
}
|
|
394
394
|
]
|
|
395
395
|
response_json = await self._auth_lib.patch(url, headers=headers, params=query, json=payload)
|
|
396
|
-
check_for_errors_hms(response_json)
|
|
396
|
+
check_for_errors_hms(self, response_json)
|
|
397
397
|
|
|
398
398
|
async def _get_plan_binding_list_by_user(self) -> Dict[Any, Any]:
|
|
399
399
|
"""
|
|
@@ -419,7 +419,7 @@ class BaseService:
|
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
response_json = await self._auth_lib.get(url, headers=headers, params=payload)
|
|
422
|
-
check_for_errors_hms(response_json)
|
|
422
|
+
check_for_errors_hms(self, response_json)
|
|
423
423
|
return response_json
|
|
424
424
|
|
|
425
425
|
async def _disable_reme_alarm(self, hms_id: str) -> None:
|
|
@@ -441,7 +441,7 @@ class BaseService:
|
|
|
441
441
|
|
|
442
442
|
response_json = await self._auth_lib.delete(url, headers=headers, json=payload)
|
|
443
443
|
|
|
444
|
-
check_for_errors_hms(response_json)
|
|
444
|
+
check_for_errors_hms(self, response_json)
|
|
445
445
|
|
|
446
446
|
async def _monitoring_profile_state_status(self, hms_id: str) -> Dict[Any, Any]:
|
|
447
447
|
"""
|
|
@@ -469,7 +469,7 @@ class BaseService:
|
|
|
469
469
|
|
|
470
470
|
response_json = await self._auth_lib.get(url, headers=headers, params=query)
|
|
471
471
|
|
|
472
|
-
check_for_errors_hms(response_json)
|
|
472
|
+
check_for_errors_hms(self, response_json)
|
|
473
473
|
return response_json
|
|
474
474
|
|
|
475
475
|
async def _lock_control(self, device: Device, action: str) -> None:
|
|
@@ -489,7 +489,7 @@ class BaseService:
|
|
|
489
489
|
|
|
490
490
|
response_json = await self._auth_lib.post(url, json=payload)
|
|
491
491
|
|
|
492
|
-
check_for_errors_lock(response_json)
|
|
492
|
+
check_for_errors_lock(self, response_json)
|
|
493
493
|
|
|
494
494
|
async def _get_lock_info(self, device: Device) -> Dict[str, Optional[Any]]:
|
|
495
495
|
await self._auth_lib.refresh_if_should()
|
|
@@ -509,7 +509,7 @@ class BaseService:
|
|
|
509
509
|
|
|
510
510
|
response_json = await self._auth_lib.get(url, params=payload)
|
|
511
511
|
|
|
512
|
-
check_for_errors_lock(response_json)
|
|
512
|
+
check_for_errors_lock(self, response_json)
|
|
513
513
|
|
|
514
514
|
return response_json
|
|
515
515
|
|
|
@@ -533,7 +533,7 @@ class BaseService:
|
|
|
533
533
|
response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/device/get_device_Info",
|
|
534
534
|
json=payload)
|
|
535
535
|
|
|
536
|
-
check_for_errors_standard(response_json)
|
|
536
|
+
check_for_errors_standard(self, response_json)
|
|
537
537
|
|
|
538
538
|
return response_json
|
|
539
539
|
|
|
@@ -554,7 +554,7 @@ class BaseService:
|
|
|
554
554
|
|
|
555
555
|
response_json = await self._auth_lib.get(url, headers=headers, params=payload)
|
|
556
556
|
|
|
557
|
-
check_for_errors_iot(response_json)
|
|
557
|
+
check_for_errors_iot(self, response_json)
|
|
558
558
|
|
|
559
559
|
return response_json
|
|
560
560
|
|
|
@@ -579,7 +579,7 @@ class BaseService:
|
|
|
579
579
|
|
|
580
580
|
response_json = await self._auth_lib.post(url, headers=headers, data=payload_str)
|
|
581
581
|
|
|
582
|
-
check_for_errors_iot(response_json)
|
|
582
|
+
check_for_errors_iot(self, response_json)
|
|
583
583
|
|
|
584
584
|
async def _local_bulb_command(self, bulb, plist):
|
|
585
585
|
# await self._auth_lib.refresh_if_should()
|
|
@@ -640,6 +640,6 @@ class BaseService:
|
|
|
640
640
|
"https://api.wyzecam.com/app/v2/plug/usage_record_list", json=payload
|
|
641
641
|
)
|
|
642
642
|
|
|
643
|
-
check_for_errors_standard(response_json)
|
|
643
|
+
check_for_errors_standard(self, response_json)
|
|
644
644
|
|
|
645
645
|
return response_json["data"]["usage_record_list"]
|
wyzeapy/utils.py
CHANGED
|
@@ -72,36 +72,42 @@ def create_password(password: str) -> str:
|
|
|
72
72
|
return hashlib.md5(hex2.encode()).hexdigest()
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def check_for_errors_standard(response_json: Dict[str, Any]) -> None:
|
|
75
|
+
def check_for_errors_standard(service, response_json: Dict[str, Any]) -> None:
|
|
76
76
|
if response_json['code'] != ResponseCodes.SUCCESS.value:
|
|
77
77
|
if response_json['code'] == ResponseCodes.PARAMETER_ERROR.value:
|
|
78
78
|
raise ParameterError(response_json)
|
|
79
79
|
elif response_json['code'] == ResponseCodes.ACCESS_TOKEN_ERROR.value:
|
|
80
|
-
|
|
80
|
+
service._auth_lib.token.expired = True
|
|
81
|
+
raise AccessTokenError("Access Token expired, attempting to refresh")
|
|
81
82
|
elif response_json['code'] == ResponseCodes.DEVICE_OFFLINE.value:
|
|
82
83
|
return
|
|
83
84
|
else:
|
|
84
85
|
raise UnknownApiError(response_json)
|
|
85
86
|
|
|
86
87
|
|
|
87
|
-
def check_for_errors_lock(response_json: Dict[str, Any]) -> None:
|
|
88
|
+
def check_for_errors_lock(service, response_json: Dict[str, Any]) -> None:
|
|
88
89
|
if response_json['ErrNo'] != 0:
|
|
89
90
|
if response_json.get('code') == ResponseCodes.PARAMETER_ERROR.value:
|
|
90
91
|
raise ParameterError
|
|
91
92
|
elif response_json.get('code') == ResponseCodes.ACCESS_TOKEN_ERROR.value:
|
|
92
|
-
|
|
93
|
+
service._auth_lib.token.expired = True
|
|
94
|
+
raise AccessTokenError("Access Token expired, attempting to refresh")
|
|
93
95
|
else:
|
|
94
96
|
raise UnknownApiError(response_json)
|
|
95
97
|
|
|
96
98
|
|
|
97
|
-
def check_for_errors_iot(response_json: Dict[Any, Any]) -> None:
|
|
99
|
+
def check_for_errors_iot(service, response_json: Dict[Any, Any]) -> None:
|
|
98
100
|
if response_json['code'] != 1:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
if str(response_json['code']) == ResponseCodes.ACCESS_TOKEN_ERROR.value:
|
|
102
|
+
service._auth_lib.token.expired = True
|
|
103
|
+
raise AccessTokenError("Access Token expired, attempting to refresh")
|
|
104
|
+
else:
|
|
105
|
+
raise UnknownApiError(response_json)
|
|
101
106
|
|
|
102
|
-
def check_for_errors_hms(response_json: Dict[Any, Any]) -> None:
|
|
107
|
+
def check_for_errors_hms(service, response_json: Dict[Any, Any]) -> None:
|
|
103
108
|
if response_json['message'] is None:
|
|
104
|
-
|
|
109
|
+
service._auth_lib.token.expired = True
|
|
110
|
+
raise AccessTokenError("Access Token expired, attempting to refresh")
|
|
105
111
|
|
|
106
112
|
|
|
107
113
|
def return_event_for_device(device: Device, events: List[Event]) -> Optional[Event]:
|
wyzeapy/wyze_auth_lib.py
CHANGED
|
@@ -22,12 +22,13 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class Token:
|
|
25
|
-
# Token is good for
|
|
26
|
-
REFRESH_INTERVAL =
|
|
25
|
+
# Token is apparently good for 24 hours, so refresh after 23
|
|
26
|
+
REFRESH_INTERVAL = 82800
|
|
27
27
|
|
|
28
28
|
def __init__(self, access_token, refresh_token, refresh_time: float = None):
|
|
29
29
|
self._access_token: str = access_token
|
|
30
30
|
self._refresh_token: str = refresh_token
|
|
31
|
+
self.expired = False
|
|
31
32
|
if refresh_time:
|
|
32
33
|
self._refresh_time: float = refresh_time
|
|
33
34
|
else:
|
|
@@ -206,9 +207,9 @@ class WyzeAuthLib:
|
|
|
206
207
|
return time.time() >= self.token.refresh_time
|
|
207
208
|
|
|
208
209
|
async def refresh_if_should(self):
|
|
209
|
-
if self.should_refresh:
|
|
210
|
+
if self.should_refresh or self.token.expired:
|
|
210
211
|
async with self.refresh_lock:
|
|
211
|
-
if self.should_refresh:
|
|
212
|
+
if self.should_refresh or self.token.expired:
|
|
212
213
|
_LOGGER.debug("Should refresh. Refreshing...")
|
|
213
214
|
await self.refresh()
|
|
214
215
|
|
|
@@ -233,11 +234,12 @@ class WyzeAuthLib:
|
|
|
233
234
|
response = await _session.post("https://api.wyzecam.com/app/user/refresh_token", headers=headers,
|
|
234
235
|
json=payload)
|
|
235
236
|
response_json = await response.json()
|
|
236
|
-
check_for_errors_standard(response_json)
|
|
237
|
+
check_for_errors_standard(self, response_json)
|
|
237
238
|
|
|
238
239
|
self.token.access_token = response_json['data']['access_token']
|
|
239
240
|
self.token.refresh_token = response_json['data']['refresh_token']
|
|
240
241
|
await self.token_callback(self.token)
|
|
242
|
+
self.token.expired = False
|
|
241
243
|
|
|
242
244
|
def sanitize(self, data):
|
|
243
245
|
if data and type(data) is dict:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
wyzeapy/__init__.py,sha256=
|
|
1
|
+
wyzeapy/__init__.py,sha256=GqTfzIPOJLdexQMtjvUsDR60oPB-rJGVSK_93FcCSuw,8918
|
|
2
2
|
wyzeapy/const.py,sha256=HqihFV6Hb9yZmUzxrhcrX93cJ2urvtCyUz9s8jP-IVU,989
|
|
3
3
|
wyzeapy/crypto.py,sha256=EI9WkKq4jS0nZS5CIEOSYD_9WtM7kEzrhqEg6YdPUIo,1342
|
|
4
4
|
wyzeapy/exceptions.py,sha256=4eBi7YRWafJlG5M7Cqr_swGKqBggm0Iomf5-Gv6ecgo,871
|
|
5
5
|
wyzeapy/payload_factory.py,sha256=bWRo-xMFfhtxzUcsYd2Eo56MqXmWYuDi8J865Uj_L0E,1920
|
|
6
6
|
wyzeapy/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
wyzeapy/services/base_service.py,sha256
|
|
7
|
+
wyzeapy/services/base_service.py,sha256=37747wJ9_Sy-rQzNetGYlJiGlnv4uWq7DqFCMveaIj8,23794
|
|
8
8
|
wyzeapy/services/bulb_service.py,sha256=n2Pvuunz5d7Iv275vDQjKxByowBDkVoVrztBLyDAOZE,6840
|
|
9
9
|
wyzeapy/services/camera_service.py,sha256=bkvd5Na-mh55xoR0CsTLTHI8685j5EoBKn1H_4mwBO8,5694
|
|
10
10
|
wyzeapy/services/hms_service.py,sha256=3Fhqlmk96dm8LFajjW6P40DCIYMudfN3YIDoVIonqGw,2459
|
|
@@ -15,9 +15,9 @@ wyzeapy/services/thermostat_service.py,sha256=3yJ8Jx7WPROTkiD2868QrfALFR1QB6_JI4
|
|
|
15
15
|
wyzeapy/services/update_manager.py,sha256=036ClmJMFzXjD03mfg5DIyjB3xwqHoWkmpU2tcquc5Q,6132
|
|
16
16
|
wyzeapy/services/wall_switch_service.py,sha256=1PmDyKh6WR8ZVVHsj9CAiIDOyG18D0wmH64U2XluT5I,4315
|
|
17
17
|
wyzeapy/types.py,sha256=rUjW2n21ArbxxRpFQGZ5pUIt4bb6JJAkTXElSFHXLiU,5828
|
|
18
|
-
wyzeapy/utils.py,sha256=
|
|
19
|
-
wyzeapy/wyze_auth_lib.py,sha256=
|
|
20
|
-
wyzeapy-0.5.
|
|
21
|
-
wyzeapy-0.5.
|
|
22
|
-
wyzeapy-0.5.
|
|
23
|
-
wyzeapy-0.5.
|
|
18
|
+
wyzeapy/utils.py,sha256=t2rktlOBXJ5O8YDwVkDwbEpBCwNA7TpiwVVeiDdpzu8,4267
|
|
19
|
+
wyzeapy/wyze_auth_lib.py,sha256=NWlWEMMNeEuCYLo7rxWd1EpJWPsP3huhJatfKTCkKm0,12713
|
|
20
|
+
wyzeapy-0.5.23.dist-info/LICENSES/GPL-3.0-only.txt,sha256=tqi_Y64slbCqJW7ndGgNe9GPIfRX2nVGb3YQs7FqzE4,34670
|
|
21
|
+
wyzeapy-0.5.23.dist-info/METADATA,sha256=0kXEypIc1o-__Yrfu0yj-MI_5-dUvGAUq5GxOWFy-5o,557
|
|
22
|
+
wyzeapy-0.5.23.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
23
|
+
wyzeapy-0.5.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|