Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diagnose and run diagnostics when log level is DEBUG #122

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
from paho.mqtt import client as mqtt_client
from TheengsDecoder import decodeBLE

from .diagnose import diagnostics

if platform.system() == "Linux":
from bleak.assigned_numbers import AdvertisementDataType
from bleak.backends.bluezdbus.advertisement_monitor import OrPattern
Expand Down Expand Up @@ -434,6 +436,9 @@ def run(arg):
logger.setLevel(log_level)

loop = asyncio.get_event_loop()

if log_level == logging.DEBUG:
asyncio.run(diagnostics())
thread = Thread(target=loop.run_forever, daemon=True)
thread.start()
asyncio.run_coroutine_threadsafe(gw.ble_scan_loop(), loop)
Expand Down
4 changes: 3 additions & 1 deletion TheengsGateway/diagnose.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _os() -> None:
"Version": platform.version(),
"Machine type": platform.machine(),
}
if platform.system() == "Linux":
if platform.system() == "Linux" and sys.version_info[:2] >= (3, 10):
os_parameters["Distribution"] = platform.freedesktop_os_release()[
"PRETTY_NAME"
]
Expand All @@ -117,7 +117,9 @@ def _config() -> None:
config = json.load(config_file)
_anonymize_strings(["user", "pass"], config)
_anonymize_addresses("time_sync", config)
print("```")
print(json.dumps(config, sort_keys=True, indent=4))
print("```")
print()
except FileNotFoundError:
print(f"Configuration file not found: {_conf_path}")
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'bluetooth-adapters>=0.15.3; python_version>="3.9"',
"bluetooth-clocks<1.0",
"bluetooth-numbers>=1.0,<2.0",
"importlib-metadata",
"paho-mqtt>=1.6.1",
"TheengsDecoder>=1.3.0",
],
Expand Down