Handle privacy mode

This commit is contained in:
Davide Depau 2023-09-17 17:54:18 +02:00
parent 092cdd6de9
commit 88fc0940c4
2 changed files with 34 additions and 2 deletions

31
bot.py
View file

@ -67,6 +67,8 @@ class Bot:
adjust_perspective=True, adjust_perspective=True,
timeout: float = 5.0, timeout: float = 5.0,
) -> List[cv2.typing.MatLike]: ) -> List[cv2.typing.MatLike]:
privacy_mode = self.tapo.getPrivacyMode()
# Prepare the camera # Prepare the camera
print("Disabling privacy mode and setting auto day/night mode...") print("Disabling privacy mode and setting auto day/night mode...")
self.tapo.setPrivacyMode(False) self.tapo.setPrivacyMode(False)
@ -85,6 +87,8 @@ class Bot:
self.tapo.setDayNightMode("on") self.tapo.setDayNightMode("on")
if not adjust_perspective: if not adjust_perspective:
self.tapo.setPrivacyMode(privacy_mode)
self.tapo.setDayNightMode("auto")
return [pretty_image] return [pretty_image]
# Iterate until we find all 4 aruco markers or timeout # Iterate until we find all 4 aruco markers or timeout
@ -100,6 +104,8 @@ class Bot:
print( print(
"Timeout waiting for ArUco markers, returning only original image" "Timeout waiting for ArUco markers, returning only original image"
) )
self.tapo.setPrivacyMode(privacy_mode)
self.tapo.setDayNightMode("auto")
return [pretty_image] return [pretty_image]
ret, annotated_image = vcap.read() ret, annotated_image = vcap.read()
@ -120,7 +126,7 @@ class Bot:
"Found all ArUco markers, enabled privacy mode and set auto day/night mode..." "Found all ArUco markers, enabled privacy mode and set auto day/night mode..."
) )
self.tapo.setDayNightMode("auto") self.tapo.setDayNightMode("auto")
self.tapo.setPrivacyMode(True) self.tapo.setPrivacyMode(privacy_mode)
corners = [aruco_corners[i] for i in range(1, 5)] corners = [aruco_corners[i] for i in range(1, 5)]
ids = np.array([[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.", text="Hello, I'm a bot that can send you a photo from the camera.",
) )
case "/reposition": case "/reposition":
privacy_mode = self.tapo.getPrivacyMode()
self.tapo.setPrivacyMode(False)
presets = self._get_presets() presets = self._get_presets()
if self.profile_name not in presets: if self.profile_name not in presets:
await self.bot.send_message( await self.bot.send_message(
@ -206,15 +214,18 @@ class Bot:
) )
return return
self.tapo.setPreset(presets[self.profile_name]) self.tapo.setPreset(presets[self.profile_name])
self.tapo.setPrivacyMode(privacy_mode)
await self.bot.send_message( await self.bot.send_message(
chat_id=msg.chat_id, chat_id=msg.chat_id,
text=f"Repositioned to profile '{self.profile_name}'", text=f"Repositioned to profile '{self.profile_name}'",
) )
case "/calibrate": case "/calibrate":
privacy_mode = self.tapo.getPrivacyMode()
self.tapo.calibrateMotor() self.tapo.calibrateMotor()
presets = self._get_presets() presets = self._get_presets()
if self.profile_name in presets: if self.profile_name in presets:
self.tapo.setPreset(presets[self.profile_name]) self.tapo.setPreset(presets[self.profile_name])
self.tapo.setPrivacyMode(privacy_mode)
await self.bot.send_message( await self.bot.send_message(
chat_id=msg.chat_id, chat_id=msg.chat_id,
text=f"Calibrated and repositioned to profile '{self.profile_name}'", 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) await self._photo_command(msg.chat_id, adjust_perspective=True)
case "/photo_unprocessed": case "/photo_unprocessed":
await self._photo_command(msg.chat_id, adjust_perspective=False) 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( async def take_photo(
self, adjust_perspective=True, timeout=5.0 self, adjust_perspective=True, timeout=5.0

View file

@ -4,4 +4,7 @@ reposition - Re-aim the camera
light_on - Turn on the light light_on - Turn on the light
light_off - Turn off the light light_off - Turn off the light
light_status - Check the status of the light light_status - Check the status of the light
photo_unprocessed - Take a photo of the grocery list board without processing 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