From 88fc0940c41793da3168e96ee99d33843156f1e2 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Sun, 17 Sep 2023 17:54:18 +0200 Subject: [PATCH] Handle privacy mode --- bot.py | 31 ++++++++++++++++++++++++++++++- commands.txt | 5 ++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 7edaba1..9207d26 100644 --- a/bot.py +++ b/bot.py @@ -67,6 +67,8 @@ class Bot: adjust_perspective=True, timeout: float = 5.0, ) -> List[cv2.typing.MatLike]: + privacy_mode = self.tapo.getPrivacyMode() + # Prepare the camera print("Disabling privacy mode and setting auto day/night mode...") self.tapo.setPrivacyMode(False) @@ -85,6 +87,8 @@ class Bot: self.tapo.setDayNightMode("on") if not adjust_perspective: + self.tapo.setPrivacyMode(privacy_mode) + self.tapo.setDayNightMode("auto") return [pretty_image] # Iterate until we find all 4 aruco markers or timeout @@ -100,6 +104,8 @@ class Bot: print( "Timeout waiting for ArUco markers, returning only original image" ) + self.tapo.setPrivacyMode(privacy_mode) + self.tapo.setDayNightMode("auto") return [pretty_image] ret, annotated_image = vcap.read() @@ -120,7 +126,7 @@ class Bot: "Found all ArUco markers, enabled privacy mode and set auto day/night mode..." ) self.tapo.setDayNightMode("auto") - self.tapo.setPrivacyMode(True) + self.tapo.setPrivacyMode(privacy_mode) corners = [aruco_corners[i] for i in range(1, 5)] ids = np.array([[i] for i in range(1, 5)]) @@ -198,6 +204,8 @@ class Bot: text="Hello, I'm a bot that can send you a photo from the camera.", ) case "/reposition": + privacy_mode = self.tapo.getPrivacyMode() + self.tapo.setPrivacyMode(False) presets = self._get_presets() if self.profile_name not in presets: await self.bot.send_message( @@ -206,15 +214,18 @@ class Bot: ) return self.tapo.setPreset(presets[self.profile_name]) + self.tapo.setPrivacyMode(privacy_mode) await self.bot.send_message( chat_id=msg.chat_id, text=f"Repositioned to profile '{self.profile_name}'", ) case "/calibrate": + privacy_mode = self.tapo.getPrivacyMode() self.tapo.calibrateMotor() presets = self._get_presets() if self.profile_name in presets: self.tapo.setPreset(presets[self.profile_name]) + self.tapo.setPrivacyMode(privacy_mode) await self.bot.send_message( chat_id=msg.chat_id, text=f"Calibrated and repositioned to profile '{self.profile_name}'", @@ -241,6 +252,24 @@ class Bot: await self._photo_command(msg.chat_id, adjust_perspective=True) case "/photo_unprocessed": await self._photo_command(msg.chat_id, adjust_perspective=False) + case "/privacy_on": + self.tapo.setPrivacyMode(True) + await self.bot.send_message( + chat_id=msg.chat_id, + text=f"Privacy mode turned on", + ) + case "/privacy_off": + self.tapo.setPrivacyMode(False) + await self.bot.send_message( + chat_id=msg.chat_id, + text=f"Privacy mode turned off", + ) + case "/privacy_status": + state = self.tapo.getPrivacyMode() + await self.bot.send_message( + chat_id=msg.chat_id, + text=f"Privacy mode is {state and 'enabled' or 'disabled'}", + ) async def take_photo( self, adjust_perspective=True, timeout=5.0 diff --git a/commands.txt b/commands.txt index caef359..72baa4a 100644 --- a/commands.txt +++ b/commands.txt @@ -4,4 +4,7 @@ reposition - Re-aim the camera light_on - Turn on the light light_off - Turn off the light light_status - Check the status of the light -photo_unprocessed - Take a photo of the grocery list board without processing \ No newline at end of file +photo_unprocessed - Take a photo of the grocery list board without processing +privacy_on - Turn on privacy mode +privacy_off - Turn off privacy mode +privacy_status - Check the status of privacy mode \ No newline at end of file