2022-12-24 16:51:42 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from sys import exit
|
|
|
|
|
|
|
|
from packaging import version
|
2024-09-27 06:42:58 +00:00
|
|
|
from requests import get
|
2022-12-24 16:51:42 +00:00
|
|
|
|
2024-09-27 06:42:58 +00:00
|
|
|
API_TOKEN = "${token}"
|
|
|
|
DOMAIN = "${domain}"
|
2022-12-24 16:51:42 +00:00
|
|
|
|
2024-09-27 06:42:58 +00:00
|
|
|
try:
|
|
|
|
r = get("https://version.home-assistant.io/stable.json")
|
|
|
|
r.raise_for_status()
|
|
|
|
stable_version = r.json()["homeassistant"]["generic-x86-64"]
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Could not get stable version information from home-assistant.io: {e!r}")
|
|
|
|
exit(3)
|
2022-12-24 16:51:42 +00:00
|
|
|
|
|
|
|
try:
|
2024-09-27 06:42:58 +00:00
|
|
|
r = get(
|
|
|
|
f"https://{DOMAIN}/api/config",
|
|
|
|
headers={"Authorization": f"Bearer {API_TOKEN}", "Content-Type": "application/json"},
|
2022-12-24 16:51:42 +00:00
|
|
|
)
|
2024-09-27 06:42:58 +00:00
|
|
|
r.raise_for_status()
|
|
|
|
running_version = r.json()["version"]
|
2022-12-24 16:51:42 +00:00
|
|
|
except Exception as e:
|
2024-09-27 06:42:58 +00:00
|
|
|
print(f"Could not get running version information from homeassistant: {e!r}")
|
|
|
|
exit(3)
|
2022-12-24 16:51:42 +00:00
|
|
|
|
2024-09-27 06:42:58 +00:00
|
|
|
try:
|
|
|
|
if stable_version > running_version:
|
|
|
|
print(
|
|
|
|
f"There is a newer version available: {stable_version} (currently installed: {running_version})"
|
|
|
|
)
|
|
|
|
exit(2)
|
|
|
|
else:
|
|
|
|
print(
|
|
|
|
f"Currently running version {running_version} matches newest release on home-assistant.io"
|
|
|
|
)
|
|
|
|
exit(0)
|
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
|
|
|
exit(3)
|