|
| 1 | +import requests |
| 2 | +import configManager |
| 3 | +import logManager |
| 4 | +import json |
| 5 | +from datetime import datetime, timezone |
| 6 | +import subprocess |
| 7 | + |
| 8 | +bridgeConfig = configManager.bridgeConfig.yaml_config |
| 9 | +logging = logManager.logger.get_logger(__name__) |
| 10 | + |
| 11 | +def versionCheck(): |
| 12 | + swversion = bridgeConfig["config"]["swversion"] |
| 13 | + url = "https://firmware.meethue.com/v1/checkupdate/?deviceTypeId=BSB002&version=" + swversion |
| 14 | + response = requests.get(url) |
| 15 | + if response.status_code == 200: |
| 16 | + device_data = json.loads(response.text) |
| 17 | + if len(device_data["updates"]) != 0: |
| 18 | + new_version = str(device_data["updates"][len(device_data["updates"])-1]["version"]) |
| 19 | + new_versionName = str(device_data["updates"][len(device_data["updates"])-1]["versionName"]) |
| 20 | + if new_version > swversion: |
| 21 | + logging.info("swversion number update from Philips, old: " + swversion + " new:" + new_version) |
| 22 | + bridgeConfig["config"]["swversion"] = new_version |
| 23 | + bridgeConfig["config"]["apiversion"] = new_versionName |
| 24 | + bridgeConfig["config"]["swupdate2"]["lastchange"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S") |
| 25 | + bridgeConfig["config"]["swupdate2"]["bridge"]["lastinstall"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S") |
| 26 | + else: |
| 27 | + logging.info("swversion higher than Philips") |
| 28 | + else: |
| 29 | + logging.info("no swversion number update from Philips") |
| 30 | + |
| 31 | +def githubCheck(): |
| 32 | + #creation_time = "2024-02-18 19:50:15.000000000 +0100\n" |
| 33 | + creation_time = subprocess.run("stat -c %y HueEmulator3.py", shell=True, capture_output=True, text=True)#2024-02-18 19:50:15.000000000 +0100\n |
| 34 | + creation_time_arg1 = creation_time.stdout.replace(".", " ").split(" ")#2024-02-18, 19:50:15, 000000000, +0100\n |
| 35 | + creation_time = creation_time_arg1[0] + " " + creation_time_arg1[1] + " " + creation_time_arg1[3].replace("\n", "")#2024-02-18 19:50:15 +0100 |
| 36 | + creation_time = datetime.strptime(creation_time, "%Y-%m-%d %H:%M:%S %z").astimezone(timezone.utc).strftime("%Y-%m-%d %H")#2024-02-18 18 |
| 37 | + |
| 38 | + url = "https://api.github.com/repos/diyhue/diyhue/branches/master" |
| 39 | + #url = "https://api.github.com/repos/hendriksen-mark/diyhue/branches/master" |
| 40 | + response = requests.get(url) |
| 41 | + if response.status_code == 200: |
| 42 | + device_data = json.loads(response.text) |
| 43 | + publish_time = datetime.strptime(device_data["commit"]["commit"]["author"]["date"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H") |
| 44 | + |
| 45 | + logging.info("creation_time diyHue : " + str(creation_time)) |
| 46 | + logging.info("publish_time diyHue : " + str(publish_time)) |
| 47 | + |
| 48 | + if publish_time > creation_time: |
| 49 | + logging.info("update on github") |
| 50 | + bridgeConfig["config"]["swupdate2"]["state"] = "allreadytoinstall" |
| 51 | + bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "allreadytoinstall" |
| 52 | + elif githubUICheck() == True: |
| 53 | + logging.info("UI update on github") |
| 54 | + bridgeConfig["config"]["swupdate2"]["state"] = "anyreadytoinstall" |
| 55 | + bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "anyreadytoinstall" |
| 56 | + else: |
| 57 | + logging.info("no update for diyHue or UI on github") |
| 58 | + bridgeConfig["config"]["swupdate2"]["state"] = "noupdates" |
| 59 | + bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "noupdates" |
| 60 | + |
| 61 | + bridgeConfig["config"]["swupdate2"]["checkforupdate"] = False |
| 62 | + |
| 63 | +def githubUICheck(): |
| 64 | + #creation_time = "2024-02-18 19:50:15.000000000 +0100\n" |
| 65 | + creation_time = subprocess.run("stat -c %y flaskUI/templates/index.html", shell=True, capture_output=True, text=True)#2024-02-18 19:50:15.000000000 +0100\n |
| 66 | + creation_time_arg1 = creation_time.stdout.replace(".", " ").split(" ")#2024-02-18, 19:50:15, 000000000, +0100\n |
| 67 | + creation_time = creation_time_arg1[0] + " " + creation_time_arg1[1] + " " + creation_time_arg1[3].replace("\n", "")#2024-02-18 19:50:15 +0100 |
| 68 | + creation_time = datetime.strptime(creation_time, "%Y-%m-%d %H:%M:%S %z").astimezone(timezone.utc).strftime("%Y-%m-%d %H")#2024-02-18 18 |
| 69 | + |
| 70 | + url = "https://api.github.com/repos/diyhue/diyhueUI/branches/master" |
| 71 | + #url = "https://api.github.com/repos/hendriksen-mark/diyhueUI/branches/master" |
| 72 | + response = requests.get(url) |
| 73 | + if response.status_code == 200: |
| 74 | + device_data = json.loads(response.text) |
| 75 | + publish_time = datetime.strptime(device_data["commit"]["commit"]["author"]["date"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H") |
| 76 | + |
| 77 | + logging.info("creation_time UI : " + str(creation_time)) |
| 78 | + logging.info("publish_time UI : " + str(publish_time)) |
| 79 | + |
| 80 | + if publish_time > creation_time: |
| 81 | + return True |
| 82 | + else: |
| 83 | + return False |
| 84 | + |
| 85 | + |
| 86 | +def githubInstall_test(): |
| 87 | + if bridgeConfig["config"]["swupdate2"]["state"] == "anyreadytoinstall":#ui update |
| 88 | + bridgeConfig["config"]["swupdate2"]["state"] = "installing" |
| 89 | + bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing" |
| 90 | + subprocess.Popen("sh githubUIInstall.sh",shell=True, close_fds=True) |
| 91 | + if bridgeConfig["config"]["swupdate2"]["state"] == "allreadytoinstall":#diyhue + ui update |
| 92 | + bridgeConfig["config"]["swupdate2"]["state"] = "installing" |
| 93 | + bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing" |
| 94 | + subprocess.Popen("sh githubInstall.sh",shell=True, close_fds=True) |
| 95 | + |
| 96 | +def githubInstall(): |
| 97 | + logging.info("work in progress") |
| 98 | + bridgeConfig["config"]["swupdate2"]["install"] = False |
0 commit comments