craftbeerpi4-pione/cbpi/controller/kettle_controller.py

45 lines
1.6 KiB
Python
Raw Normal View History

2021-02-16 20:37:51 +01:00
from cbpi.api.dataclasses import Kettle, Props
from cbpi.controller.basic_controller2 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-02-16 20:37:51 +01:00
super(KettleController, self).__init__(cbpi, Kettle, "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
2021-02-16 20:37:51 +01:00
def create(self, data):
return Kettle(data.get("id"), data.get("name"), type=data.get("type"), props=Props(data.get("props", {})), sensor=data.get("sensor"), heater=data.get("heater"), agitator=data.get("agitator"))
2021-01-30 22:29:33 +01:00
async def toggle(self, id):
2021-02-16 20:37:51 +01:00
2021-01-30 22:29:33 +01:00
try:
item = self.find_by_id(id)
2021-02-16 20:37:51 +01:00
if item.instance is None or item.instance.state == False:
2021-01-30 22:29:33 +01:00
await self.start(id)
else:
2021-02-16 20:37:51 +01:00
await item.instance.stop()
2021-01-30 22:29:33 +01:00
await self.push_udpate()
2021-01-22 23:25:20 +01:00
except Exception as e:
2021-11-20 11:13:51 +01:00
logging.error("Failed to switch on KettleLogic {} {}".format(id, e))
2021-01-22 23:25:20 +01:00
async def set_target_temp(self, id, target_temp):
try:
item = self.find_by_id(id)
2021-02-16 20:37:51 +01:00
item.target_temp = target_temp
2021-01-22 23:25:20 +01:00
await self.save()
except Exception as e:
2021-11-20 11:13:51 +01:00
logging.error("Failed to set Target Temp {} {}".format(id, e))
2021-01-22 23:25:20 +01:00
2021-11-20 11:13:51 +01:00
async def stop(self, id):
try:
logging.info("Stop Kettle {}".format(id))
2021-11-20 11:13:51 +01:00
item = self.find_by_id(id)
if item.instance:
await item.instance.stop()
2021-11-20 11:13:51 +01:00
await self.push_udpate()
except Exception as e:
logging.error("Failed to switch off KettleLogic {} {}".format(id, e))