RaspCam/server/lib/CameraCommander/WaitEnabledModeReply.py
2020-05-15 12:27:34 +02:00

41 lines
1.3 KiB
Python

import time
from CameraModel import CameraModel
from WaitState import WaitState
from WaitActivity import WaitActivity
class WaitEnabledModeReply(WaitState):
def __init__(self, userCommand):
self.userCommand = userCommand
self.initTime = time.time()
def handle(self, context):
data = self.waitMsg(context)
if not data:
if self.userCommand:
self.userCommand.callback(False, "connection_lost")
return
if data == "enabled":
print("[WaitEnabledModeReply] : Camera ({}) at {}:{} successfully enabled".format(context.camera.id, context.connection.addr, context.connection.port))
context.camera.enabled = True
mdl = CameraModel()
mdl.update(context.camera)
context.state = WaitActivity()
if self.userCommand:
self.userCommand.callback(True)
else:
print("[WaitEnabledModeReply] : Error({}) from camera ({}) at {}:{}".format(data, context.camera.id, context.connection.addr, context.connection.port))
context.close()
if self.userCommand:
self.userCommand.callback(False, data)
def tic(self, context):
if time.time() - self.initTime > 10:
print("[WaitEnabledModeReply] : Timeout exeeded for camera ({}) at {}:{}".format(context.camera.id, context.connection.addr, context.connection.port))
context.close()
if self.userCommand:
self.userCommand.callback(False, "timeout")