|
@@ -1,4 +1,5 @@
|
|
|
import subprocess
|
|
import subprocess
|
|
|
|
|
+import logging
|
|
|
import re
|
|
import re
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
from pydantic import BaseModel
|
|
@@ -64,9 +65,17 @@ class KDEConnect:
|
|
|
command: list[str] = ["kdeconnect-cli"]
|
|
command: list[str] = ["kdeconnect-cli"]
|
|
|
command.extend(args)
|
|
command.extend(args)
|
|
|
process: CompletedProcess = subprocess.run(command, capture_output=True)
|
|
process: CompletedProcess = subprocess.run(command, capture_output=True)
|
|
|
|
|
+
|
|
|
|
|
+ subprocess_response = process.stdout.decode("utf-8")
|
|
|
|
|
+ logging.debug("Subprocess call : \n>> " + " ".join(command) + "\n" + subprocess_response)
|
|
|
if process.stderr != b"":
|
|
if process.stderr != b"":
|
|
|
- print(f"[Err] {process.stderr.decode('utf-8')}")
|
|
|
|
|
- return process.stdout.decode("utf-8")
|
|
|
|
|
|
|
+ error_msg: str = process.stderr.decode("utf-8")
|
|
|
|
|
+ if error_msg.endswith("devices found\n"):
|
|
|
|
|
+ logging.info(error_msg)
|
|
|
|
|
+ else:
|
|
|
|
|
+ raise KDEConnectError(error_msg)
|
|
|
|
|
+
|
|
|
|
|
+ return subprocess_response
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def get_device_list() -> list[KDEDevice]:
|
|
def get_device_list() -> list[KDEDevice]:
|
|
@@ -75,6 +84,8 @@ class KDEConnect:
|
|
|
output: list[KDEDevice] = []
|
|
output: list[KDEDevice] = []
|
|
|
device_entries: list[str] = KDEConnect.run_kde_command(["-l"]).strip().split("\n")
|
|
device_entries: list[str] = KDEConnect.run_kde_command(["-l"]).strip().split("\n")
|
|
|
for device_str in device_entries:
|
|
for device_str in device_entries:
|
|
|
|
|
+ if device_str == "":
|
|
|
|
|
+ continue
|
|
|
result = re.search("^- ([^:]+): ([a-z0-9_]{36})", device_str)
|
|
result = re.search("^- ([^:]+): ([a-z0-9_]{36})", device_str)
|
|
|
reachable = "reachable" in device_str
|
|
reachable = "reachable" in device_str
|
|
|
paired = "paired" in device_str
|
|
paired = "paired" in device_str
|