-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.py
53 lines (39 loc) · 1.55 KB
/
core.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import signal
import subprocess
import logging
from config import Config
from mqtt import Mqtt
from subprocess import PIPE, STDOUT
import time
from alarmserver import AlarmServer
logger = logging.getLogger(__name__)
class Core:
def __init__(self):
self.config = Config()
self.config.read()
self.mqtt = Mqtt(self.config.mqtt_address, self.config.mqtt_port, self.config.mqtt_username, self.config.mqtt_password, self.config.mqtt_clientname)
self.mqtt.subscribe('pyainvr/all/state/set', "off", self.kill_all)
self.mqtt.subscribe('pyainvr/all/state/set', "on", self.start_all)
logging.basicConfig()
logger.setLevel(logging.WARNING)
if self.config.alarmserver_enabled:
logger.warn("Alarm server is enabled")
AlarmServer(self.config.alarmserver_port, self.mqtt, self.config.Cameras)
for cam in self.config.Cameras:
self.mqtt.subscribe('pyainvr/' + cam.name + '/state/set', "off", cam.kill)
self.mqtt.subscribe('pyainvr/' + cam.name + '/state/set', "on", cam.start)
self.mqtt.subscribe('pyainvr/' + cam.name + '/state/set', "autorecord", cam.autoRecord)
self.mqtt.start()
self.start_all()
def kill_all(self):
for cam in self.config.Cameras:
cam.kill()
def start_all(self):
for cam in self.config.Cameras:
cam.start()
def alarm_record(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
self.kill_all()
pass