aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2026-06-18 22:54:23 +0100
committerjwansek <eddie.atten.ea29@gmail.com>2026-06-18 22:54:23 +0100
commitc1c005a7c5783522db043bcd0be6c38a8764873d (patch)
treecbad94d789b16667fa2e8690af9bd8dc942bcf7b
parent29770b708616e3c6379b17350baf74c2dd79a52e (diff)
downloadHomelabPowerButtons-c1c005a7c5783522db043bcd0be6c38a8764873d.tar.gz
HomelabPowerButtons-c1c005a7c5783522db043bcd0be6c38a8764873d.zip
Started on omada
-rw-r--r--.gitmodules3
m---------omada-api0
-rw-r--r--powerButtons.py49
3 files changed, 45 insertions, 7 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..aec9c7e
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "omada-api"]
+ path = omada-api
+ url = git@github.com:thannerfabian/omada-api.git
diff --git a/omada-api b/omada-api
new file mode 160000
+Subproject b169929137ec8647bf520067aa2e75e61839a9a
diff --git a/powerButtons.py b/powerButtons.py
index 2e0d4fe..995a185 100644
--- a/powerButtons.py
+++ b/powerButtons.py
@@ -4,10 +4,14 @@ from tkinter import ttk
import configparser
import threading
import requests
+import time
import json
import sys
import os
+sys.path.insert(1, os.path.join(os.path.dirname(__file__), "omada-api"))
+from omada import Omada
+
ZIGBEE_TRANSFORMATIONS = {
"Power": "on",
"ActivePower": "power",
@@ -20,20 +24,24 @@ TASMOTA_TRANSFORMATIONS = {
"Power": "power",
"Voltage": "voltage",
"Current": "current",
- "POWER": "on",
- "Current": "current"
+ "POWER": "on"
}
class App(tk.Tk):
def __init__(self, config_path, *args, **kwargs):
super().__init__(*args, **kwargs)
+ self.config_path = config_path
+
self.title("Power Buttons")
self.protocol("WM_DELETE_WINDOW", self._on_closing)
- self.iconbitmap(os.path.join(os.path.dirname(__file__), "Assets", "icon.ico"))
+ # self.iconbitmap(os.path.join(os.path.dirname(__file__), "Assets", "icon.ico"))
self.config = configparser.ConfigParser()
self.config.read(config_path)
+ self.omada_client = Omada(config_path)
+ self.omada_client.login()
+
self.mqttc = paho.Client("PowerButtonsBUI", clean_session = True)
self.mqttc.on_connect = self._on_connect_cb
@@ -73,6 +81,13 @@ class App(tk.Tk):
self.device_types[friendlyname] = type_
self.tasmota_ips[friendlyname] = ip
+ for profile in self.config["omada"]["profiles"].split(","):
+ self.devices[profile] = omada_query_to_fields(query_omada_profile(self.omada_client, profile))
+ type_ = "Omada HTTP"
+ self.device_widgets[profile] = DeviceButtonWidget(self, profile, type_)
+ self.device_widgets[profile].pack(fill = tk.BOTH, expand = True)
+ self.device_types[profile] = type_
+
self.after(30 * 1000, self._after)
self.mqtt_thread = threading.Thread(target = self._mqtt_thread_func)
@@ -86,6 +101,11 @@ class App(tk.Tk):
self.devices[friendlyname] = fields
self.device_widgets[friendlyname].update()
+ for profile in self.config["omada"]["profiles"].split(","):
+ self.devices[profile] = omada_query_to_fields(query_omada_profile(self.omada_client, profile))
+ self.device_widgets[profile].update()
+ time.sleep(0.1)
+
self.after(30 * 1000, self._after)
def _on_connect_cb(self, mqtt, userdata, flags, rc):
@@ -109,7 +129,10 @@ class App(tk.Tk):
self.mqttc.loop_forever()
def _on_closing(self):
+ self.omada_client.logout()
+ print("Omada disconnected")
self.mqttc.disconnect()
+ print("MQTT client disconnected")
self.destroy()
class DeviceButtonWidget(tk.Frame):
@@ -208,6 +231,15 @@ def send_raw_tasmota_http(host, password, command):
})
return req.json()
+def query_omada_profile(omada, profile_name):
+ profileId = omada.getProfileId(profile_name)
+ print(profile_name, profileId)
+ settings = omada.getProfileSettings(profileId)
+ return settings
+
+def omada_query_to_fields(profile_query_results):
+ return {"on": bool(profile_query_results["poe"]), "power": None, "current": None, "voltage": None}
+
if __name__ == "__main__":
places_to_look = [
os.path.dirname(__file__),
@@ -218,7 +250,10 @@ if __name__ == "__main__":
for p in places_to_look:
fp = os.path.join(p, "powerButtons.ini")
if os.path.exists(fp):
- app = App(fp)
- app.mainloop()
-
- print("Couldn't find a config file :c") \ No newline at end of file
+
+ root = App(fp)
+ root.mainloop()
+
+ exit()
+
+ print("Couldn't find a config file :c")