!!! DONT USE !!! - feasibility test to add output parameter to actor

This commit is contained in:
avollkopf 2024-08-07 18:42:57 +02:00
parent 90289ef949
commit 1c6dae875c
10 changed files with 233 additions and 13 deletions

View file

@ -21,6 +21,7 @@ class CBPiActor(metaclass=ABCMeta):
self.state = False self.state = False
self.running = False self.running = False
self.power = 100 self.power = 100
self.output = 100
self.timer = 0 self.timer = 0
def init(self): def init(self):
@ -71,7 +72,7 @@ class CBPiActor(metaclass=ABCMeta):
async def add_config_value(self, name, value, type: ConfigType, description, options=None): async def add_config_value(self, name, value, type: ConfigType, description, options=None):
await self.cbpi.add(name, value, type, description, options=None) await self.cbpi.add(name, value, type, description, options=None)
async def on(self, power): async def on(self, power, output):
''' '''
Code to switch the actor on. Power is provided as integer value Code to switch the actor on. Power is provided as integer value
@ -98,3 +99,11 @@ class CBPiActor(metaclass=ABCMeta):
return dict(power=self.power) return dict(power=self.power)
pass pass
async def set_output(self,output):
'''
Code to set power for actor
:return: dict power
'''
return dict(output=self.output)
pass

View file

@ -65,10 +65,10 @@ class CBPiBase(metaclass=ABCMeta):
logging.error("Failed to read actor state in step - actor {}".format(id)) logging.error("Failed to read actor state in step - actor {}".format(id))
return False return False
async def actor_on(self,id,power=100): async def actor_on(self,id,power=100, output=100):
try: try:
await self.cbpi.actor.on(id,power) await self.cbpi.actor.on(id,power, output)
except Exception as e: except Exception as e:
pass pass
@ -83,3 +83,9 @@ class CBPiBase(metaclass=ABCMeta):
await self.cbpi.actor.set_power(id,power) await self.cbpi.actor.set_power(id,power)
except Exception as e: except Exception as e:
pass pass
async def actor_set_output(self,id,output):
try:
await self.cbpi.actor.set_output(id,output)
except Exception as e:
pass

View file

@ -56,14 +56,15 @@ class Actor:
props: Props = Props() props: Props = Props()
state: bool = False state: bool = False
power: int = 100 power: int = 100
output: int = 100
timer: int = 0 timer: int = 0
type: str = None type: str = None
instance: str = None instance: str = None
def __str__(self): def __str__(self):
return "name={} props={}, state={}, type={}, power={}, timer={}".format(self.name, self.props, self.state, self.type, self.power, self.timer) return "name={} props={}, state={}, type={}, power={}, output={}, timer={}".format(self.name, self.props, self.state, self.type, self.power, self.output, self.timer)
def to_dict(self): def to_dict(self):
return dict(id=self.id, name=self.name, type=self.type, props=self.props.to_dict(), state=self.instance.get_state(), power=self.power, timer=self.timer) return dict(id=self.id, name=self.name, type=self.type, props=self.props.to_dict(), state=self.instance.get_state(), power=self.power, output=self.output, timer=self.timer)
class DataType(Enum): class DataType(Enum):
VALUE="value" VALUE="value"

View file

@ -9,7 +9,7 @@ class ActorController(BasicController):
self.update_key = "actorupdate" self.update_key = "actorupdate"
self.sorting=True self.sorting=True
async def on(self, id, power=None): async def on(self, id, power=None, output=None):
try: try:
item = self.find_by_id(id) item = self.find_by_id(id)
if power is None: if power is None:
@ -18,14 +18,22 @@ class ActorController(BasicController):
power = item.power power = item.power
else: else:
power = 100 power = 100
if output is None:
logging.info("Output is none")
if item.output:
output = item.output
else:
output = 100
if item.instance.state is False: if item.instance.state is False:
await item.instance.on(power) await item.instance.on(power,output)
#await self.push_udpate() #await self.push_udpate()
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting) self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict(), True) self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict(), True)
else: else:
await self.set_power(id, power) await self.set_power(id, power)
await self.set_output(id, output)
except Exception as e: except Exception as e:
logging.error("Failed to switch on Actor {} {}".format(id, e)) logging.error("Failed to switch on Actor {} {}".format(id, e))
@ -57,10 +65,18 @@ class ActorController(BasicController):
except Exception as e: except Exception as e:
logging.error("Failed to set power {} {}".format(id, e)) logging.error("Failed to set power {} {}".format(id, e))
async def actor_update(self, id, power): async def set_output(self, id, output):
try:
item = self.find_by_id(id)
await item.instance.set_output(output)
except Exception as e:
logging.error("Failed to set output {} {}".format(id, e))
async def actor_update(self, id, power, output):
try: try:
item = self.find_by_id(id) item = self.find_by_id(id)
item.power = round(power) item.power = round(power)
item.output = round(output)
#await self.push_udpate() #await self.push_udpate()
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting) self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict()) self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())

View file

@ -27,6 +27,7 @@ class SatelliteController:
("cbpi/actor/+/on", self._actor_on), ("cbpi/actor/+/on", self._actor_on),
("cbpi/actor/+/off", self._actor_off), ("cbpi/actor/+/off", self._actor_off),
("cbpi/actor/+/power", self._actor_power), ("cbpi/actor/+/power", self._actor_power),
("cbpi/actor/+/output", self._actor_output),
("cbpi/updateactor", self._actorupdate), ("cbpi/updateactor", self._actorupdate),
("cbpi/updatekettle", self._kettleupdate), ("cbpi/updatekettle", self._kettleupdate),
("cbpi/updatesensor", self._sensorupdate), ("cbpi/updatesensor", self._sensorupdate),
@ -123,6 +124,21 @@ class SatelliteController:
self.logger.warning("Failed to set actor power via mqtt. No valid power in message") self.logger.warning("Failed to set actor power via mqtt. No valid power in message")
except: except:
self.logger.warning("Failed to set actor power via mqtt") self.logger.warning("Failed to set actor power via mqtt")
async def _actor_output(self, message):
try:
topic_key = str(message.topic).split("/")
try:
output=int(message.payload.decode())
#if power > 100:
# power = 100
#if power < 0:
# power = 0
await self.cbpi.actor.set_output(topic_key[2],output)
except:
self.logger.warning("Failed to set actor output via mqtt. No valid output in message")
except:
self.logger.warning("Failed to set actor output via mqtt")
async def _kettleupdate(self, message): async def _kettleupdate(self, message):
try: try:

View file

@ -61,6 +61,8 @@ class FermenterHysteresis(CBPiFermenterLogic):
self.cooler_offset_max = float(self.props.get("CoolerOffsetOff", 0)) self.cooler_offset_max = float(self.props.get("CoolerOffsetOff", 0))
self.heater_max_power = int(self.props.get("HeaterMaxPower", 100)) self.heater_max_power = int(self.props.get("HeaterMaxPower", 100))
self.cooler_max_power = int(self.props.get("CoolerMaxPower", 100)) self.cooler_max_power = int(self.props.get("CoolerMaxPower", 100))
self.heater_max_output=self.heater_max_power
self.cooler_max_output=self.cooler_max_power
self.fermenter = self.get_fermenter(self.id) self.fermenter = self.get_fermenter(self.id)
self.heater = self.fermenter.heater self.heater = self.fermenter.heater
@ -85,7 +87,7 @@ class FermenterHysteresis(CBPiFermenterLogic):
if sensor_value + self.heater_offset_min <= target_temp: if sensor_value + self.heater_offset_min <= target_temp:
if self.heater and (heater_state == False): if self.heater and (heater_state == False):
await self.actor_on(self.heater, self.heater_max_power) await self.actor_on(self.heater, self.heater_max_power, self.heater_max_output)
if sensor_value + self.heater_offset_max >= target_temp: if sensor_value + self.heater_offset_max >= target_temp:
if self.heater and (heater_state == True): if self.heater and (heater_state == True):
@ -93,7 +95,7 @@ class FermenterHysteresis(CBPiFermenterLogic):
if sensor_value >= self.cooler_offset_min + target_temp: if sensor_value >= self.cooler_offset_min + target_temp:
if self.cooler and (cooler_state == False): if self.cooler and (cooler_state == False):
await self.actor_on(self.cooler, self.cooler_max_power) await self.actor_on(self.cooler, self.cooler_max_power, self.cooler_max_output)
if sensor_value <= self.cooler_offset_max + target_temp: if sensor_value <= self.cooler_offset_max + target_temp:
if self.cooler and (cooler_state == True): if self.cooler and (cooler_state == True):

View file

@ -24,7 +24,7 @@ class DummyActor(CBPiActor):
async def start(self): async def start(self):
await super().start() await super().start()
async def on(self, power=0): async def on(self, power=0, output=0):
logger.info("ACTOR %s ON " % self.id) logger.info("ACTOR %s ON " % self.id)
self.state = True self.state = True

View file

@ -3,9 +3,11 @@
{ {
"id": "3CUJte4bkxDMFCtLX8eqsX", "id": "3CUJte4bkxDMFCtLX8eqsX",
"name": "SomeActor", "name": "SomeActor",
"output": 100,
"power": 100, "power": 100,
"props": {}, "props": {},
"state": false, "state": false,
"timer": 0,
"type": "DummyActor" "type": "DummyActor"
} }
] ]

View file

@ -41,6 +41,128 @@
"type": "select", "type": "select",
"value": "Yes" "value": "Yes"
}, },
"AutoReboot": {
"description": "Reboot Pi once a day at selected time",
"name": "AutoReboot",
"options": [
{
"label": "Yes",
"value": "Yes"
},
{
"label": "No",
"value": "No"
}
],
"source": "cbpi4-system",
"type": "select",
"value": "No"
},
"AutoRebootTime": {
"description": "Time for daily reboot",
"name": "AutoRebootTime",
"options": [
{
"label": "0",
"value": 0
},
{
"label": "1",
"value": 1
},
{
"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
},
{
"label": "11",
"value": 11
},
{
"label": "12",
"value": 12
},
{
"label": "13",
"value": 13
},
{
"label": "14",
"value": 14
},
{
"label": "15",
"value": 15
},
{
"label": "16",
"value": 16
},
{
"label": "17",
"value": 17
},
{
"label": "18",
"value": 18
},
{
"label": "19",
"value": 19
},
{
"label": "20",
"value": 20
},
{
"label": "21",
"value": 21
},
{
"label": "22",
"value": 22
},
{
"label": "23",
"value": 23
}
],
"source": "cbpi4-system",
"type": "select",
"value": "0"
},
"BREWERY_NAME": { "BREWERY_NAME": {
"description": "Brewery Name", "description": "Brewery Name",
"name": "BREWERY_NAME", "name": "BREWERY_NAME",
@ -80,7 +202,7 @@
"options": null, "options": null,
"source": "hidden", "source": "hidden",
"type": "string", "type": "string",
"value": "4.3.2.a6" "value": "4.4.3"
}, },
"CSVLOGFILES": { "CSVLOGFILES": {
"description": "Write sensor data to csv logfiles (enabling requires restart)", "description": "Write sensor data to csv logfiles (enabling requires restart)",
@ -302,6 +424,14 @@
"type": "select", "type": "select",
"value": "C" "value": "C"
}, },
"TasmotaTopic": {
"description": "Tasmota MQTT Topic",
"name": "TasmotaTopic",
"options": null,
"source": "craftbeerpi",
"type": "string",
"value": ""
},
"brewfather_api_key": { "brewfather_api_key": {
"description": "Brewfather API Key", "description": "Brewfather API Key",
"name": "brewfather_api_key", "name": "brewfather_api_key",
@ -310,6 +440,35 @@
"type": "string", "type": "string",
"value": "" "value": ""
}, },
"brewfather_list_length": {
"description": "Brewfather Recipe List length",
"name": "brewfather_list_length",
"options": [
{
"label": "5",
"value": 5
},
{
"label": "10",
"value": 10
},
{
"label": "25",
"value": 25
},
{
"label": "50",
"value": 50
},
{
"label": "100",
"value": 100
}
],
"source": "craftbeerpi",
"type": "select",
"value": 50
},
"brewfather_user_id": { "brewfather_user_id": {
"description": "Brewfather User ID", "description": "Brewfather User ID",
"name": "brewfather_user_id", "name": "brewfather_user_id",
@ -318,6 +477,14 @@
"type": "string", "type": "string",
"value": "" "value": ""
}, },
"cbpi4-system_update": {
"description": "cbpi4 system version update",
"name": "cbpi4-system_update",
"options": null,
"source": "hidden",
"type": "string",
"value": "0.0.9a6"
},
"current_dashboard_number": { "current_dashboard_number": {
"description": "Number of current Dashboard", "description": "Number of current Dashboard",
"name": "current_dashboard_number", "name": "current_dashboard_number",

View file

@ -18,3 +18,4 @@ password: 123
plugins: plugins:
- cbpi4ui - cbpi4ui
mqtt_offset: false