python-aidot 0.3.41__tar.gz → 0.3.42__tar.gz
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.
- {python_aidot-0.3.41 → python_aidot-0.3.42}/PKG-INFO +1 -1
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/client.py +6 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/device_client.py +85 -38
- {python_aidot-0.3.41 → python_aidot-0.3.42}/python_aidot.egg-info/PKG-INFO +1 -1
- {python_aidot-0.3.41 → python_aidot-0.3.42}/setup.py +1 -1
- {python_aidot-0.3.41 → python_aidot-0.3.42}/LICENSE +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/README.md +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/__init__.py +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/aes_utils.py +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/const.py +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/discover.py +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/exceptions.py +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/aidot/login_const.py +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/python_aidot.egg-info/SOURCES.txt +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/python_aidot.egg-info/dependency_links.txt +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/python_aidot.egg-info/requires.txt +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/python_aidot.egg-info/top_level.txt +0 -0
- {python_aidot-0.3.41 → python_aidot-0.3.42}/setup.cfg +0 -0
|
@@ -235,6 +235,12 @@ class AidotClient:
|
|
|
235
235
|
device_client.update_ip_address(ip)
|
|
236
236
|
return device_client
|
|
237
237
|
|
|
238
|
+
async def remove_device_client(self, dev_id: str) -> None:
|
|
239
|
+
device_client: DeviceClient = self._device_clients.get(dev_id)
|
|
240
|
+
if device_client is not None:
|
|
241
|
+
await device_client.close()
|
|
242
|
+
del self._device_clients[dev_id]
|
|
243
|
+
|
|
238
244
|
def start_discover(self) -> None:
|
|
239
245
|
if self._discover is not None:
|
|
240
246
|
return
|
|
@@ -102,10 +102,10 @@ class DeviceClient(object):
|
|
|
102
102
|
_connect_and_login: bool = False
|
|
103
103
|
_connecting: bool = False
|
|
104
104
|
_simpleVersion: str = ""
|
|
105
|
-
_ip_address: str
|
|
105
|
+
_ip_address: str = None
|
|
106
106
|
device_id: str
|
|
107
107
|
_is_close: bool = False
|
|
108
|
-
|
|
108
|
+
_status_fresh_cb: Any = None
|
|
109
109
|
@property
|
|
110
110
|
def connect_and_login(self) -> bool:
|
|
111
111
|
return self._connect_and_login
|
|
@@ -132,6 +132,7 @@ class DeviceClient(object):
|
|
|
132
132
|
self._simpleVersion = device.get("simpleVersion")
|
|
133
133
|
|
|
134
134
|
async def connect(self, ip_address) -> None:
|
|
135
|
+
_LOGGER.info(f"connect device : {ip_address}")
|
|
135
136
|
self.reader = self.writer = None
|
|
136
137
|
self._connecting = True
|
|
137
138
|
try:
|
|
@@ -147,8 +148,12 @@ class DeviceClient(object):
|
|
|
147
148
|
self._connecting = False
|
|
148
149
|
|
|
149
150
|
def update_ip_address(self, ip: str) -> None:
|
|
151
|
+
if ip is None:
|
|
152
|
+
return
|
|
150
153
|
self._ip_address = ip
|
|
151
|
-
|
|
154
|
+
if self._connecting is not True and self._connect_and_login is not True:
|
|
155
|
+
asyncio.get_running_loop().create_task(self.async_login())
|
|
156
|
+
|
|
152
157
|
async def async_login(self) -> None:
|
|
153
158
|
if self._ip_address is None:
|
|
154
159
|
return
|
|
@@ -211,44 +216,84 @@ class DeviceClient(object):
|
|
|
211
216
|
self.ascNumber = json_data[CONF_PAYLOAD][CONF_ASCNUMBER]
|
|
212
217
|
self.ascNumber += 1
|
|
213
218
|
self.status.online = True
|
|
219
|
+
asyncio.get_running_loop().create_task(self.reveive_data())
|
|
214
220
|
await self.send_action({}, "getDevAttrReq")
|
|
215
221
|
|
|
222
|
+
async def reveive_data(self) -> None:
|
|
223
|
+
while True:
|
|
224
|
+
try:
|
|
225
|
+
data = await self.reader.read(1024)
|
|
226
|
+
except (BrokenPipeError, ConnectionResetError) as e:
|
|
227
|
+
_LOGGER.error(f"{self.device_id} read status error {e}")
|
|
228
|
+
await self.reset()
|
|
229
|
+
self.status.online = False
|
|
230
|
+
return
|
|
231
|
+
except Exception as e:
|
|
232
|
+
_LOGGER.error(f"recv data error {e}")
|
|
233
|
+
return
|
|
234
|
+
data_len = len(data)
|
|
235
|
+
if data_len <= 0:
|
|
236
|
+
_LOGGER.error("recv data error len, exit socket")
|
|
237
|
+
await self.reset()
|
|
238
|
+
self.status.online = False
|
|
239
|
+
return
|
|
240
|
+
try:
|
|
241
|
+
magic, msgtype, bodysize = struct.unpack(">HHI", data[:8])
|
|
242
|
+
decrypted_data = aes_decrypt(data[8:], self.aes_key)
|
|
243
|
+
json_data = json.loads(decrypted_data)
|
|
244
|
+
except Exception as e:
|
|
245
|
+
_LOGGER.error(f"recv json error : {e}")
|
|
246
|
+
|
|
247
|
+
if "service" in json_data:
|
|
248
|
+
if "test" == json_data["service"]:
|
|
249
|
+
self.ping_count = 0
|
|
250
|
+
continue
|
|
251
|
+
|
|
252
|
+
payload = json_data.get(CONF_PAYLOAD)
|
|
253
|
+
if payload is not None:
|
|
254
|
+
self.ascNumber = payload.get(CONF_ASCNUMBER)
|
|
255
|
+
self.status.update(payload.get(CONF_ATTR))
|
|
256
|
+
# _LOGGER.info(f"recv status : {payload}")
|
|
257
|
+
if self._status_fresh_cb:
|
|
258
|
+
self._status_fresh_cb(self.status)
|
|
259
|
+
def set_status_fresh_cb(self, callback) -> None:
|
|
260
|
+
self._status_fresh_cb = callback
|
|
216
261
|
async def read_status(self) -> DeviceStatusData:
|
|
217
|
-
if self._connect_and_login is False:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
try:
|
|
221
|
-
|
|
222
|
-
except (BrokenPipeError, ConnectionResetError) as e:
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
except Exception as e:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
data_len = len(data)
|
|
231
|
-
if data_len <= 0:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
try:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
except Exception as e:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if "service" in json_data:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
payload = json_data.get(CONF_PAYLOAD)
|
|
249
|
-
if payload is not None:
|
|
250
|
-
|
|
251
|
-
|
|
262
|
+
# if self._connect_and_login is False:
|
|
263
|
+
# await asyncio.sleep(2)
|
|
264
|
+
# raise AidotNotLogin
|
|
265
|
+
# try:
|
|
266
|
+
# data = await self.reader.read(1024)
|
|
267
|
+
# except (BrokenPipeError, ConnectionResetError) as e:
|
|
268
|
+
# _LOGGER.error(f"{self.device_id} read status error {e}")
|
|
269
|
+
# await self.reset()
|
|
270
|
+
# self.status.online = False
|
|
271
|
+
# return self.status
|
|
272
|
+
# except Exception as e:
|
|
273
|
+
# _LOGGER.error(f"recv data error {e}")
|
|
274
|
+
# return self.status
|
|
275
|
+
# data_len = len(data)
|
|
276
|
+
# if data_len <= 0:
|
|
277
|
+
# _LOGGER.error("recv data error len")
|
|
278
|
+
# await self.reset()
|
|
279
|
+
# self.status.online = False
|
|
280
|
+
# return self.status
|
|
281
|
+
# try:
|
|
282
|
+
# magic, msgtype, bodysize = struct.unpack(">HHI", data[:8])
|
|
283
|
+
# decrypted_data = aes_decrypt(data[8:], self.aes_key)
|
|
284
|
+
# json_data = json.loads(decrypted_data)
|
|
285
|
+
# except Exception as e:
|
|
286
|
+
# _LOGGER.error(f"recv json error : {e}")
|
|
287
|
+
# return await self.read_status()
|
|
288
|
+
|
|
289
|
+
# if "service" in json_data:
|
|
290
|
+
# if "test" == json_data["service"]:
|
|
291
|
+
# self.ping_count = 0
|
|
292
|
+
# return await self.read_status()
|
|
293
|
+
# payload = json_data.get(CONF_PAYLOAD)
|
|
294
|
+
# if payload is not None:
|
|
295
|
+
# self.ascNumber = payload.get(CONF_ASCNUMBER)
|
|
296
|
+
# self.status.update(payload.get(CONF_ATTR))
|
|
252
297
|
return self.status
|
|
253
298
|
|
|
254
299
|
async def ping_task(self) -> None:
|
|
@@ -260,6 +305,8 @@ class DeviceClient(object):
|
|
|
260
305
|
await asyncio.sleep(5)
|
|
261
306
|
|
|
262
307
|
async def send_dev_attr(self, dev_attr) -> None:
|
|
308
|
+
if not self._connect_and_login:
|
|
309
|
+
raise ConnectionError('Device offline')
|
|
263
310
|
await self.send_action(dev_attr, "setDevAttrReq")
|
|
264
311
|
|
|
265
312
|
async def async_turn_off(self) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|