spinners_mqtt_contract_version 2.2.5
This commit is contained in:
parent
ed7da84306
commit
7bd62ab983
|
|
@ -39,7 +39,7 @@ APP_DIR = "/opt/iomatex-console"
|
||||||
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
||||||
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
||||||
CONFIG_PATH = "/etc/iomatex/console.json"
|
CONFIG_PATH = "/etc/iomatex/console.json"
|
||||||
UI_VERSION = "V 2.2.4"
|
UI_VERSION = "V 2.2.5"
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
"bind": "0.0.0.0",
|
"bind": "0.0.0.0",
|
||||||
|
|
|
||||||
|
|
@ -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)
|
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):
|
def _extract_response_payload(response_text):
|
||||||
raw = str(response_text or "").strip()
|
raw = str(response_text or "").strip()
|
||||||
if not raw:
|
if not raw:
|
||||||
|
|
@ -569,9 +588,14 @@ class MqttSettingsSession:
|
||||||
return candidate
|
return candidate
|
||||||
raise TimeoutError("No response from device")
|
raise TimeoutError("No response from device")
|
||||||
|
|
||||||
def login(self):
|
def login(self, password_candidates=None):
|
||||||
self.publish({"action": "login", "password": LOGIN_PASSWORD})
|
passwords = [value for value in (password_candidates or []) if _truncate_empty(value)]
|
||||||
deadline = time.time() + 1.0
|
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:
|
while time.time() < deadline:
|
||||||
try:
|
try:
|
||||||
candidate = self.queue.get(timeout=0.1)
|
candidate = self.queue.get(timeout=0.1)
|
||||||
|
|
@ -584,10 +608,13 @@ class MqttSettingsSession:
|
||||||
if candidate.get("action") != "login":
|
if candidate.get("action") != "login":
|
||||||
continue
|
continue
|
||||||
if candidate.get("result") is False:
|
if candidate.get("result") is False:
|
||||||
raise RuntimeError(candidate.get("note") or candidate.get("error") or "Login failed")
|
last_error = candidate.get("note") or candidate.get("error") or "Login failed"
|
||||||
|
break
|
||||||
if candidate.get("result") is True:
|
if candidate.get("result") is True:
|
||||||
return True
|
return True
|
||||||
return True
|
else:
|
||||||
|
last_error = "Login response timeout"
|
||||||
|
raise RuntimeError(last_error or "Login failed")
|
||||||
|
|
||||||
def get_server_state(self):
|
def get_server_state(self):
|
||||||
return self.publish_and_wait(
|
return self.publish_and_wait(
|
||||||
|
|
@ -719,7 +746,7 @@ def get_registration_status():
|
||||||
state = dict(persisted)
|
state = dict(persisted)
|
||||||
try:
|
try:
|
||||||
def _status_flow(session, _contract_meta):
|
def _status_flow(session, _contract_meta):
|
||||||
session.login()
|
session.login(_candidate_login_passwords(state["device_id"], persisted))
|
||||||
server_state = session.get_server_state()
|
server_state = session.get_server_state()
|
||||||
device_state = _read_device_registration_snapshot(
|
device_state = _read_device_registration_snapshot(
|
||||||
session,
|
session,
|
||||||
|
|
@ -810,7 +837,7 @@ def register_device(host):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
def _register_flow(session, contract_meta):
|
def _register_flow(session, contract_meta):
|
||||||
session.login()
|
session.login(_candidate_login_passwords(working["device_id"], persisted))
|
||||||
current_server_state = session.get_server_state()
|
current_server_state = session.get_server_state()
|
||||||
if _bool_value((current_server_state or {}).get("registered"), default=False):
|
if _bool_value((current_server_state or {}).get("registered"), default=False):
|
||||||
raise RuntimeError("Device is already registered")
|
raise RuntimeError("Device is already registered")
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
{ mode: "test_by", label: "TEST BY", host: "rest.test.it-screen.by" },
|
{ mode: "test_by", label: "TEST BY", host: "rest.test.it-screen.by" },
|
||||||
{ mode: "custom", label: "Custom", host: "" }
|
{ 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_INITIAL_LINES = 50;
|
||||||
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
||||||
const ITSCREEN_LOG_BATCH_MS = 250;
|
const ITSCREEN_LOG_BATCH_MS = 250;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue