浏览代码

Merge 118cda5f79 into 2b095c8c77

pull/84/merge
Carl Allen GitHub 6 年前
父节点
当前提交
8d595ed83d
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 1 个文件被更改,包括 15 次插入11 次删除
  1. +15
    -11
      modules/core/core.py

+ 15
- 11
modules/core/core.py 查看文件

@@ -18,6 +18,7 @@ from hardware import *


import time import time
import uuid import uuid
from os import popen, system




class NotificationAPI(object): class NotificationAPI(object):
@@ -83,7 +84,7 @@ class SensorAPI(object):
def init_sensors(self): def init_sensors(self):
''' '''
Initialize all sensors Initialize all sensors
:return:
:return:
''' '''


self.app.logger.info("Init Sensors") self.app.logger.info("Init Sensors")
@@ -108,15 +109,15 @@ class SensorAPI(object):
def init_sensor(self, id): def init_sensor(self, id):
''' '''
initialize sensor by id initialize sensor by id
:param id:
:return:
:param id:
:return:
''' '''


def start_active_sensor(instance): def start_active_sensor(instance):
''' '''
start active sensors as background job start active sensors as background job
:param instance:
:return:
:param instance:
:return:
''' '''
instance.execute() instance.execute()


@@ -151,6 +152,9 @@ class SensorAPI(object):
filename = "./logs/%s_%s.log" % (prefix, str(id)) filename = "./logs/%s_%s.log" % (prefix, str(id))
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime()) formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
msg = str(formatted_time) + "," +str(value) + "\n" msg = str(formatted_time) + "," +str(value) + "\n"
if popen("tail -n 2 "+ filename).read().count(","+ str(value)+ "\n") == 2:
# if the data was logged twice, delete the last logged data and write a new one
system("truncate -s -\"$(tail -n1 " + filename + " | wc -c)\" " + filename)


with open(filename, "a") as file: with open(filename, "a") as file:
file.write(msg) file.write(msg)
@@ -447,7 +451,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
def run_init(self): def run_init(self):
''' '''
call all initialziers after startup call all initialziers after startup
:return:
:return:
''' '''
self.app.logger.info("Invoke Init") self.app.logger.info("Invoke Init")
self.cache["init"] = sorted(self.cache["init"], key=lambda k: k['order']) self.cache["init"] = sorted(self.cache["init"], key=lambda k: k['order'])
@@ -461,10 +465,10 @@ class CraftBeerPi(ActorAPI, SensorAPI):


''' '''
Background Task Decorator Background Task Decorator
:param key:
:param interval:
:param config_parameter:
:return:
:param key:
:param interval:
:param config_parameter:
:return:
''' '''
def real_decorator(function): def real_decorator(function):
self.cache["background"].append({"function": function, "key": key, "interval": interval, "config_parameter": config_parameter}) self.cache["background"].append({"function": function, "key": key, "interval": interval, "config_parameter": config_parameter})
@@ -476,7 +480,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
def run_background_processes(self): def run_background_processes(self):
''' '''
call all background task after startup call all background task after startup
:return:
:return:
''' '''
self.app.logger.info("Start Background") self.app.logger.info("Start Background")




正在加载...
取消
保存