fixed bug in parameter generation -> source | options order

This commit is contained in:
avollkopf 2023-04-16 17:22:33 +02:00
parent f990e0e0a3
commit 1d6cd75f8c
8 changed files with 136 additions and 38 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.1.8.a11"
__version__ = "4.1.8.a12"
__codename__ = "Groundhog Day"

View file

@ -21,7 +21,7 @@ class CBPiBase(metaclass=ABCMeta):
return await self.cbpi.config.remove(name)
async def add_config_value(self, name, value, type: ConfigType, description, source, options=None):
await self.cbpi.config.add(name, value, type, description, source,options=None)
await self.cbpi.config.add(name, value, type, description, source, options=None)
def get_kettle(self,id):
return self.cbpi.kettle.find_by_id(id)

View file

@ -204,7 +204,7 @@ class Config:
def __str__(self):
return "....name={} value={}".format(self.name, self.value)
def to_dict(self):
return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, options=self.options, source=self.source)
return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, source=self.source, options=self.options)
@dataclass
class NotificationAction:

View file

@ -30,7 +30,8 @@ class ConfigController:
with open(self.path) as json_file:
data = json.load(json_file)
for key, value in data.items():
self.cache[key] = Config(name=value.get("name"), value=value.get("value"), description=value.get("description"), type=ConfigType(value.get("type", "string")), options=value.get("options", None), source=value.get("source", "craftbeerpi") )
self.cache[key] = Config(name=value.get("name"), value=value.get("value"), description=value.get("description"), type=ConfigType(value.get("type", "string")), source=value.get("source", "craftbeerpi"), options=value.get("options", None))
logging.error(self.cache)
def get(self, name, default=None):
self.logger.debug("GET CONFIG VALUE %s (default %s)" % (name, default))
@ -78,7 +79,7 @@ class ConfigController:
json.dump(data, file, indent=4, sort_keys=True)
self.cache=self.testcache
async def remove_obsolete(self):
async def obsolete(self, remove=False):
result = {}
for key, value in self.cache.items():
if (value.source not in ('craftbeerpi','steps','hidden')):
@ -86,7 +87,10 @@ class ConfigController:
if test == []:
update=self.get(str(value.source)+'_update')
if update:
await self.remove(str(value.source)+'_update')
await self.remove(key)
logging.warning(update)
if remove:
await self.remove(str(value.source)+'_update')
if remove:
await self.remove(key)
result[key] = value.to_dict()
return result

View file

@ -159,7 +159,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT Max Dashboard Numbers for multiple dashboards")
try:
await self.cbpi.config.add("max_dashboard_number", 4, type=ConfigType.SELECT, description="Max Number of Dashboards",
source="craftbeerpi",
options= [{"label": "1", "value": 1},
{"label": "2", "value": 2},
{"label": "3", "value": 3},
@ -169,8 +169,8 @@ class ConfigUpdate(CBPiExtension):
{"label": "7", "value": 7},
{"label": "8", "value": 8},
{"label": "9", "value": 9},
{"label": "10", "value": 10}],
source="craftbeerpi")
{"label": "10", "value": 10}])
except:
logger.warning('Unable to update database')
@ -190,17 +190,19 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT AutoMode")
try:
await self.cbpi.config.add("AutoMode", "Yes", type=ConfigType.SELECT, description="Use AutoMode in steps",
source="steps",
options=[{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}],
source="steps")
{"label": "No", "value": "No"}])
except:
logger.warning('Unable to update config')
else:
if CONFIG_STATUS is None or CONFIG_STATUS != self.version:
await self.cbpi.config.add("AutoMode", AutoMode, type=ConfigType.SELECT, description="Use AutoMode in steps", options=
[{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}],
source="steps")
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"}])
## Check if AddMashInStep for Steps is in config
@ -208,24 +210,26 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT AddMashInStep")
try:
await self.cbpi.config.add("AddMashInStep", "Yes", type=ConfigType.SELECT, description= "Add MashIn Step automatically if not defined in recipe",
source="steps",
options = [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}],
source="steps")
{"label": "No", "value": "No"}])
except:
logger.warning('Unable to update config')
else:
if CONFIG_STATUS is None or CONFIG_STATUS != self.version:
await self.cbpi.config.add("AddMashInStep", AddMashIn, type=ConfigType.SELECT, description="Add MashIn Step automatically if not defined in recipe",
source="steps",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}],
source="steps")
{"label": "No", "value": "No"}])
## Check if Brewfather UserID is in config
if bfuserid is None:
logger.info("INIT Brewfather User ID")
try:
await self.cbpi.config.add("brewfather_user_id", "", type=ConfigType.STRING, description="Brewfather User ID")
await self.cbpi.config.add("brewfather_user_id", "", type=ConfigType.STRING, description="Brewfather User ID", source="craftbeerpi")
except:
logger.warning('Unable to update config')
@ -234,7 +238,7 @@ class ConfigUpdate(CBPiExtension):
if bfapikey is None:
logger.info("INIT Brewfather API Key")
try:
await self.cbpi.config.add("brewfather_api_key", "", type=ConfigType.STRING, description="Brewfather API Key")
await self.cbpi.config.add("brewfather_api_key", "", type=ConfigType.STRING, description="Brewfather API Key", source="craftbeerpi")
except:
logger.warning('Unable to update config')
@ -243,7 +247,7 @@ class ConfigUpdate(CBPiExtension):
if RecipeCreationPath is None:
logger.info("INIT Recipe Creation Path")
try:
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")
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")
except:
logger.warning('Unable to update config')
@ -274,6 +278,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT CSV logfiles")
try:
await self.cbpi.config.add("CSVLOGFILES", "Yes", type=ConfigType.SELECT, description="Write sensor data to csv logfiles",
source="craftbeerpi",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}])
except:
@ -284,6 +289,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT Influxdb")
try:
await self.cbpi.config.add("INFLUXDB", "No", type=ConfigType.SELECT, description="Write sensor data to influxdb",
source="craftbeerpi",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}])
except:
@ -293,7 +299,7 @@ class ConfigUpdate(CBPiExtension):
if influxdbaddr is None:
logger.info("INIT Influxdbaddr")
try:
await self.cbpi.config.add("INFLUXDBADDR", "http://localhost:8086", type=ConfigType.STRING, description="URL Address of your influxdb server (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server)")
await self.cbpi.config.add("INFLUXDBADDR", "http://localhost:8086", type=ConfigType.STRING, description="URL Address of your influxdb server (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server)", source="craftbeerpi")
except:
logger.warning('Unable to update config')
@ -301,7 +307,7 @@ class ConfigUpdate(CBPiExtension):
if influxdbname is None:
logger.info("INIT Influxdbname")
try:
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)")
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")
except:
logger.warning('Unable to update config')
@ -309,7 +315,7 @@ class ConfigUpdate(CBPiExtension):
if influxdbuser is None:
logger.info("INIT Influxdbuser")
try:
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)")
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")
except:
logger.warning('Unable to update config')
@ -317,7 +323,7 @@ class ConfigUpdate(CBPiExtension):
if influxdbpwd is None:
logger.info("INIT Influxdbpwd")
try:
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)")
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")
except:
logger.warning('Unable to update config')
@ -326,6 +332,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT influxdbcloud")
try:
await self.cbpi.config.add("INFLUXDBCLOUD", "No", type=ConfigType.SELECT, description="Write sensor data to influxdb cloud (INFLUXDB must set to Yes)",
source="craftbeerpi",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}])
except:
@ -335,7 +342,7 @@ class ConfigUpdate(CBPiExtension):
if influxdbmeasurement is None:
logger.info("INIT Influxdb measurementname")
try:
await self.cbpi.config.add("INFLUXDBMEASUREMENT", "measurement", type=ConfigType.STRING, description="Name of the measurement in your INFLUXDB database (default: measurement)")
await self.cbpi.config.add("INFLUXDBMEASUREMENT", "measurement", type=ConfigType.STRING, description="Name of the measurement in your INFLUXDB database (default: measurement)", source="craftbeerpi")
except:
logger.warning('Unable to update config')
@ -343,6 +350,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT MQTT update frequency for Kettles and Fermenters")
try:
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",
source="craftbeerpi",
options= [{"label": "30", "value": 30},
{"label": "60", "value": 60},
{"label": "120", "value": 120},
@ -356,6 +364,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT PRESSURE_UNIT")
try:
await self.cbpi.config.add("PRESSURE_UNIT", "kPa", type=ConfigType.SELECT, description="Set unit for pressure",
source="craftbeerpi",
options= [{"label": "kPa", "value": "kPa"},
{"label": "PSI", "value": "PSI"}])
except:
@ -365,7 +374,7 @@ class ConfigUpdate(CBPiExtension):
if SENSOR_LOG_BACKUP_COUNT is None:
logger.info("INIT SENSOR_LOG_BACKUP_COUNT")
try:
await self.cbpi.config.add("SENSOR_LOG_BACKUP_COUNT", 3, type=ConfigType.NUMBER, description="Max. number of backup logs")
await self.cbpi.config.add("SENSOR_LOG_BACKUP_COUNT", 3, type=ConfigType.NUMBER, description="Max. number of backup logs", source="craftbeerpi")
except:
logger.warning('Unable to update database')
@ -373,7 +382,7 @@ class ConfigUpdate(CBPiExtension):
if SENSOR_LOG_MAX_BYTES is None:
logger.info("Init maximum size of sensor logfiles")
try:
await self.cbpi.config.add("SENSOR_LOG_MAX_BYTES", 100000, type=ConfigType.NUMBER, description="Max. number of bytes in sensor logs")
await self.cbpi.config.add("SENSOR_LOG_MAX_BYTES", 100000, type=ConfigType.NUMBER, description="Max. number of bytes in sensor logs", source="craftbeerpi")
except:
logger.warning('Unable to update database')
@ -382,6 +391,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT slow_pipe_animation")
try:
await self.cbpi.config.add("slow_pipe_animation", "Yes", type=ConfigType.SELECT, description="Slow down dashboard pipe animation taking up close to 100% of the CPU's capacity",
source="craftbeerpi",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}])
except:
@ -392,6 +402,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT NOTIFY_ON_ERROR")
try:
await self.cbpi.config.add("NOTIFY_ON_ERROR", "No", type=ConfigType.SELECT, description="Send Notification on Logging Error",
source="craftbeerpi",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}])
except:
@ -402,6 +413,7 @@ class ConfigUpdate(CBPiExtension):
logger.info("INIT PLAY_BUZZER")
try:
await self.cbpi.config.add("PLAY_BUZZER", "No", type=ConfigType.SELECT, description="Play buzzer sound in Web interface on Notifications",
source="craftbeerpi",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}])
except:
@ -411,10 +423,11 @@ class ConfigUpdate(CBPiExtension):
logging.info("INIT BoilAutoTimer")
try:
await self.cbpi.config.add('BoilAutoTimer', 'No', type=ConfigType.SELECT,
description='Start Boil timer automatically if Temp does not change for 5 Minutes and is above 95C/203F',
description='Start Boil timer automatically if Temp does not change for 5 Minutes and is above 95C/203F',
source="steps",
options= [{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}],
source="steps")
{"label": "No", "value": "No"}])
BoilAutoTimer = self.cbpi.config.get("BoilAutoTimer", "No")
except:
logging.warning('Unable to update database')
@ -422,9 +435,10 @@ class ConfigUpdate(CBPiExtension):
if CONFIG_STATUS is None or CONFIG_STATUS != self.version:
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',
source="steps",
options=[{"label": "Yes", "value": "Yes"},
{"label": "No", "value": "No"}],
source="steps")
{"label": "No", "value": "No"}])
## Check if influxdbname is in config

View file

@ -104,7 +104,20 @@ class ConfigHttpEndpoints:
await self.controller.remove(name=name)
return web.Response(status=200)
@request_mapping(path="/obsolete", auth_required=False)
@request_mapping(path="/getobsolete", auth_required=False)
async def http_get_obsolete(self, request) -> web.Response:
"""
---
description: Get obsolete config parameters
tags:
- Config
responses:
"List of Obsolete Parameters":
description: successful operation
"""
return web.json_response(await self.controller.obsolete(False), dumps=json_dumps)
@request_mapping(path="/removeobsolete", auth_required=False)
async def http_remove_obsolete(self, request) -> web.Response:
"""
---
@ -115,4 +128,5 @@ class ConfigHttpEndpoints:
"200":
description: successful operation
"""
return web.json_response(await self.controller.remove_obsolete(), dumps=json_dumps)
await self.controller.obsolete(True)
return web.Response(status=200)

View file

@ -3,6 +3,7 @@
"description": "Author",
"name": "AUTHOR",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "John Doe"
},
@ -19,6 +20,7 @@
"value": "No"
}
],
"source": "steps",
"type": "select",
"value": "Yes"
},
@ -35,6 +37,7 @@
"value": "No"
}
],
"source": "steps",
"type": "select",
"value": "Yes"
},
@ -42,6 +45,7 @@
"description": "Brewery Name",
"name": "BREWERY_NAME",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "Some New Brewery Name"
},
@ -58,6 +62,7 @@
"value": "No"
}
],
"source": "steps",
"type": "select",
"value": "No"
},
@ -65,9 +70,18 @@
"description": "Define Kettle that is used for Boil, Whirlpool and Cooldown. If not selected, MASH_TUN will be used",
"name": "BoilKettle",
"options": null,
"source": "steps",
"type": "kettle",
"value": ""
},
"CONFIG_STATUS": {
"description": "Status of the config file. Internal use for maintenance",
"name": "CONFIG_STATUS",
"options": null,
"source": "hidden",
"type": "string",
"value": "4.1.8.a11"
},
"CSVLOGFILES": {
"description": "Write sensor data to csv logfiles",
"name": "CSVLOGFILES",
@ -81,6 +95,7 @@
"value": "No"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "Yes"
},
@ -97,6 +112,7 @@
"value": "No"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "No"
},
@ -104,6 +120,7 @@
"description": "IP Address of your influxdb server (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server)",
"name": "INFLUXDBADDR",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "localhost"
},
@ -120,6 +137,7 @@
"value": "No"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "No"
},
@ -127,6 +145,7 @@
"description": "Name of the measurement in your INFLUXDB database (default: measurement)",
"name": "INFLUXDBMEASUREMENT",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "measurement"
},
@ -134,6 +153,7 @@
"description": "Name of your influxdb database name (If INFLUXDBCLOUD set to Yes use bucket of your influxdb cloud database)",
"name": "INFLUXDBNAME",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "cbpi4"
},
@ -141,6 +161,7 @@
"description": "Port of your influxdb server",
"name": "INFLUXDBPORT",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "8086"
},
@ -148,6 +169,7 @@
"description": "Password for your influxdb database (only if required)(If INFLUXDBCLOUD set to Yes use token of your influxdb cloud database)",
"name": "INFLUXDBPWD",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": " "
},
@ -155,6 +177,7 @@
"description": "User name for your influxdb database (only if required)(If INFLUXDBCLOUD set to Yes use organisation of your influxdb cloud database)",
"name": "INFLUXDBUSER",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": " "
},
@ -162,6 +185,7 @@
"description": "Default Mash Tun",
"name": "MASH_TUN",
"options": null,
"source": "steps",
"type": "kettle",
"value": ""
},
@ -190,6 +214,7 @@
"value": 0
}
],
"source": "craftbeerpi",
"type": "select",
"value": 0
},
@ -206,6 +231,24 @@
"value": "No"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "No"
},
"PLAY_BUZZER": {
"description": "Play buzzer sound in Web interface on Notifications",
"name": "PLAY_BUZZER",
"options": [
{
"label": "Yes",
"value": "Yes"
},
{
"label": "No",
"value": "No"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "No"
},
@ -222,6 +265,7 @@
"value": "PSI"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "kPa"
},
@ -229,6 +273,7 @@
"description": "API path to creation plugin. Default: upload . CHANGE ONLY IF USING A RECIPE CREATION PLUGIN",
"name": "RECIPE_CREATION_PATH",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": "upload"
},
@ -236,6 +281,7 @@
"description": "Max. number of backup logs",
"name": "SENSOR_LOG_BACKUP_COUNT",
"options": null,
"source": "craftbeerpi",
"type": "number",
"value": 3
},
@ -243,6 +289,7 @@
"description": "Max. number of bytes in sensor logs",
"name": "SENSOR_LOG_MAX_BYTES",
"options": null,
"source": "craftbeerpi",
"type": "number",
"value": 100000
},
@ -259,6 +306,7 @@
"value": "F"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "C"
},
@ -266,6 +314,7 @@
"description": "Brewfather API Key",
"name": "brewfather_api_key",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": ""
},
@ -273,6 +322,7 @@
"description": "Brewfather User ID",
"name": "brewfather_user_id",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": ""
},
@ -280,6 +330,7 @@
"description": "Number of current Dashboard",
"name": "current_dashboard_number",
"options": null,
"source": "hidden",
"type": "number",
"value": 1
},
@ -328,6 +379,7 @@
"value": 10
}
],
"source": "craftbeerpi",
"type": "select",
"value": 4
},
@ -344,6 +396,7 @@
"value": "No"
}
],
"source": "craftbeerpi",
"type": "select",
"value": "Yes"
},
@ -351,6 +404,7 @@
"description": "Boil step type",
"name": "steps_boil",
"options": null,
"source": "steps",
"type": "step",
"value": "BoilStep"
},
@ -358,6 +412,7 @@
"description": "Default Boil Temperature for Recipe Creation",
"name": "steps_boil_temp",
"options": null,
"source": "steps",
"type": "number",
"value": "99"
},
@ -365,6 +420,7 @@
"description": "Cooldown step type",
"name": "steps_cooldown",
"options": null,
"source": "steps",
"type": "step",
"value": "CooldownStep"
},
@ -372,6 +428,7 @@
"description": "Actor to trigger cooldown water on and off (default: None)",
"name": "steps_cooldown_actor",
"options": null,
"source": "steps",
"type": "actor",
"value": ""
},
@ -379,6 +436,7 @@
"description": "Alternative Sensor to monitor temperature durring cooldown (if not selected, Kettle Sensor will be used)",
"name": "steps_cooldown_sensor",
"options": null,
"source": "steps",
"type": "sensor",
"value": ""
},
@ -386,6 +444,7 @@
"description": "Cooldown temp will send notification when this temeprature is reached",
"name": "steps_cooldown_temp",
"options": null,
"source": "steps",
"type": "number",
"value": 35
},
@ -393,6 +452,7 @@
"description": "Mash step type",
"name": "steps_mash",
"options": null,
"source": "steps",
"type": "step",
"value": "MashStep"
},
@ -400,6 +460,7 @@
"description": "MashIn step type",
"name": "steps_mashin",
"options": null,
"source": "steps",
"type": "step",
"value": "MashInStep"
},
@ -407,6 +468,7 @@
"description": "MashOut step type",
"name": "steps_mashout",
"options": null,
"source": "steps",
"type": "step",
"value": "NotificationStep"
}

View file

@ -1,3 +1,7 @@
{
"elements": []
"config": {},
"dbid": 1,
"type": "Test",
"x": 0,
"y": 0
}