From 621a1d23d6d3cb5a6395936484a331458848657e Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Thu, 16 May 2024 15:59:48 +0100 Subject: [PATCH] Toggle lights with right-hand buttons --- api.py | 3 +++ app.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/api.py b/api.py index 718fa18..584bf8f 100644 --- a/api.py +++ b/api.py @@ -70,3 +70,6 @@ class Api: else: dir = "down" self.__post(f"/api/services/media_player/volume_{dir}", {"entity_id": entity_id}) self.__post(f"/api/services/media_player/volume_{dir}", {"entity_id": entity_id}) + + def toggleLight(self, entity_id: str) -> None: + self.__post(f"/api/services/light/toggle", {"entity_id": entity_id}) diff --git a/app.py b/app.py index 8c3c6bb..f445f3e 100644 --- a/app.py +++ b/app.py @@ -177,13 +177,25 @@ class App: # if its settings have changed, re-draw them without clearing the display d = self.api.getLightData(SCREENS[self.screen]["entities"][i]["id"]) if (d != self.scr_vals[i]): - self.__displayLightEntity(i, self.lcd.width//2, self.lcd.height//2, self.lcd.width//2 * (i % 2), self.lcd.height//2 * (i//2), SCREENS[self.screen]["entities"][i]["name"], d[i]) + self.__displayLightEntity(i, self.lcd.width//2, self.lcd.height//2, self.lcd.width//2 * (i % 2), self.lcd.height//2 * (i//2), SCREENS[self.screen]["entities"][i]["name"], d) # TODO: double button press to select a light, then up/down to change brightness? and single button click to turn on/off? self.lcd.show() def __handleLightsScreenButtons(self) -> bool: # TODO: reset buttons used - return False + b = [self.lcd.keyA["v"], self.lcd.keyB["v"], self.lcd.keyX["v"], self.lcd.keyY["v"]] + self.lcd.keyA["v"] = False + self.lcd.keyB["v"] = False + self.lcd.keyX["v"] = False + self.lcd.keyY["v"] = False + e = min(len(SCREENS[self.screen]["entities"]), 4) + a = False + for i in range(0, e): + # if button for light clicked, toggle the light + if (b[i]): + self.api.toggleLight(SCREENS[self.screen]["entities"][i]["id"]) + a = True + return a def __updateMediaScreen(self) -> None: d = self.api.getMediaPlayerData(SCREENS[self.screen]["entity"])