浏览代码

fixed bug where logger stopped logging, because of calling cbpi.run() twice

pull/147/head
Johannes 8 年前
父节点
当前提交
ec335ecadf
共有 3 个文件被更改,包括 8 次插入11 次删除
  1. +1
    -0
      modules/core/basetypes.py
  2. +7
    -5
      modules/core/core.py
  3. +0
    -6
      run.py

+ 1
- 0
modules/core/basetypes.py 查看文件

@@ -65,6 +65,7 @@ class Sensor(Base):
def update_value(self, value): def update_value(self, value):
self.value = value self.value = value
self.__logger.info("Updated value for sensor [%s] with value [%s].", self.id, value)
self.cbpi.sensor.write_log(self.id, value) self.cbpi.sensor.write_log(self.id, value)
self.cbpi.emit("SENSOR_UPDATE", id=self.id, value=value) self.cbpi.emit("SENSOR_UPDATE", id=self.id, value=value)
self.cbpi.ws_emit("SENSOR_UPDATE", self.cbpi.cache["sensors"][self.id]) self.cbpi.ws_emit("SENSOR_UPDATE", self.cbpi.cache["sensors"][self.id])


+ 7
- 5
modules/core/core.py 查看文件

@@ -205,9 +205,11 @@ class SensorCore(object):
self.logger.debug(self.cbpi) self.logger.debug(self.cbpi)
def write_log(self, id, value, prefix="sensor"): def write_log(self, id, value, prefix="sensor"):
self.logger.info("Write Log")
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"
self.logger.info("Write to log [%s]", msg)
with open(filename, "a") as file: with open(filename, "a") as file:
file.write(msg) file.write(msg)
@@ -246,7 +248,7 @@ class BrewingCore(object):
# Start controller # Start controller
if kettle.logic is not None: if kettle.logic is not None:
cfg = kettle.config.copy() cfg = kettle.config.copy()
cfg.update(dict(api=cbpi, kettle_id=kettle.id, heater=kettle.heater, sensor=kettle.sensor))
cfg.update(dict(api=self.cbpi, kettle_id=kettle.id, heater=kettle.heater, sensor=kettle.sensor))
instance = self.get_controller(kettle.logic).get("class")(**cfg) instance = self.get_controller(kettle.logic).get("class")(**cfg)
instance.init() instance.init()
kettle.instance = instance kettle.instance = instance
@@ -256,13 +258,13 @@ class BrewingCore(object):
t = self.cbpi._socketio.start_background_task(target=run, instance=instance) t = self.cbpi._socketio.start_background_task(target=run, instance=instance)
kettle.state = not kettle.state kettle.state = not kettle.state
self.cbpi.ws_emit("UPDATE_KETTLE", cbpi.cache.get("kettle").get(id))
self.cbpi.ws_emit("UPDATE_KETTLE", self.cbpi.cache.get("kettle").get(id))
self.cbpi.emit("KETTLE_CONTROLLER_STARTED", id=id) self.cbpi.emit("KETTLE_CONTROLLER_STARTED", id=id)
else: else:
# Stop controller # Stop controller
kettle.instance.stop() kettle.instance.stop()
kettle.state = not kettle.state kettle.state = not kettle.state
self.cbpi.ws_emit("UPDATE_KETTLE", cbpi.cache.get("kettle").get(id))
self.cbpi.ws_emit("UPDATE_KETTLE", self.cbpi.cache.get("kettle").get(id))
self.cbpi.emit("KETTLE_CONTROLLER_STOPPED", id=id) self.cbpi.emit("KETTLE_CONTROLLER_STOPPED", id=id)
@@ -285,6 +287,7 @@ class CraftBeerPI(object):
#logging.basicConfig(filename='./logs/app.log', level=logging.INFO, format=FORMAT) #logging.basicConfig(filename='./logs/app.log', level=logging.INFO, format=FORMAT)
logging.config.dictConfig(yaml.load(open('./config/logger.yaml', 'r'))) logging.config.dictConfig(yaml.load(open('./config/logger.yaml', 'r')))
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
self.logger.info("Logger got initialized.")
self.cache["messages"] = [] self.cache["messages"] = []
self.cache["version"] = "3.1" self.cache["version"] = "3.1"
@@ -399,6 +402,5 @@ class CraftBeerPI(object):
self.logger.error(e) self.logger.error(e)
self.notify("Failed to load plugin %s " % filename, str(e), type="danger", timeout=None) self.notify("Failed to load plugin %s " % filename, str(e), type="danger", timeout=None)
cbpi = CraftBeerPI() cbpi = CraftBeerPI()
addon = cbpi.addon
addon = cbpi.addon

+ 0
- 6
run.py 查看文件

@@ -1,12 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python


from modules.core.core import * from modules.core.core import *

cbpi = CraftBeerPI()

addon = cbpi.addon


from modules.core.db_migrate import * from modules.core.db_migrate import *
from modules.buzzer import * from modules.buzzer import *
from modules.config import * from modules.config import *


正在加载...
取消
保存