homebridge-kasa-python 2.5.14 → 2.5.15
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 +10 -6
- 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
|
|
4
|
+
from kasa import Discover, Device, UnsupportedDeviceException
|
|
5
5
|
from loguru import logger
|
|
6
6
|
|
|
7
7
|
app = Flask(__name__)
|
|
@@ -52,7 +52,6 @@ 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
|
|
56
55
|
|
|
57
56
|
def on_unsupported(ip):
|
|
58
57
|
app.logger.warning(f"Unsupported device found: {ip}")
|
|
@@ -60,12 +59,13 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
|
|
|
60
59
|
for broadcast in broadcasts:
|
|
61
60
|
try:
|
|
62
61
|
app.logger.debug(f"Starting discovery on broadcast: {broadcast}")
|
|
63
|
-
if
|
|
62
|
+
if username is not None and password is not None:
|
|
64
63
|
app.logger.debug(f"Using credentials for discovery on broadcast: {broadcast}")
|
|
65
64
|
try:
|
|
66
65
|
discovered_devices = await Discover.discover(
|
|
67
66
|
target=broadcast,
|
|
68
|
-
|
|
67
|
+
username=username,
|
|
68
|
+
password=password,
|
|
69
69
|
on_unsupported=lambda device: on_unsupported(device.host)
|
|
70
70
|
)
|
|
71
71
|
except Exception as e:
|
|
@@ -102,8 +102,12 @@ async def discover_devices(username=None, password=None, additional_broadcasts=N
|
|
|
102
102
|
app.logger.debug(f"Manual device {host} already exists in devices, skipping.")
|
|
103
103
|
continue
|
|
104
104
|
try:
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
if username is not None and password is not None:
|
|
106
|
+
app.logger.debug(f"Discovering manual device with credentials: {host}")
|
|
107
|
+
discovered_device = await Discover.discover_single(host=host, username=username, password=password)
|
|
108
|
+
else:
|
|
109
|
+
app.logger.debug(f"Discovering manual device without credentials: {host}")
|
|
110
|
+
discovered_device = await Discover.discover_single(host=host)
|
|
107
111
|
if discovered_device:
|
|
108
112
|
if hasattr(discovered_device, 'device_type'):
|
|
109
113
|
devices[host] = discovered_device
|
package/package.json
CHANGED