41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import time
|
|
|
|
from CameraModel import CameraModel
|
|
from WaitState import WaitState
|
|
from WaitActivity import WaitActivity
|
|
|
|
|
|
class WaitDisabledModeReply(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 == "disabled":
|
|
print("[WaitDisabledModeReply] : Camera ({}) at {}:{} successfully disabled".format(context.camera.id, context.connection.addr, context.connection.port))
|
|
context.camera.enabled = False
|
|
mdl = CameraModel()
|
|
mdl.update(context.camera)
|
|
context.state = WaitActivity()
|
|
if self.userCommand:
|
|
self.userCommand.callback(True)
|
|
else:
|
|
print("[WaitDisabledModeReply] : 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("[WaitDisabledModeReply] : 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")
|