mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-22 06:58:17 +01:00
Added mqttutil extension
- forces mqtt update for kettle and femrenter in specified timeframes even w/o change in payload - required for mqttdevice - only active if mqtt is enabled - can be set to never and is also deactivated when mqtt is enabled
This commit is contained in:
parent
a7ddcdd306
commit
ed141f8788
4 changed files with 62 additions and 1 deletions
|
@ -1 +1 @@
|
||||||
__version__ = "4.0.1.8"
|
__version__ = "4.0.1.9"
|
||||||
|
|
|
@ -44,6 +44,7 @@ class ConfigUpdate(CBPiExtension):
|
||||||
influxdbname = self.cbpi.config.get("INFLUXDBNAME", None)
|
influxdbname = self.cbpi.config.get("INFLUXDBNAME", None)
|
||||||
influxdbuser = self.cbpi.config.get("INFLUXDBUSER", None)
|
influxdbuser = self.cbpi.config.get("INFLUXDBUSER", None)
|
||||||
influxdbpwd = self.cbpi.config.get("INFLUXDBPWD", None)
|
influxdbpwd = self.cbpi.config.get("INFLUXDBPWD", None)
|
||||||
|
mqttupdate = self.cbpi.config.get("MQTTUpdate", None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -252,6 +253,19 @@ class ConfigUpdate(CBPiExtension):
|
||||||
except:
|
except:
|
||||||
logger.warning('Unable to update config')
|
logger.warning('Unable to update config')
|
||||||
|
|
||||||
|
if mqttupdate is None:
|
||||||
|
logger.info("INIT MQTT update frequency for Kettles and Fermenters")
|
||||||
|
try:
|
||||||
|
await self.cbpi.config.add("MQTTUpdate", 60, ConfigType.SELECT, "Forced MQTT Update frequency in s for Kettle and Fermenter (no changes in payload required). Restart required after change",
|
||||||
|
[{"label": "30", "value": 30},
|
||||||
|
{"label": "60", "value": 60},
|
||||||
|
{"label": "120", "value": 120},
|
||||||
|
{"label": "300", "value": 300},
|
||||||
|
{"label": "Never", "value": 0}])
|
||||||
|
except:
|
||||||
|
logger.warning('Unable to update database')
|
||||||
|
|
||||||
|
|
||||||
def setup(cbpi):
|
def setup(cbpi):
|
||||||
cbpi.plugin.register("ConfigUpdate", ConfigUpdate)
|
cbpi.plugin.register("ConfigUpdate", ConfigUpdate)
|
||||||
pass
|
pass
|
||||||
|
|
44
cbpi/extension/mqtt_util/__init__.py
Normal file
44
cbpi/extension/mqtt_util/__init__.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
from cbpi.api import *
|
||||||
|
from cbpi.api.config import ConfigType
|
||||||
|
from cbpi.api.base import CBPiBase
|
||||||
|
from cbpi.controller.fermentation_controller import FermentationController
|
||||||
|
from cbpi.controller.kettle_controller import KettleController
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class MQTTUtil(CBPiExtension):
|
||||||
|
|
||||||
|
def __init__(self,cbpi):
|
||||||
|
self.cbpi = cbpi
|
||||||
|
self.kettlecontroller : KettleController = cbpi.kettle
|
||||||
|
self.fermentationcontroller : FermentationController = cbpi.fermenter
|
||||||
|
self.mqttupdate = int(self.cbpi.config.get("MQTTUpdate", 60))
|
||||||
|
if self.mqttupdate != 0:
|
||||||
|
self._task = asyncio.create_task(self.run())
|
||||||
|
logger.info("INIT MQTTUtil")
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self.kettle=self.kettlecontroller.get_state()
|
||||||
|
for item in self.kettle['data']:
|
||||||
|
self.cbpi.push_update("cbpi/{}/{}".format("kettleupdate",item['id']), item)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self.fermenter=self.fermentationcontroller.get_state()
|
||||||
|
for item in self.fermenter['data']:
|
||||||
|
self.cbpi.push_update("cbpi/{}/{}".format("fermenterupdate",item['id']), item)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
pass
|
||||||
|
await asyncio.sleep(self.mqttupdate)
|
||||||
|
|
||||||
|
def setup(cbpi):
|
||||||
|
if str(cbpi.static_config.get("mqtt", False)).lower() == "true":
|
||||||
|
cbpi.plugin.register("MQTTUtil", MQTTUtil)
|
||||||
|
pass
|
3
cbpi/extension/mqtt_util/config.yaml
Normal file
3
cbpi/extension/mqtt_util/config.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
name: MQTTUtil
|
||||||
|
version: 4
|
||||||
|
active: true
|
Loading…
Reference in a new issue