Skip to content

Commit

Permalink
Merge pull request #111 from PiBrewing/development
Browse files Browse the repository at this point in the history
Merge Development into master
  • Loading branch information
avollkopf authored Jun 10, 2023
2 parents da72d61 + 1d9b27e commit e9c38f1
Show file tree
Hide file tree
Showing 24 changed files with 641 additions and 274 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ logs/
.coverage
.devcontainer/cbpi-dev-config/*
cbpi4-*
temp*
temp*
*.patch
6 changes: 5 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"type": "python",
"request": "launch",
"module": "run",
"args": ["--config-folder-path=./.devcontainer/cbpi-dev-config", "start"],
"args": [
"--config-folder-path=./.devcontainer/cbpi-dev-config",
"--debug-log-level=20",
"start"
],
"preLaunchTask": "copy default cbpi config files if dev config files dont exist"
},

Expand Down
2 changes: 1 addition & 1 deletion cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.1.7"
__version__ = "4.1.10"
__codename__ = "Groundhog Day"

7 changes: 5 additions & 2 deletions cbpi/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ def get_config_value(self,name,default):

async def set_config_value(self,name,value):
return await self.cbpi.config.set(name,value)

async def remove_config_parameter(self,name):
return await self.cbpi.config.remove(name)

async def add_config_value(self, name, value, type: ConfigType, description, options=None):
await self.cbpi.config.add(name, value, type, description, options=None)
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)

def get_kettle(self,id):
return self.cbpi.kettle.find_by_id(id)
Expand Down
3 changes: 2 additions & 1 deletion cbpi/api/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ class Config:
value: Any = None
description: str = None
type: ConfigType = ConfigType.STRING
source: str = None
options: Any = None

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)
return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, source=self.source, options=self.options)

@dataclass
class NotificationAction:
Expand Down
2 changes: 1 addition & 1 deletion cbpi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def plugin_create(self, pluginName):
print("Cant create Plugin. Folder {} already exists ".format(name))
return

url = 'https://github.com/Manuel83/craftbeerpi4-plugin-template/archive/main.zip'
url = 'https://github.com/PiBrewing/craftbeerpi4-plugin-template/archive/main.zip'
r = requests.get(url)
with open('temp.zip', 'wb') as f:
f.write(r.content)
Expand Down
121 changes: 5 additions & 116 deletions cbpi/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,17 @@
"name": "AUTHOR",
"options": null,
"type": "string",
"source": "craftbeerpi",
"value": "John Doe"
},
"BREWERY_NAME": {
"description": "Brewery Name",
"name": "BREWERY_NAME",
"options": null,
"type": "string",
"source": "craftbeerpi",
"value": "CraftBeerPi Brewery"
},
"MASH_TUN": {
"description": "Default Mash Tun",
"name": "MASH_TUN",
"options": null,
"type": "kettle",
"value": ""
},
"AddMashInStep": {
"description": "Add MashIn Step automatically if not defined in recipe",
"name": "AddMashInStep",
"options": [
{
"label": "Yes",
"value": "Yes"
},
{
"label": "No",
"value": "No"
}
],
"type": "select",
"value": "Yes"
},
"RECIPE_CREATION_PATH": {
"description": "API path to creation plugin. Default: empty",
"name": "RECIPE_CREATION_PATH",
"options": null,
"type": "string",
"value": ""
},
"brewfather_api_key": {
"description": "Brewfather API Kay",
"name": "brewfather_api_key",
"options": null,
"type": "string",
"value": ""
},
"brewfather_user_id": {
"description": "Brewfather User ID",
"name": "brewfather_user_id",
"options": null,
"type": "string",
"value": ""
},
"TEMP_UNIT": {
"description": "Temperature Unit",
"name": "TEMP_UNIT",
Expand All @@ -71,78 +29,9 @@
}
],
"type": "select",
"source": "craftbeerpi",
"value": "C"
},
"AutoMode": {
"description": "Use AutoMode in steps",
"name": "AutoMode",
"options": [
{
"label": "Yes",
"value": "Yes"
},
{
"label": "No",
"value": "No"
}
],
"type": "select",
"value": "Yes"
},
"steps_boil": {
"description": "Boil step type",
"name": "steps_boil",
"options": null,
"type": "step",
"value": "BoilStep"
},
"steps_boil_temp": {
"description": "Default Boil Temperature for Recipe Creation",
"name": "steps_boil_temp",
"options": null,
"type": "number",
"value": "99"
},
"steps_cooldown": {
"description": "Cooldown step type",
"name": "steps_cooldown",
"options": null,
"type": "step",
"value": "CooldownStep"
},
"steps_cooldown_sensor": {
"description": "Alternative Sensor to monitor temperature durring cooldown (if not selected, Kettle Sensor will be used)",
"name": "steps_cooldown_sensor",
"options": null,
"type": "sensor",
"value": ""
},
"steps_cooldown_temp": {
"description": "Cooldown temp will send notification when this temeprature is reached",
"name": "steps_cooldown_temp",
"options": null,
"type": "number",
"value": "20"
},
"steps_mash": {
"description": "Mash step type",
"name": "steps_mash",
"options": null,
"type": "step",
"value": "MashStep"
},
"steps_mashin": {
"description": "MashIn step type",
"name": "steps_mashin",
"options": null,
"type": "step",
"value": "MashInStep"
},
"steps_mashout": {
"description": "MashOut step type",
"name": "steps_mashout",
"options": null,
"type": "step",
"value": "NotificationStep"
}


}
42 changes: 31 additions & 11 deletions cbpi/controller/basic_controller2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,39 @@ def create(self, data):
return self.resource(data.get("id"), data.get("name"), type=data.get("type"), props=Props(data.get("props", {})) )

async def load(self):
logging.info("{} Load ".format(self.name))
with open(self.path) as json_file:
data = json.load(json_file)
data['data'].sort(key=lambda x: x.get('name').upper())
try:
logging.info("{} Load ".format(self.name))
with open(self.path) as json_file:
data = json.load(json_file)
data['data'].sort(key=lambda x: x.get('name').upper())

for i in data["data"]:
self.data.append(self.create(i))

if self.autostart is True:
for item in self.data:
logging.info("{} Starting ".format(self.name))
await self.start(item.id)
await self.push_udpate()
except Exception as e:
logging.warning("Invalid {} file - Creating empty file".format(self.path))
os.remove(self.path)
with open(self.path, "w") as file:
json.dump(dict( data=[]), file, indent=4, sort_keys=True)

with open(self.path) as json_file:
data = json.load(json_file)
data['data'].sort(key=lambda x: x.get('name').upper())

for i in data["data"]:
self.data.append(self.create(i))
for i in data["data"]:
self.data.append(self.create(i))

if self.autostart is True:
for item in self.data:
logging.info("{} Starting ".format(self.name))
await self.start(item.id)
await self.push_udpate()
if self.autostart is True:
for item in self.data:
logging.info("{} Starting ".format(self.name))
await self.start(item.id)
await self.push_udpate()


async def save(self):
logging.info("{} Save ".format(self.name))
Expand Down
49 changes: 41 additions & 8 deletions cbpi/controller/config_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ def __init__(self, cbpi):
self.path_static = cbpi.config_folder.get_file_path("config.yaml")
self.logger.info("Config folder path : " + os.path.join(Path(self.cbpi.config_folder.configFolderPath).absolute()))

def get_state(self):

def get_state(self):
result = {}
for key, value in self.cache.items():
result[key] = value.to_dict()

return result

return result

async def init(self):
self.static = load_config(self.path_static)
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) )
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))

def get(self, name, default=None):
self.logger.debug("GET CONFIG VALUE %s (default %s)" % (name, default))
Expand All @@ -53,10 +50,46 @@ async def set(self, name, value):
with open(self.path, "w") as file:
json.dump(data, file, indent=4, sort_keys=True)

async def add(self, name, value, type: ConfigType, description, options=None):
self.cache[name] = Config(name,value,description,type,options)
async def add(self, name, value, type: ConfigType, description, source="craftbeerpi", options=None):
self.cache[name] = Config(name,value,description,type,source,options)
data = {}
for key, value in self.cache.items():
data[key] = value.to_dict()
with open(self.path, "w") as file:
json.dump(data, file, indent=4, sort_keys=True)

async def remove(self, name):
data = {}
self.testcache={}
success=False
for key, value in self.cache.items():
try:
if key != name:
data[key] = value.to_dict()
self.testcache[key] = Config(name=data[key].get("name"), value=data[key].get("value"), description=data[key].get("description"),
type=ConfigType(data[key].get("type", "string")), options=data[key].get("options", None),
source=data[key].get("source", "craftbeerpi") )
success=True
except Exception as e:
print(e)
success=False
if success == True:
with open(self.path, "w") as file:
json.dump(data, file, indent=4, sort_keys=True)
self.cache=self.testcache

async def obsolete(self, remove=False):
result = {}
for key, value in self.cache.items():
if (value.source not in ('craftbeerpi','steps','hidden')):
test = await self.cbpi.plugin.load_plugin_list(value.source)
if test == []:
update=self.get(str(value.source)+'_update')
if update:
result[str(value.source)+'_update']={"value": update}
if remove:
await self.remove(str(value.source)+'_update')
if remove:
await self.remove(key)
result[key] = value.to_dict()
return result
Loading

0 comments on commit e9c38f1

Please sign in to comment.