homebridge-kasa-python 2.5.15 → 2.5.16
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 +11 -9
- package/package.json +1 -1
package/dist/python/kasaApi.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
-
from kasa import Discover, Device, UnsupportedDeviceException
|
|
4
|
+
from kasa import Credentials, Discover, Device, UnsupportedDeviceException
|
|
5
5
|
from loguru import logger
|
|
6
6
|
|
|
7
7
|
app = Flask(__name__)
|
|
@@ -52,6 +52,7 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
|
|
|
52
52
|
app.logger.debug("Starting device discovery")
|
|
53
53
|
devices = {}
|
|
54
54
|
broadcasts = ["255.255.255.255"] + (additional_broadcasts or [])
|
|
55
|
+
creds = Credentials(username, password) if username and password else None
|
|
55
56
|
|
|
56
57
|
def on_unsupported(ip):
|
|
57
58
|
app.logger.warning(f"Unsupported device found: {ip}")
|
|
@@ -59,13 +60,12 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
|
|
|
59
60
|
for broadcast in broadcasts:
|
|
60
61
|
try:
|
|
61
62
|
app.logger.debug(f"Starting discovery on broadcast: {broadcast}")
|
|
62
|
-
if
|
|
63
|
+
if creds is not None:
|
|
63
64
|
app.logger.debug(f"Using credentials for discovery on broadcast: {broadcast}")
|
|
64
65
|
try:
|
|
65
66
|
discovered_devices = await Discover.discover(
|
|
66
67
|
target=broadcast,
|
|
67
|
-
|
|
68
|
-
password=password,
|
|
68
|
+
credentials=creds,
|
|
69
69
|
on_unsupported=lambda device: on_unsupported(device.host)
|
|
70
70
|
)
|
|
71
71
|
except Exception as e:
|
|
@@ -86,7 +86,8 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
|
|
|
86
86
|
|
|
87
87
|
for ip, dev in discovered_devices.items():
|
|
88
88
|
app.logger.debug(f"Processing device {ip}")
|
|
89
|
-
|
|
89
|
+
device_type = getattr(dev, 'device_type', None)
|
|
90
|
+
if device_type:
|
|
90
91
|
devices[ip] = dev
|
|
91
92
|
app.logger.debug(f"Added device {ip} with device type {dev.device_type} from broadcast {broadcast} to devices list")
|
|
92
93
|
else:
|
|
@@ -102,16 +103,17 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
|
|
|
102
103
|
app.logger.debug(f"Manual device {host} already exists in devices, skipping.")
|
|
103
104
|
continue
|
|
104
105
|
try:
|
|
105
|
-
if
|
|
106
|
+
if creds is not None:
|
|
106
107
|
app.logger.debug(f"Discovering manual device with credentials: {host}")
|
|
107
|
-
discovered_device = await Discover.discover_single(host=host,
|
|
108
|
+
discovered_device = await Discover.discover_single(host=host, credentials=creds)
|
|
108
109
|
else:
|
|
109
110
|
app.logger.debug(f"Discovering manual device without credentials: {host}")
|
|
110
111
|
discovered_device = await Discover.discover_single(host=host)
|
|
111
112
|
if discovered_device:
|
|
112
|
-
|
|
113
|
+
device_type = getattr(dev, 'device_type', None)
|
|
114
|
+
if device_type:
|
|
113
115
|
devices[host] = discovered_device
|
|
114
|
-
app.logger.debug(f"Discovered manual device: {host}")
|
|
116
|
+
app.logger.debug(f"Discovered manual device: {host} with device type {dev.device_type}")
|
|
115
117
|
else:
|
|
116
118
|
app.logger.warning(f"Manual device {host} is missing device_type and was not added")
|
|
117
119
|
else:
|
package/package.json
CHANGED