2021-02-10 07:38:55 +01:00
|
|
|
from abc import abstractmethod, ABCMeta
|
|
|
|
import asyncio
|
|
|
|
from cbpi.api.config import ConfigType
|
|
|
|
import time
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
class CBPiBase(metaclass=ABCMeta):
|
|
|
|
|
|
|
|
def get_static_config_value(self,name,default):
|
|
|
|
return self.cbpi.static_config.get(name, default)
|
|
|
|
|
|
|
|
def get_config_value(self,name,default):
|
|
|
|
return self.cbpi.config.get(name, default=default)
|
|
|
|
|
|
|
|
async def set_config_value(self,name,value):
|
|
|
|
return await self.cbpi.config.set(name,value)
|
|
|
|
|
|
|
|
async def add_config_value(self, name, value, type: ConfigType, description, options=None):
|
2021-02-12 11:13:32 +01:00
|
|
|
await self.cbpi.config.add(name, value, type, description, options=None)
|
2021-02-10 07:38:55 +01:00
|
|
|
|
|
|
|
def get_kettle(self,id):
|
|
|
|
return self.cbpi.kettle.find_by_id(id)
|
|
|
|
|
2021-02-10 22:11:35 +01:00
|
|
|
def get_kettle_target_temp(self,id):
|
2021-02-16 20:37:51 +01:00
|
|
|
return self.cbpi.kettle.find_by_id(id).target_temp
|
2021-02-10 22:11:35 +01:00
|
|
|
|
2021-02-10 07:38:55 +01:00
|
|
|
async def set_target_temp(self,id, temp):
|
|
|
|
await self.cbpi.kettle.set_target_temp(id, temp)
|
|
|
|
|
2022-01-02 11:25:56 +01:00
|
|
|
def get_fermenter(self,id):
|
|
|
|
return self.cbpi.fermenter._find_by_id(id)
|
|
|
|
|
|
|
|
def get_fermenter_target_temp(self,id):
|
|
|
|
return self.cbpi.fermenter._find_by_id(id).target_temp
|
|
|
|
|
|
|
|
async def set_fermenter_target_temp(self,id, temp):
|
|
|
|
await self.cbpi.fermenter.set_target_temp(id, temp)
|
|
|
|
|
2021-02-10 07:38:55 +01:00
|
|
|
def get_sensor(self,id):
|
|
|
|
return self.cbpi.sensor.find_by_id(id)
|
|
|
|
|
|
|
|
def get_sensor_value(self,id):
|
2021-02-16 20:37:51 +01:00
|
|
|
|
2021-02-10 07:38:55 +01:00
|
|
|
return self.cbpi.sensor.get_sensor_value(id)
|
|
|
|
|
|
|
|
def get_actor(self,id):
|
|
|
|
return self.cbpi.actor.find_by_id(id)
|
|
|
|
|
|
|
|
def get_actor_state(self,id):
|
|
|
|
try:
|
|
|
|
actor = self.cbpi.actor.find_by_id(id)
|
|
|
|
return actor.get("instance").get_state()
|
|
|
|
except:
|
2021-11-08 14:04:28 +01:00
|
|
|
logging.error("Failed to read actor state in step - actor {}".format(id))
|
2021-02-10 07:38:55 +01:00
|
|
|
return None
|
|
|
|
|
2021-11-11 11:22:13 +01:00
|
|
|
async def actor_on(self,id,power=100):
|
2021-02-10 07:38:55 +01:00
|
|
|
|
|
|
|
try:
|
2021-11-11 11:22:13 +01:00
|
|
|
await self.cbpi.actor.on(id,power)
|
2021-02-10 07:38:55 +01:00
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def actor_off(self,id):
|
|
|
|
try:
|
|
|
|
await self.cbpi.actor.off(id)
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
2021-11-08 14:04:28 +01:00
|
|
|
async def actor_set_power(self,id,power):
|
|
|
|
try:
|
|
|
|
await self.cbpi.actor.set_power(id,power)
|
|
|
|
except Exception as e:
|
|
|
|
pass
|