2022-01-02 11:25:56 +01:00
import os , threading , time , shutil
2021-07-15 07:16:26 +02:00
from aiohttp import web
import logging
from unittest . mock import MagicMock , patch
import asyncio
import random
2022-01-02 11:25:56 +01:00
import json
2021-07-15 07:16:26 +02:00
from cbpi . api import *
from cbpi . api . config import ConfigType
from cbpi . api . base import CBPiBase
2023-04-08 12:26:10 +02:00
from cbpi import __version__
2021-07-15 07:16:26 +02:00
logger = logging . getLogger ( __name__ )
class ConfigUpdate ( CBPiExtension ) :
def __init__ ( self , cbpi ) :
self . cbpi = cbpi
self . _task = asyncio . create_task ( self . run ( ) )
async def run ( self ) :
logging . info ( " Check Config for required changes " )
# check is default steps are config parameters
TEMP_UNIT = self . cbpi . config . get ( " TEMP_UNIT " , " C " )
default_boil_temp = 99 if TEMP_UNIT == " C " else 212
default_cool_temp = 20 if TEMP_UNIT == " C " else 68
boil_temp = self . cbpi . config . get ( " steps_boil_temp " , None )
cooldown_sensor = self . cbpi . config . get ( " steps_cooldown_sensor " , None )
2022-01-28 07:56:24 +01:00
cooldown_actor = self . cbpi . config . get ( " steps_cooldown_actor " , None )
2021-07-15 07:16:26 +02:00
cooldown_temp = self . cbpi . config . get ( " steps_cooldown_temp " , None )
mashin_step = self . cbpi . config . get ( " steps_mashin " , None )
mash_step = self . cbpi . config . get ( " steps_mash " , None )
mashout_step = self . cbpi . config . get ( " steps_mashout " , None )
boil_step = self . cbpi . config . get ( " steps_boil " , None )
cooldown_step = self . cbpi . config . get ( " steps_cooldown " , None )
2021-08-11 17:12:13 +02:00
max_dashboard_number = self . cbpi . config . get ( " max_dashboard_number " , None )
2021-08-18 21:55:56 +02:00
current_dashboard_number = self . cbpi . config . get ( " current_dashboard_number " , None )
2021-12-14 07:20:22 +01:00
logfiles = self . cbpi . config . get ( " CSVLOGFILES " , None )
influxdb = self . cbpi . config . get ( " INFLUXDB " , None )
influxdbaddr = self . cbpi . config . get ( " INFLUXDBADDR " , None )
influxdbname = self . cbpi . config . get ( " INFLUXDBNAME " , None )
influxdbuser = self . cbpi . config . get ( " INFLUXDBUSER " , None )
influxdbpwd = self . cbpi . config . get ( " INFLUXDBPWD " , None )
2022-02-04 20:48:55 +01:00
influxdbcloud = self . cbpi . config . get ( " INFLUXDBCLOUD " , None )
2023-04-21 07:29:05 +02:00
influxdbport = self . cbpi . config . get ( " INFLUXDBPORT " , None )
2023-01-20 17:31:23 +01:00
influxdbmeasurement = self . cbpi . config . get ( " INFLUXDBMEASUREMENT " , None )
2022-01-31 17:17:53 +01:00
mqttupdate = self . cbpi . config . get ( " MQTTUpdate " , None )
2022-04-03 12:37:34 +02:00
PRESSURE_UNIT = self . cbpi . config . get ( " PRESSURE_UNIT " , None )
2022-07-19 21:03:17 +02:00
SENSOR_LOG_BACKUP_COUNT = self . cbpi . config . get ( " SENSOR_LOG_BACKUP_COUNT " , None )
SENSOR_LOG_MAX_BYTES = self . cbpi . config . get ( " SENSOR_LOG_MAX_BYTES " , None )
2022-07-21 10:27:54 +02:00
slow_pipe_animation = self . cbpi . config . get ( " slow_pipe_animation " , None )
2022-12-02 20:05:30 +01:00
NOTIFY_ON_ERROR = self . cbpi . config . get ( " NOTIFY_ON_ERROR " , None )
2023-03-18 16:05:13 +01:00
PLAY_BUZZER = self . cbpi . config . get ( " PLAY_BUZZER " , None )
2023-02-07 19:34:58 +01:00
BoilAutoTimer = self . cbpi . config . get ( " BoilAutoTimer " , None )
2023-04-02 16:14:33 +02:00
MASH_TUN = self . cbpi . config . get ( " MASH_TUN " , None )
AutoMode = self . cbpi . config . get ( " AutoMode " , None )
AddMashIn = self . cbpi . config . get ( " AddMashInStep " , None )
bfuserid = self . cbpi . config . get ( " brewfather_user_id " , None )
bfapikey = self . cbpi . config . get ( " brewfather_api_key " , None )
RecipeCreationPath = self . cbpi . config . get ( " RECIPE_CREATION_PATH " , None )
BoilKettle = self . cbpi . config . get ( " BoilKettle " , None )
CONFIG_STATUS = self . cbpi . config . get ( " CONFIG_STATUS " , None )
2023-04-08 12:26:10 +02:00
self . version = __version__
2023-04-02 16:14:33 +02:00
2021-07-15 07:16:26 +02:00
if boil_temp is None :
logger . info ( " INIT Boil Temp Setting " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_boil_temp " , default_boil_temp , type = ConfigType . NUMBER , description = " Default Boil Temperature for Recipe Creation " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_boil_temp " , boil_temp , type = ConfigType . NUMBER , description = " Default Boil Temperature for Recipe Creation " , source = " steps " )
2021-07-15 07:16:26 +02:00
if cooldown_sensor is None :
logger . info ( " INIT Cooldown Sensor Setting " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown_sensor " , " " , type = ConfigType . SENSOR , description = " Alternative Sensor to monitor temperature durring cooldown (if not selected, Kettle Sensor will be used) " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown_sensor " , cooldown_sensor , type = ConfigType . SENSOR , description = " Alternative Sensor to monitor temperature durring cooldown (if not selected, Kettle Sensor will be used) " , source = " steps " )
2021-07-15 07:16:26 +02:00
2022-01-28 07:56:24 +01:00
if cooldown_actor is None :
logger . info ( " INIT Cooldown Actor Setting " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown_actor " , " " , type = ConfigType . ACTOR , description = " Actor to trigger cooldown water on and off (default: None) " , source = " steps " )
2022-01-28 07:56:24 +01:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown_actor " , cooldown_actor , type = ConfigType . ACTOR , description = " Actor to trigger cooldown water on and off (default: None) " , source = " steps " )
2022-01-28 07:56:24 +01:00
2021-07-15 07:16:26 +02:00
if cooldown_temp is None :
logger . info ( " INIT Cooldown Temp Setting " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown_temp " , default_cool_temp , type = ConfigType . NUMBER , description = " Cooldown temp will send notification when this temeprature is reached " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown_temp " , cooldown_temp , type = ConfigType . NUMBER , description = " Cooldown temp will send notification when this temeprature is reached " , source = " steps " )
2021-07-15 07:16:26 +02:00
if cooldown_step is None :
logger . info ( " INIT Cooldown Step Type " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown " , " " , type = ConfigType . STEP , description = " Cooldown step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_cooldown " , cooldown_step , type = ConfigType . STEP , description = " Cooldown step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
if mashin_step is None :
logger . info ( " INIT MashIn Step Type " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_mashin " , " " , type = ConfigType . STEP , description = " MashIn step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_mashin " , mashin_step , type = ConfigType . STEP , description = " MashIn step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
if mash_step is None :
logger . info ( " INIT Mash Step Type " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_mash " , " " , type = ConfigType . STEP , description = " Mash step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_mash " , mash_step , type = ConfigType . STEP , description = " Mash step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
if mashout_step is None :
logger . info ( " INIT MashOut Step Type " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_mashout " , " " , type = ConfigType . STEP , description = " MashOut step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_mashout " , mashout_step , type = ConfigType . STEP , description = " MashOut step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
if boil_step is None :
logger . info ( " INIT Boil Step Type " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_boil " , " " , type = ConfigType . STEP , description = " Boil step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " steps_boil " , boil_step , type = ConfigType . STEP , description = " Boil step type " , source = " steps " )
2021-07-15 07:16:26 +02:00
2021-08-11 17:12:13 +02:00
if max_dashboard_number is None :
logger . info ( " INIT Max Dashboard Numbers for multiple dashboards " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " max_dashboard_number " , 4 , type = ConfigType . SELECT , description = " Max Number of Dashboards " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " 1 " , " value " : 1 } ,
2021-08-11 17:12:13 +02:00
{ " label " : " 2 " , " value " : 2 } ,
{ " label " : " 3 " , " value " : 3 } ,
{ " label " : " 4 " , " value " : 4 } ,
{ " label " : " 5 " , " value " : 5 } ,
{ " label " : " 6 " , " value " : 6 } ,
{ " label " : " 7 " , " value " : 7 } ,
{ " label " : " 8 " , " value " : 8 } ,
{ " label " : " 9 " , " value " : 9 } ,
{ " label " : " 10 " , " value " : 10 } ] )
2023-04-16 17:22:33 +02:00
2021-08-11 17:12:13 +02:00
except :
logger . warning ( ' Unable to update database ' )
2021-08-18 21:55:56 +02:00
if current_dashboard_number is None :
logger . info ( " INIT Current Dashboard Number " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " current_dashboard_number " , 1 , type = ConfigType . NUMBER , description = " Number of current Dashboard " , source = " hidden " )
2021-08-18 21:55:56 +02:00
except :
logger . warning ( ' Unable to update database ' )
2023-04-02 16:32:10 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:32:10 +02:00
await self . cbpi . config . add ( " current_dashboard_number " , current_dashboard_number , type = ConfigType . NUMBER , description = " Number of current Dashboard " , source = " hidden " )
2021-08-18 21:55:56 +02:00
2021-08-11 17:12:13 +02:00
## Check if AtuoMode for Steps is in config
2023-04-02 16:14:33 +02:00
2021-07-15 07:16:26 +02:00
if AutoMode is None :
logger . info ( " INIT AutoMode " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " AutoMode " , " Yes " , type = ConfigType . SELECT , description = " Use AutoMode in steps " ,
2023-04-16 17:22:33 +02:00
source = " steps " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2021-07-15 07:16:26 +02:00
{ " label " : " No " , " value " : " No " } ] )
2023-04-16 17:22:33 +02:00
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " AutoMode " , AutoMode , type = ConfigType . SELECT , description = " Use AutoMode in steps " ,
source = " steps " ,
options = [ { " label " : " Yes " , " value " : " Yes " } ,
{ " label " : " No " , " value " : " No " } ] )
2021-07-15 07:16:26 +02:00
## Check if AddMashInStep for Steps is in config
2023-04-02 16:14:33 +02:00
2021-07-15 07:16:26 +02:00
if AddMashIn is None :
logger . info ( " INIT AddMashInStep " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " AddMashInStep " , " Yes " , type = ConfigType . SELECT , description = " Add MashIn Step automatically if not defined in recipe " ,
2023-04-16 17:22:33 +02:00
source = " steps " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2021-07-15 07:16:26 +02:00
{ " label " : " No " , " value " : " No " } ] )
2023-04-16 17:22:33 +02:00
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " AddMashInStep " , AddMashIn , type = ConfigType . SELECT , description = " Add MashIn Step automatically if not defined in recipe " ,
2023-04-16 17:22:33 +02:00
source = " steps " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2023-04-16 17:22:33 +02:00
{ " label " : " No " , " value " : " No " } ] )
2021-07-15 07:16:26 +02:00
## Check if Brewfather UserID is in config
2023-04-02 16:14:33 +02:00
2021-07-15 07:16:26 +02:00
if bfuserid is None :
logger . info ( " INIT Brewfather User ID " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " brewfather_user_id " , " " , type = ConfigType . STRING , description = " Brewfather User ID " , source = " craftbeerpi " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update config ' )
## Check if Brewfather API Key is in config
2023-04-02 16:14:33 +02:00
2021-07-15 07:16:26 +02:00
if bfapikey is None :
logger . info ( " INIT Brewfather API Key " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " brewfather_api_key " , " " , type = ConfigType . STRING , description = " Brewfather API Key " , source = " craftbeerpi " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update config ' )
## Check if Brewfather API Key is in config
2023-04-02 16:14:33 +02:00
2021-07-15 07:16:26 +02:00
if RecipeCreationPath is None :
logger . info ( " INIT Recipe Creation Path " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " RECIPE_CREATION_PATH " , " upload " , type = ConfigType . STRING , description = " API path to creation plugin. Default: upload . CHANGE ONLY IF USING A RECIPE CREATION PLUGIN " , source = " craftbeerpi " )
2021-07-15 07:16:26 +02:00
except :
logger . warning ( ' Unable to update config ' )
2021-09-21 18:06:23 +02:00
## Check if Kettle for Boil, Whirlpool and Cooldown is in config
2023-04-02 16:14:33 +02:00
2021-09-21 18:06:23 +02:00
if BoilKettle is None :
logger . info ( " INIT BoilKettle " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " BoilKettle " , " " , type = ConfigType . KETTLE , description = " Define Kettle that is used for Boil, Whirlpool and Cooldown. If not selected, MASH_TUN will be used " , source = " steps " )
2021-09-21 18:06:23 +02:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " BoilKettle " , BoilKettle , type = ConfigType . KETTLE , description = " Define Kettle that is used for Boil, Whirlpool and Cooldown. If not selected, MASH_TUN will be used " , source = " steps " )
if MASH_TUN is None :
logger . info ( " INIT MASH_TUN " )
try :
await self . cbpi . config . add ( " MASH_TUN " , " " , type = ConfigType . KETTLE , description = " Default Mash Tun " , source = " steps " )
2021-09-21 18:06:23 +02:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " MASH_TUN " , MASH_TUN , type = ConfigType . KETTLE , description = " Default Mash Tun " , source = " steps " )
2021-09-21 18:06:23 +02:00
2021-12-14 07:20:22 +01:00
## Check if CSV logfiles is on config
if logfiles is None :
logger . info ( " INIT CSV logfiles " )
try :
2023-05-14 14:16:18 +02:00
await self . cbpi . config . add ( " CSVLOGFILES " , " Yes " , type = ConfigType . SELECT , description = " Write sensor data to csv logfiles (enabling requires restart) " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2021-12-14 07:20:22 +01:00
{ " label " : " No " , " value " : " No " } ] )
except :
logger . warning ( ' Unable to update config ' )
2023-05-17 21:52:53 +02:00
else :
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
try :
await self . cbpi . config . add ( " CSVLOGFILES " , logfiles , type = ConfigType . SELECT , description = " Write sensor data to csv logfiles (enabling requires restart) " ,
source = " craftbeerpi " ,
options = [ { " label " : " Yes " , " value " : " Yes " } ,
{ " label " : " No " , " value " : " No " } ] )
except :
logger . warning ( ' Unable to update config ' )
2021-12-14 07:20:22 +01:00
2022-02-04 20:48:55 +01:00
## Check if influxdb is on config
2021-12-14 07:20:22 +01:00
if influxdb is None :
logger . info ( " INIT Influxdb " )
try :
2023-05-14 14:16:18 +02:00
await self . cbpi . config . add ( " INFLUXDB " , " No " , type = ConfigType . SELECT , description = " Write sensor data to influxdb (enabling requires restart) " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2021-12-14 07:20:22 +01:00
{ " label " : " No " , " value " : " No " } ] )
except :
logger . warning ( ' Unable to update config ' )
2023-05-17 21:52:53 +02:00
else :
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
try :
await self . cbpi . config . add ( " INFLUXDB " , influxdb , type = ConfigType . SELECT , description = " Write sensor data to influxdb (enabling requires restart) " ,
source = " craftbeerpi " ,
options = [ { " label " : " Yes " , " value " : " Yes " } ,
{ " label " : " No " , " value " : " No " } ] )
except :
logger . warning ( ' Unable to update config ' )
2023-04-21 07:29:05 +02:00
## Check if influxdbport is in config and remove it as it is obsolete
if influxdbport is not None :
logger . warning ( " Remove obsolete Influxdbport config parameter " )
try :
await self . cbpi . config . remove ( " INFLUXDBPORT " )
except :
logger . warning ( ' Unable to update config ' )
2021-12-14 07:20:22 +01:00
## Check if influxdbaddr is in config
if influxdbaddr is None :
logger . info ( " INIT Influxdbaddr " )
try :
2023-04-21 07:29:05 +02:00
await self . cbpi . config . add ( " INFLUXDBADDR " , " http://localhost:8086 " , type = ConfigType . STRING , description = " URL Address of your influxdb server incl. http:// and port, e.g. http://localhost:8086 (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server) " , source = " craftbeerpi " )
2021-12-14 07:20:22 +01:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-21 07:29:05 +02:00
else :
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
try :
await self . cbpi . config . add ( " INFLUXDBADDR " , influxdbaddr , type = ConfigType . STRING , description = " URL Address of your influxdb server incl. http:// and port, e.g. http://localhost:8086 (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server) " , source = " craftbeerpi " )
except :
logger . warning ( ' Unable to update config ' )
2021-12-14 07:20:22 +01:00
## Check if influxdbname is in config
if influxdbname is None :
logger . info ( " INIT Influxdbname " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " INFLUXDBNAME " , " cbpi4 " , type = ConfigType . STRING , description = " Name of your influxdb database name (If INFLUXDBCLOUD set to Yes use bucket of your influxdb cloud database) " , source = " craftbeerpi " )
2021-12-14 07:20:22 +01:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-21 07:29:05 +02:00
else :
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
try :
await self . cbpi . config . add ( " INFLUXDBNAME " , influxdbname , type = ConfigType . STRING , description = " Name of your influxdb database name (If INFLUXDBCLOUD set to Yes use bucket of your influxdb cloud database) " , source = " craftbeerpi " )
except :
logger . warning ( ' Unable to update config ' )
2021-12-14 07:20:22 +01:00
2022-02-04 20:48:55 +01:00
## Check if influxduser is in config
2021-12-14 07:20:22 +01:00
if influxdbuser is None :
logger . info ( " INIT Influxdbuser " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " INFLUXDBUSER " , " " , type = ConfigType . STRING , description = " User name for your influxdb database (only if required)(If INFLUXDBCLOUD set to Yes use organisation of your influxdb cloud database) " , source = " craftbeerpi " )
2021-12-14 07:20:22 +01:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-21 07:29:05 +02:00
else :
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
try :
await self . cbpi . config . add ( " INFLUXDBUSER " , influxdbuser , type = ConfigType . STRING , description = " User Name for your influxdb database (only if required)(If INFLUXDBCLOUD set to Yes use organisation of your influxdb cloud database) " , source = " craftbeerpi " )
except :
logger . warning ( ' Unable to update config ' )
2021-12-14 07:20:22 +01:00
2022-02-04 20:48:55 +01:00
## Check if influxdpwd is in config
2021-12-14 07:20:22 +01:00
if influxdbpwd is None :
logger . info ( " INIT Influxdbpwd " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " INFLUXDBPWD " , " " , type = ConfigType . STRING , description = " Password for your influxdb database (only if required)(If INFLUXDBCLOUD set to Yes use token of your influxdb cloud database) " , source = " craftbeerpi " )
2022-02-04 20:48:55 +01:00
except :
logger . warning ( ' Unable to update config ' )
2023-04-21 07:29:05 +02:00
else :
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
try :
await self . cbpi . config . add ( " INFLUXDBPWD " , influxdbpwd , type = ConfigType . STRING , description = " Password for your influxdb database (only if required)(If INFLUXDBCLOUD set to Yes use token of your influxdb cloud database) " , source = " craftbeerpi " )
except :
logger . warning ( ' Unable to update config ' )
2022-02-04 20:48:55 +01:00
## Check if influxdb cloud is on config
if influxdbcloud is None :
logger . info ( " INIT influxdbcloud " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " INFLUXDBCLOUD " , " No " , type = ConfigType . SELECT , description = " Write sensor data to influxdb cloud (INFLUXDB must set to Yes) " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2022-02-04 20:48:55 +01:00
{ " label " : " No " , " value " : " No " } ] )
2021-12-14 07:20:22 +01:00
except :
logger . warning ( ' Unable to update config ' )
2021-07-15 07:16:26 +02:00
2023-01-20 17:31:23 +01:00
## Check if influxdbname is in config
if influxdbmeasurement is None :
logger . info ( " INIT Influxdb measurementname " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " INFLUXDBMEASUREMENT " , " measurement " , type = ConfigType . STRING , description = " Name of the measurement in your INFLUXDB database (default: measurement) " , source = " craftbeerpi " )
2023-01-20 17:31:23 +01:00
except :
logger . warning ( ' Unable to update config ' )
2022-01-31 17:17:53 +01:00
if mqttupdate is None :
logger . info ( " INIT MQTT update frequency for Kettles and Fermenters " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " MQTTUpdate " , 0 , type = ConfigType . SELECT , description = " Forced MQTT Update frequency in s for Kettle and Fermenter (no changes in payload required). Restart required after change " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " 30 " , " value " : 30 } ,
2022-01-31 17:17:53 +01:00
{ " label " : " 60 " , " value " : 60 } ,
{ " label " : " 120 " , " value " : 120 } ,
{ " label " : " 300 " , " value " : 300 } ,
{ " label " : " Never " , " value " : 0 } ] )
except :
logger . warning ( ' Unable to update database ' )
2022-04-03 12:37:34 +02:00
## Check if PRESSURE_UNIT is in config
if PRESSURE_UNIT is None :
logger . info ( " INIT PRESSURE_UNIT " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " PRESSURE_UNIT " , " kPa " , type = ConfigType . SELECT , description = " Set unit for pressure " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " kPa " , " value " : " kPa " } ,
2022-04-03 12:37:34 +02:00
{ " label " : " PSI " , " value " : " PSI " } ] )
except :
logger . warning ( ' Unable to update config ' )
2022-07-19 09:39:27 +02:00
# check if SENSOR_LOG_BACKUP_COUNT exists in config
if SENSOR_LOG_BACKUP_COUNT is None :
logger . info ( " INIT SENSOR_LOG_BACKUP_COUNT " )
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " SENSOR_LOG_BACKUP_COUNT " , 3 , type = ConfigType . NUMBER , description = " Max. number of backup logs " , source = " craftbeerpi " )
2022-07-19 09:39:27 +02:00
except :
logger . warning ( ' Unable to update database ' )
# check if SENSOR_LOG_MAX_BYTES exists in config
if SENSOR_LOG_MAX_BYTES is None :
2022-07-19 18:27:10 +02:00
logger . info ( " Init maximum size of sensor logfiles " )
2022-07-19 09:39:27 +02:00
try :
2023-04-16 17:22:33 +02:00
await self . cbpi . config . add ( " SENSOR_LOG_MAX_BYTES " , 100000 , type = ConfigType . NUMBER , description = " Max. number of bytes in sensor logs " , source = " craftbeerpi " )
2022-07-19 09:39:27 +02:00
except :
logger . warning ( ' Unable to update database ' )
2022-07-21 10:27:54 +02:00
# Check if slow_pipe_animation is in config
if slow_pipe_animation is None :
logger . info ( " INIT slow_pipe_animation " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " slow_pipe_animation " , " Yes " , type = ConfigType . SELECT , description = " Slow down dashboard pipe animation taking up close to 100 % o f the CPU ' s capacity " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2022-07-21 10:27:54 +02:00
{ " label " : " No " , " value " : " No " } ] )
except :
logger . warning ( ' Unable to update config ' )
2022-12-02 20:05:30 +01:00
## Check if NOTIFY_ON_ERROR is in config
if NOTIFY_ON_ERROR is None :
logger . info ( " INIT NOTIFY_ON_ERROR " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " NOTIFY_ON_ERROR " , " No " , type = ConfigType . SELECT , description = " Send Notification on Logging Error " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2022-12-02 20:05:30 +01:00
{ " label " : " No " , " value " : " No " } ] )
2023-03-18 16:05:13 +01:00
except :
logger . warning ( ' Unable to update config ' )
## Check if PLAY_BUZZER is in config
if PLAY_BUZZER is None :
logger . info ( " INIT PLAY_BUZZER " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( " PLAY_BUZZER " , " No " , type = ConfigType . SELECT , description = " Play buzzer sound in Web interface on Notifications " ,
2023-04-16 17:22:33 +02:00
source = " craftbeerpi " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2023-03-18 16:05:13 +01:00
{ " label " : " No " , " value " : " No " } ] )
2022-12-02 20:05:30 +01:00
except :
logger . warning ( ' Unable to update config ' )
2023-02-07 19:34:58 +01:00
if BoilAutoTimer is None :
logging . info ( " INIT BoilAutoTimer " )
try :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( ' BoilAutoTimer ' , ' No ' , type = ConfigType . SELECT ,
2023-04-16 17:22:33 +02:00
description = ' Start Boil timer automatically if Temp does not change for 5 Minutes and is above 95C/203F ' ,
source = " steps " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2023-02-07 19:34:58 +01:00
{ " label " : " No " , " value " : " No " } ] )
2023-04-16 17:22:33 +02:00
2023-02-07 19:34:58 +01:00
BoilAutoTimer = self . cbpi . config . get ( " BoilAutoTimer " , " No " )
except :
logging . warning ( ' Unable to update database ' )
2023-04-02 16:14:33 +02:00
else :
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
await self . cbpi . config . add ( ' BoilAutoTimer ' , BoilAutoTimer , type = ConfigType . SELECT ,
description = ' Start Boil timer automatically if Temp does not change for 5 Minutes and is above 95C/203F ' ,
2023-04-16 17:22:33 +02:00
source = " steps " ,
2023-04-02 16:14:33 +02:00
options = [ { " label " : " Yes " , " value " : " Yes " } ,
2023-04-16 17:22:33 +02:00
{ " label " : " No " , " value " : " No " } ] )
2023-04-02 16:14:33 +02:00
## Check if influxdbname is in config
2023-04-08 12:26:10 +02:00
if CONFIG_STATUS is None or CONFIG_STATUS != self . version :
2023-04-02 16:14:33 +02:00
logger . warning ( " Setting Config Status " )
try :
2023-04-08 12:26:10 +02:00
await self . cbpi . config . add ( " CONFIG_STATUS " , self . version , type = ConfigType . STRING , description = " Status of the config file. Internal use for maintenance " , source = " hidden " )
2023-04-02 16:14:33 +02:00
except :
logger . warning ( ' Unable to update config ' )
2023-02-07 19:34:58 +01:00
2021-07-15 07:16:26 +02:00
def setup ( cbpi ) :
cbpi . plugin . register ( " ConfigUpdate " , ConfigUpdate )
pass