refactor(led-driver): simplify websocket runtime and test layout
This commit is contained in:
@@ -15,7 +15,7 @@ Deploy src to the device (including utils.py with mdns_hostname), then from the
|
||||
|
||||
mpremote connect PORT run tests/test_mdns.py
|
||||
|
||||
If ImportError: copy utils.py from src/ to the device, or rely on the built-in fallback below.
|
||||
Copy ``utils.py`` from ``src/`` onto the device if imports fail.
|
||||
|
||||
Or with cwd led-driver:
|
||||
|
||||
@@ -30,26 +30,7 @@ import utime
|
||||
from machine import WDT
|
||||
|
||||
from settings import Settings
|
||||
|
||||
try:
|
||||
from utils import mdns_hostname
|
||||
except ImportError:
|
||||
|
||||
def mdns_hostname(settings):
|
||||
"""Same as utils.mdns_hostname (fallback if device utils.py is older than host repo)."""
|
||||
raw = settings.get("name") or "led"
|
||||
suffix = []
|
||||
for c in str(raw).lower():
|
||||
o = ord(c)
|
||||
if (48 <= o <= 57) or (97 <= o <= 122):
|
||||
suffix.append(c)
|
||||
s = "".join(suffix)
|
||||
if not s:
|
||||
s = "device"
|
||||
h = "led" + s
|
||||
if len(h) > 32:
|
||||
h = h[:32]
|
||||
return h
|
||||
from utils import mdns_hostname
|
||||
|
||||
CONNECT_TIMEOUT_S = 45
|
||||
# ESP32 MicroPython WDT timeout is capped (typically 10000 ms). Longer blocking work
|
||||
@@ -213,16 +194,6 @@ def main():
|
||||
"Set SELF_LOCAL_GETADDRINFO = True to attempt (may hang)."
|
||||
)
|
||||
|
||||
# Optional: built-in mdns module (not present on all ESP32 builds)
|
||||
_dbg(t0, "checking for optional 'mdns' module")
|
||||
try:
|
||||
import mdns # noqa: F401
|
||||
|
||||
print("Note: 'mdns' module is present; check your port's docs for Server/API.")
|
||||
except ImportError:
|
||||
print("No top-level 'mdns' module; relying on stack mDNS from hostname.")
|
||||
_dbg(t0, "mdns import check done")
|
||||
|
||||
if HOLD_S != 0:
|
||||
forever = HOLD_S < 0
|
||||
_dbg(
|
||||
|
||||
Reference in New Issue
Block a user