Skip to content

Commit

Permalink
treewide: selectable OTA from GH
Browse files Browse the repository at this point in the history
  • Loading branch information
stintel committed Jul 12, 2023
1 parent 0345da3 commit 28b7bef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions shared/was.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 10 additions & 2 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_devices,
get_ha_commands_for_entity,
get_ha_entities,
get_releases,
get_tz,
merge_dict,
num_devices,
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit 28b7bef

Please sign in to comment.