From 28b7bef3a79c5968d94cca35d96628f5c692fc6a Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 12 Jul 2023 15:04:24 +0300 Subject: [PATCH] treewide: selectable OTA from GH --- api.py | 2 +- shared/was.py | 7 +++++-- ui.py | 12 ++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/api.py b/api.py index 715b3f4..dea9145 100644 --- a/api.py +++ b/api.py @@ -281,7 +281,7 @@ async def post_release_cache(request: Request): @app.post("/api/ota") async def post_ota(body: Dict = Body(...)): log.error(f"body: {body} {type(body)}") - msg = json.dumps({'cmd': 'ota_start', 'ota_url': os.environ['OTA_URL']}) + msg = json.dumps({'cmd': 'ota_start', 'ota_url': body["ota_url"]}) try: ws = connmgr.get_client_by_hostname(body["hostname"]) await ws.send_text(msg) diff --git a/shared/was.py b/shared/was.py index cfdc136..3a9c0d2 100644 --- a/shared/was.py +++ b/shared/was.py @@ -12,6 +12,7 @@ URL_WAS_API_CLIENTS = 'http://localhost:8502/api/clients' URL_WAS_API_OTA = 'http://localhost:8502/api/ota' URL_WAS_API_RELEASES = 'http://localhost:8502/api/releases' +URL_WAS_API_RELEASE_CACHE = 'http://localhost:8502/api/release/cache' URL_WAS_API_CONFIG = "http://localhost:8502/api/config" URL_WAS_API_CONFIG_APPLY = "http://localhost:8502/api/config/apply" @@ -169,8 +170,10 @@ def num_devices(): return (len(get_devices())) -def ota(hostname): - requests.post(URL_WAS_API_OTA, json={'hostname': hostname}) +def ota(hostname, info, version): + info['version'] = version + requests.post(URL_WAS_API_RELEASE_CACHE, json=info) + requests.post(URL_WAS_API_OTA, json={'hostname': hostname, 'ota_url': info['was_url']}) def post_config(json, apply=False): diff --git a/ui.py b/ui.py index 2851dbf..d44eaae 100644 --- a/ui.py +++ b/ui.py @@ -12,6 +12,7 @@ get_devices, get_ha_commands_for_entity, get_ha_entities, + get_releases, get_tz, merge_dict, num_devices, @@ -46,6 +47,10 @@ except Exception: default_nvs = {} +releases = {} +if len(user_nvs) != 0: + releases = get_releases(user_nvs["WAS"]["URL"]) + title = 'Willow Application Server' st.set_page_config(page_title=title, layout='wide') @@ -81,9 +86,12 @@ on_click=apply_config_host, type="primary") actions.button(key=f"btn_apply_nvs_{idx}", kwargs=dict(hostname=row['hostname']), label="Apply NVS", on_click=apply_nvs_host, type="primary") - actions.button(key=f"btn_ota_{idx}", kwargs=dict(hostname=row['hostname']), label="OTA", - on_click=ota, type="primary") + if len(releases) > 0: + actions.selectbox("Select release to flash", releases, key=f"sb_ota_{idx}") + actions.button(key=f"btn_ota_{idx}", kwargs=dict(hostname=row['hostname'], + info=releases[st.session_state[f"sb_ota_{idx}"]][row['hw_type']], + version=st.session_state[f"sb_ota_{idx}"]), label="OTA", on_click=ota, type="primary") with configuration: was_url = ""