From 7bd62ab9832395ffaaffe11d4d188f2d6bfc57c2 Mon Sep 17 00:00:00 2001 From: Andrei Smaliak Date: Tue, 21 Apr 2026 20:29:36 +0400 Subject: [PATCH] spinners_mqtt_contract_version 2.2.5 --- stage_ui/console_core/backend/app.py | 2 +- .../backend/itscreen_registration.py | 69 +++++++++++++------ stage_ui/console_core/frontend/console.js | 2 +- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/stage_ui/console_core/backend/app.py b/stage_ui/console_core/backend/app.py index fe98572..e940a39 100644 --- a/stage_ui/console_core/backend/app.py +++ b/stage_ui/console_core/backend/app.py @@ -39,7 +39,7 @@ APP_DIR = "/opt/iomatex-console" PUBLIC_DIR = os.path.join(APP_DIR, "public") PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d") CONFIG_PATH = "/etc/iomatex/console.json" -UI_VERSION = "V 2.2.4" +UI_VERSION = "V 2.2.5" DEFAULT_CONFIG = { "bind": "0.0.0.0", diff --git a/stage_ui/console_core/backend/itscreen_registration.py b/stage_ui/console_core/backend/itscreen_registration.py index 41aa5b4..1ad47f5 100644 --- a/stage_ui/console_core/backend/itscreen_registration.py +++ b/stage_ui/console_core/backend/itscreen_registration.py @@ -304,6 +304,25 @@ def _load_registration_from_itscreen_config(device_id, persisted=None): return _normalize_registration_payload(payload, persisted=persisted, source="config", contract_meta=contract_meta) +def _candidate_login_passwords(device_id, persisted=None): + candidates = [] + seen = set() + + def add(value): + text = _truncate_empty(value) + if not text or text in seen: + return + seen.add(text) + candidates.append(text) + + persisted = persisted or {} + add((persisted or {}).get("password")) + config_payload = _load_registration_from_itscreen_config(device_id, persisted=persisted) + add(config_payload.get("password")) + add(LOGIN_PASSWORD) + return candidates + + def _extract_response_payload(response_text): raw = str(response_text or "").strip() if not raw: @@ -569,25 +588,33 @@ class MqttSettingsSession: return candidate raise TimeoutError("No response from device") - def login(self): - self.publish({"action": "login", "password": LOGIN_PASSWORD}) - deadline = time.time() + 1.0 - while time.time() < deadline: - try: - candidate = self.queue.get(timeout=0.1) - except queue.Empty: - continue - if isinstance(candidate, dict) and candidate.get("__invalid_json__") is not None: - raise RuntimeError("Invalid MQTT payload") - if not isinstance(candidate, dict): - continue - if candidate.get("action") != "login": - continue - if candidate.get("result") is False: - raise RuntimeError(candidate.get("note") or candidate.get("error") or "Login failed") - if candidate.get("result") is True: - return True - return True + def login(self, password_candidates=None): + passwords = [value for value in (password_candidates or []) if _truncate_empty(value)] + if not passwords: + passwords = [LOGIN_PASSWORD] + last_error = None + for password in passwords: + self.publish({"action": "login", "password": password}) + deadline = time.time() + 2.0 + while time.time() < deadline: + try: + candidate = self.queue.get(timeout=0.1) + except queue.Empty: + continue + if isinstance(candidate, dict) and candidate.get("__invalid_json__") is not None: + raise RuntimeError("Invalid MQTT payload") + if not isinstance(candidate, dict): + continue + if candidate.get("action") != "login": + continue + if candidate.get("result") is False: + last_error = candidate.get("note") or candidate.get("error") or "Login failed" + break + if candidate.get("result") is True: + return True + else: + last_error = "Login response timeout" + raise RuntimeError(last_error or "Login failed") def get_server_state(self): return self.publish_and_wait( @@ -719,7 +746,7 @@ def get_registration_status(): state = dict(persisted) try: def _status_flow(session, _contract_meta): - session.login() + session.login(_candidate_login_passwords(state["device_id"], persisted)) server_state = session.get_server_state() device_state = _read_device_registration_snapshot( session, @@ -810,7 +837,7 @@ def register_device(host): try: def _register_flow(session, contract_meta): - session.login() + session.login(_candidate_login_passwords(working["device_id"], persisted)) current_server_state = session.get_server_state() if _bool_value((current_server_state or {}).get("registered"), default=False): raise RuntimeError("Device is already registered") diff --git a/stage_ui/console_core/frontend/console.js b/stage_ui/console_core/frontend/console.js index 7e58434..c3d7a97 100644 --- a/stage_ui/console_core/frontend/console.js +++ b/stage_ui/console_core/frontend/console.js @@ -43,7 +43,7 @@ { mode: "test_by", label: "TEST BY", host: "rest.test.it-screen.by" }, { mode: "custom", label: "Custom", host: "" } ]; - const UI_VERSION = "V 2.2.4"; + const UI_VERSION = "V 2.2.5"; const ITSCREEN_LOG_INITIAL_LINES = 50; const ITSCREEN_LOG_BUFFER_LIMIT = 300; const ITSCREEN_LOG_BATCH_MS = 250;