homebridge-kasa-python 2.5.11 → 2.5.13

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.
@@ -1,4 +1,4 @@
1
- import asyncio, eventlet, eventlet.wsgi, json, os, requests, sys
1
+ import asyncio, eventlet, eventlet.wsgi, json, os, requests, sys, traceback
2
2
  from flask import Flask, request, jsonify
3
3
  from flask_socketio import SocketIO
4
4
  from kasa import Credentials, Discover, Device, UnsupportedDeviceException
@@ -54,14 +54,38 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
54
54
  broadcasts = ["255.255.255.255"] + (additional_broadcasts or [])
55
55
  creds = Credentials(username, password) if username and password else None
56
56
 
57
- def on_unsupported(ip, dev):
58
- app.logger.warning(f"Unsupported device found: {ip} - {dev}")
57
+ def on_unsupported(ip):
58
+ app.logger.warning(f"Unsupported device found: {ip}")
59
59
 
60
60
  for broadcast in broadcasts:
61
61
  try:
62
- app.logger.debug(f"Discovering devices on broadcast: {broadcast}")
63
- discovered_devices = await Discover.discover(target=broadcast, credentials=creds, on_unsupported=on_unsupported)
62
+ app.logger.debug(f"Starting discovery on broadcast: {broadcast}")
63
+ if creds is not None:
64
+ app.logger.debug(f"Using credentials for discovery on broadcast: {broadcast}")
65
+ try:
66
+ discovered_devices = await Discover.discover(
67
+ target=broadcast,
68
+ credentials=creds,
69
+ on_unsupported=lambda device: on_unsupported(device.host)
70
+ )
71
+ except Exception as e:
72
+ app.logger.error(f"Error during discovery with credentials on broadcast {broadcast}: {str(e)}", exc_info=True)
73
+ app.logger.debug(f"Exception details: {traceback.format_exc()}")
74
+ continue
75
+ else:
76
+ app.logger.debug(f"Discovering without credentials on broadcast: {broadcast}")
77
+ try:
78
+ discovered_devices = await Discover.discover(
79
+ target=broadcast,
80
+ on_unsupported=lambda device: on_unsupported(device.host)
81
+ )
82
+ except Exception as e:
83
+ app.logger.error(f"Error during discovery without credentials on broadcast {broadcast}: {str(e)}", exc_info=True)
84
+ app.logger.debug(f"Exception details: {traceback.format_exc()}")
85
+ continue
86
+
64
87
  for ip, dev in discovered_devices.items():
88
+ app.logger.debug(f"Processing device {ip}")
65
89
  if hasattr(dev, 'device_type'):
66
90
  devices[ip] = dev
67
91
  app.logger.debug(f"Added device {ip} with device type {dev.device_type} from broadcast {broadcast} to devices list")
@@ -69,7 +93,8 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
69
93
  app.logger.debug(f"Device {ip} from broadcast {broadcast} does not have a device_type and was not added")
70
94
  app.logger.debug(f"Discovered {len(discovered_devices)} devices on broadcast {broadcast}")
71
95
  except Exception as e:
72
- app.logger.error(f"Error discovering devices on broadcast {broadcast}: {str(e)}")
96
+ app.logger.error(f"Error processing broadcast {broadcast}: {str(e)}", exc_info=True)
97
+ app.logger.debug(f"Exception details: {traceback.format_exc()}")
73
98
 
74
99
  if manual_devices:
75
100
  for host in manual_devices:
@@ -181,8 +206,8 @@ def run_async(func, *args):
181
206
  @app.route('/discover', methods=['POST'])
182
207
  def discover():
183
208
  auth = request.authorization
184
- username = auth.username if auth else None
185
- password = auth.password if auth else None
209
+ username = f"'{auth.username}'" if auth else None
210
+ password = f"'{auth.password}'" if auth else None
186
211
  additional_broadcasts = request.json.get('additionalBroadcasts', [])
187
212
  manual_devices = request.json.get('manualDevices', [])
188
213
  app.logger.debug(f"Starting device discovery with additionalBroadcasts: {additional_broadcasts} and manualDevices: {manual_devices}")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge Kasa Python",
3
3
  "name": "homebridge-kasa-python",
4
- "version": "2.5.11",
4
+ "version": "2.5.13",
5
5
  "description": "Plugin that uses Python-Kasa API to communicate with Kasa Devices.",
6
6
  "license": "MIT",
7
7
  "type": "module",