2021-01-22 23:25:20 +01:00
|
|
|
from cbpi.controller.basic_controller import BasicController
|
2019-07-27 21:08:19 +02:00
|
|
|
import logging
|
2021-01-22 23:25:20 +01:00
|
|
|
from tabulate import tabulate
|
|
|
|
class KettleController(BasicController):
|
2018-11-18 15:40:10 +01:00
|
|
|
|
|
|
|
def __init__(self, cbpi):
|
2021-01-22 23:25:20 +01:00
|
|
|
super(KettleController, self).__init__(cbpi, "kettle.json")
|
2021-01-24 22:14:57 +01:00
|
|
|
self.update_key = "kettleupdate"
|
2021-01-22 23:25:20 +01:00
|
|
|
self.autostart = False
|
2018-11-18 23:09:17 +01:00
|
|
|
|
2021-01-22 23:25:20 +01:00
|
|
|
async def on(self, id):
|
|
|
|
try:
|
|
|
|
item = self.find_by_id(id)
|
|
|
|
instance = item.get("instance")
|
|
|
|
await instance.start()
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Faild to switch on KettleLogic {} {}".format(id, e))
|
|
|
|
|
|
|
|
async def off(self, id):
|
|
|
|
try:
|
|
|
|
item = self.find_by_id(id)
|
|
|
|
instance = item.get("instance")
|
|
|
|
await instance.stop()
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Faild to switch on KettleLogic {} {}".format(id, e))
|
|
|
|
|
|
|
|
async def set_target_temp(self, id, target_temp):
|
|
|
|
try:
|
|
|
|
item = self.find_by_id(id)
|
|
|
|
item["target_temp"] = target_temp
|
|
|
|
await self.save()
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Faild to set Target Temp {} {}".format(id, e))
|
|
|
|
|
|
|
|
def create_dict(self, data):
|
|
|
|
try:
|
|
|
|
instance = data.get("instance")
|
|
|
|
state = dict(state=instance.get_state())
|
|
|
|
except Exception as e:
|
|
|
|
logging.error("Faild to create KettleLogic dict {} ".format(e))
|
|
|
|
state = dict()
|
|
|
|
return dict(name=data.get("name"), id=data.get("id"), type=data.get("type"), sensor=data.get("sensor"), heater=data.get("heater"), agitator=data.get("agitator"), target_temp=data.get("target_temp"), state=state,props=data.get("props", []))
|