From a41642da071d62ce5252160334334183c37f8a2f Mon Sep 17 00:00:00 2001 From: infeeeee Date: Fri, 23 Aug 2024 19:47:44 +0200 Subject: [PATCH 1/2] Support more commands, reorder, raise error with screenshot and camshot --- fullykiosk/__init__.py | 134 ++++++++++++++++++++++++++++------------- 1 file changed, 92 insertions(+), 42 deletions(-) diff --git a/fullykiosk/__init__.py b/fullykiosk/__init__.py index c7ff95c..9981952 100644 --- a/fullykiosk/__init__.py +++ b/fullykiosk/__init__.py @@ -25,7 +25,12 @@ async def sendCommand(self, cmd, **kwargs): data = await self._rh.get( cmd=cmd, password=self._password, type="json", **kwargs ) - if RESPONSE_STATUS in data and data[RESPONSE_STATUS] == RESPONSE_ERRORSTATUS: + + if ( + isinstance(data, dict) + and RESPONSE_STATUS in data + and data[RESPONSE_STATUS] == RESPONSE_ERRORSTATUS + ): raise FullyKioskError(RESPONSE_ERRORSTATUS, data[RESPONSE_STATUSTEXT]) return data @@ -47,11 +52,15 @@ def deviceInfo(self): def settings(self): return self._settings - async def startScreensaver(self): - await self.sendCommand("startScreensaver") + # Configurations - async def stopScreensaver(self): - await self.sendCommand("stopScreensaver") + async def setConfigurationString(self, setting, stringValue): + await self.sendCommand("setStringSetting", key=setting, value=stringValue) + + async def setConfigurationBool(self, setting, boolValue): + await self.sendCommand("setBooleanSetting", key=setting, value=boolValue) + + # Screen, screensaver async def screenOn(self): await self.sendCommand("screenOn") @@ -59,22 +68,28 @@ async def screenOn(self): async def screenOff(self): await self.sendCommand("screenOff") - async def setScreenBrightness(self, brightness): - await self.sendCommand( - "setStringSetting", key="screenBrightness", value=brightness - ) + async def forceSleep(self): + await self.sendCommand("forceSleep") - async def setAudioVolume(self, volume, stream=None): - await self.sendCommand("setAudioVolume", level=volume, stream=stream) + async def startScreensaver(self): + await self.sendCommand("startScreensaver") - async def restartApp(self): - await self.sendCommand("restartApp") + async def stopScreensaver(self): + await self.sendCommand("stopScreensaver") - async def loadStartUrl(self): - await self.sendCommand("loadStartUrl") + async def startDaydream(self): + await self.sendCommand("startScreensaver") - async def loadUrl(self, url): - await self.sendCommand("loadUrl", url=url) + async def stopDaydream(self): + await self.sendCommand("stopScreensaver") + + async def setScreenBrightness(self, brightness): + await self.setConfigurationString("screenBrightness", brightness) + + # Audio + + async def setAudioVolume(self, volume, stream=None): + await self.sendCommand("setAudioVolume", level=volume, stream=stream) async def playSound(self, url, stream=None): await self.sendCommand("playSound", url=url, stream=stream) @@ -82,20 +97,21 @@ async def playSound(self, url, stream=None): async def stopSound(self): await self.sendCommand("stopSound") - async def toForeground(self): - await self.sendCommand("toForeground") - - async def toBackground(self): - await self.sendCommand("toBackground") + async def textToSpeech(self, text, locale=None, engine=None, queue=None): + if queue is not None: + queue = "1" if queue else "0" + await self.sendCommand("textToSpeech", text=text, locale=locale, engine=engine, queue=queue) - async def startApplication(self, application): - await self.sendCommand("startApplication", package=application) + async def stopTextToSpeech(self): + await self.sendCommand("stopTextToSpeech") - async def setConfigurationString(self, setting, stringValue): - await self.sendCommand("setStringSetting", key=setting, value=stringValue) + # Lock, maintenance - async def setConfigurationBool(self, setting, boolValue): - await self.sendCommand("setBooleanSetting", key=setting, value=boolValue) + async def lockKiosk(self): + await self.sendCommand("lockKiosk") + + async def unlockKiosk(self): + await self.sendCommand("unlockKiosk") async def enableLockedMode(self): await self.sendCommand("enableLockedMode") @@ -103,35 +119,69 @@ async def enableLockedMode(self): async def disableLockedMode(self): await self.sendCommand("disableLockedMode") - async def lockKiosk(self): - await self.sendCommand("lockKiosk") + # Root only: - async def unlockKiosk(self): - await self.sendCommand("unlockKiosk") + async def rebootDevice(self): + await self.sendCommand("rebootDevice") - async def enableMotionDetection(self): - await self.setConfigurationBool("motionDetection", True) + # App management - async def disableMotionDetection(self): - await self.setConfigurationBool("motionDetection", False) + async def restartApp(self): + await self.sendCommand("restartApp") - async def rebootDevice(self): - await self.sendCommand("rebootDevice") + async def exitApp(self): + await self.sendCommand("exitApp") + + async def killMyProcess(self): + await self.sendCommand("killMyProcess") + + async def toForeground(self): + await self.sendCommand("toForeground") + + async def toBackground(self): + await self.sendCommand("toBackground") + + async def startApplication(self, application): + await self.sendCommand("startApplication", package=application) + + # Web browsing + + async def loadStartUrl(self): + await self.sendCommand("loadStartUrl") + + async def loadUrl(self, url): + await self.sendCommand("loadUrl", url=url) async def clearCache(self): await self.sendCommand("clearCache") - + async def clearWebstorage(self): await self.sendCommand("clearWebstorage") - + async def clearCookies(self): await self.sendCommand("clearCookies") + async def resetWebview(self): + await self.sendCommand("resetWebview") + + # Motion detection + + async def triggerMotion(self): + await self.sendCommand("triggerMotion") + + async def enableMotionDetection(self): + await self.setConfigurationBool("motionDetection", True) + + async def disableMotionDetection(self): + await self.setConfigurationBool("motionDetection", False) + + # Camera, screenshot: + async def getCamshot(self): - return await self._rh.get(cmd="getCamshot", password=self._password) + return await self.sendCommand("getCamshot") async def getScreenshot(self): - return await self._rh.get(cmd="getScreenshot", password=self._password) + return await self.sendCommand("getScreenshot") class _RequestsHandler: From da9bdaab49ea0b083a1dbf195b3739300e76a262 Mon Sep 17 00:00:00 2001 From: infeeeee Date: Fri, 30 Aug 2024 00:36:14 +0200 Subject: [PATCH 2/2] Fix Daydream commands, comments --- fullykiosk/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fullykiosk/__init__.py b/fullykiosk/__init__.py index 9981952..d7b4e2e 100644 --- a/fullykiosk/__init__.py +++ b/fullykiosk/__init__.py @@ -34,6 +34,8 @@ async def sendCommand(self, cmd, **kwargs): raise FullyKioskError(RESPONSE_ERRORSTATUS, data[RESPONSE_STATUSTEXT]) return data + # REST API Documentation: https://www.fully-kiosk.com/en/#rest + async def getDeviceInfo(self): result = await self.sendCommand("deviceInfo") self._deviceInfo = result @@ -77,11 +79,13 @@ async def startScreensaver(self): async def stopScreensaver(self): await self.sendCommand("stopScreensaver") + # Daydream: max Android 12 + async def startDaydream(self): - await self.sendCommand("startScreensaver") + await self.sendCommand("startDaydream") async def stopDaydream(self): - await self.sendCommand("stopScreensaver") + await self.sendCommand("stopDaydream") async def setScreenBrightness(self, brightness): await self.setConfigurationString("screenBrightness", brightness)