homebridge-kasa-python 2.1.2 → 2.1.3
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.
- package/dist/python/kasaApi.py +42 -17
- package/package.json +1 -1
package/dist/python/kasaApi.py
CHANGED
|
@@ -16,37 +16,62 @@ def custom_device_serializer(device):
|
|
|
16
16
|
except TypeError:
|
|
17
17
|
return False
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
serialized_data = {}
|
|
20
|
+
for attr in dir(device):
|
|
21
|
+
if not attr.startswith("_") and not callable(getattr(device, attr)) and not asyncio.iscoroutine(getattr(device, attr)):
|
|
22
|
+
value = getattr(device, attr)
|
|
23
|
+
if is_serializable(value):
|
|
24
|
+
serialized_data[attr] = value
|
|
25
|
+
else:
|
|
26
|
+
app.logger.debug(f"Skipping non-serializable attribute: {attr} with value: {value}")
|
|
27
|
+
app.logger.debug(f"Serialized data for device: {serialized_data}")
|
|
28
|
+
return serialized_data
|
|
23
29
|
|
|
24
30
|
async def discover_devices():
|
|
25
31
|
app.logger.debug('Starting device discovery...')
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
try:
|
|
33
|
+
devices = await Discover.discover()
|
|
34
|
+
app.logger.debug(f'Discovered devices: {devices}')
|
|
35
|
+
except Exception as e:
|
|
36
|
+
app.logger.error(f'Error during device discovery: {str(e)}')
|
|
37
|
+
return {}
|
|
38
|
+
|
|
28
39
|
all_device_info = {}
|
|
29
40
|
tasks = []
|
|
30
41
|
for ip, dev in devices.items():
|
|
31
|
-
app.logger.debug(f'Creating update task for device at {ip}')
|
|
42
|
+
app.logger.debug(f'Creating update task for device at {ip} with device: {dev}')
|
|
32
43
|
tasks.append(update_device_info(ip, dev))
|
|
33
|
-
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
results = await asyncio.gather(*tasks)
|
|
47
|
+
app.logger.debug(f'Update tasks completed with results: {results}')
|
|
48
|
+
except Exception as e:
|
|
49
|
+
app.logger.error(f'Error during update tasks: {str(e)}')
|
|
50
|
+
return {}
|
|
51
|
+
|
|
34
52
|
for ip, info in results:
|
|
35
53
|
all_device_info[ip] = info
|
|
54
|
+
app.logger.debug(f'Updated device info for {ip}: {info}')
|
|
55
|
+
|
|
36
56
|
app.logger.debug(f'All device info: {all_device_info}')
|
|
37
57
|
return all_device_info
|
|
38
58
|
|
|
39
59
|
async def update_device_info(ip, dev: Device):
|
|
40
60
|
app.logger.debug(f'Updating device info for {ip}')
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
try:
|
|
62
|
+
await dev.update()
|
|
63
|
+
app.logger.debug(f'Device updated for {ip}: {dev}')
|
|
64
|
+
device_info = custom_device_serializer(dev)
|
|
65
|
+
device_config = dev.config.to_dict()
|
|
66
|
+
device_cache[ip] = {
|
|
67
|
+
"device_info": device_info,
|
|
68
|
+
"device_config": device_config
|
|
69
|
+
}
|
|
70
|
+
app.logger.debug(f'Updated device info for {ip}: {device_cache[ip]}')
|
|
71
|
+
return ip, device_cache[ip]
|
|
72
|
+
except Exception as e:
|
|
73
|
+
app.logger.error(f'Error updating device info for {ip}: {str(e)}')
|
|
74
|
+
return ip, {}
|
|
50
75
|
|
|
51
76
|
async def get_device_info(device_config):
|
|
52
77
|
app.logger.debug(f'Getting device info for config: {device_config}')
|
package/package.json
CHANGED