importlogging
+fromunittest.mockimportMagicMock,patch
-fromcore.apiimportCBPiActor,Property,action
+fromcbpi.apiimport*
+logger=logging.getLogger(__name__)
+
+try:
+ importRPi.GPIOasGPIO
+exceptException:
+ logger.error("Failed to load RPi.GPIO. Using Mock")
+ MockRPi=MagicMock()
+ modules={
+ "RPi":MockRPi,
+ "RPi.GPIO":MockRPi.GPIO
+ }
+ patcher=patch.dict("sys.modules",modules)
+ patcher.start()
+ importRPi.GPIOasGPIO
+
classCustomActor(CBPiActor):# Custom property which can be configured by the user
- gpio=Property.Number(label="Test")
-
- @action(key="name",parameters={})
- defmyAction(self):
+ definit(self):pass
- defstate(self):
- super().state()
+ defon(self,power=0):
+ logger.info("ACTOR %s ON"%self.id)
+ self.state=Truedefoff(self):
- print("OFF",self.gpio)
-
- # Code to swtich the actor off goes here
-
+ logger.info("ACTOR %s OFF "%self.id)self.state=False
- defon(self,power=100):
- print("ON",self.gpio)
- # Code to swtich the actor on goes here
+
+classGPIOActor(CBPiActor):
+
+ # Custom property which can be configured by the user
+
+ gpio=Property.Select("GPIO",options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],description="GPIO to which the actor is connected")
+
+ definit(self):
+ try:
+ GPIO.setup(int(self.gpio),GPIO.OUT)
+ GPIO.output(int(self.gpio),0)
+ exceptExceptionase:
+ raiseCBPiException("FAILD TO INIT ACTOR")
+
+ defon(self,power=0):
+
+ print("GPIO ON %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),1)self.state=True
+ defoff(self):
+ print("GPIO OFF %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),0)
+ self.state=False
+
+classGPIORelayBoardActor(CBPiActor):
+
+ # Custom property which can be configured by the user
+
+ gpio=Property.Select("GPIO",options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],description="GPIO to which the actor is connected")
+
+ definit(self):
+ try:
+ GPIO.setup(int(self.gpio),GPIO.OUT)
+ GPIO.output(int(self.gpio),1)
+ exceptExceptionase:
+ raiseCBPiException("FAILD TO INIT ACTOR")
+
+ defon(self,power=0):
+
+ print("GPIO ON %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),0)
+ self.state=True
+
+ defoff(self):
+ print("GPIO OFF %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),1)
+ self.state=False
+
defsetup(cbpi):
diff --git a/docs/genindex.html b/docs/genindex.html
index 7b80f50..e7a2a29 100644
--- a/docs/genindex.html
+++ b/docs/genindex.html
@@ -86,6 +86,8 @@
To start CraftBeerPi just run the following command in your shell
+
$ cbpi
+
+
+
During the first startup a config and logs folder gets created in the directory from where the $ cbpi in called
+PIP Website: https://test.pypi.org/project/cbpi/
importlogging
+fromunittest.mockimportMagicMock,patch
-fromcore.apiimportCBPiActor,Property,action
+fromcbpi.apiimport*
+logger=logging.getLogger(__name__)
+
+try:
+ importRPi.GPIOasGPIO
+exceptException:
+ logger.error("Failed to load RPi.GPIO. Using Mock")
+ MockRPi=MagicMock()
+ modules={
+ "RPi":MockRPi,
+ "RPi.GPIO":MockRPi.GPIO
+ }
+ patcher=patch.dict("sys.modules",modules)
+ patcher.start()
+ importRPi.GPIOasGPIO
+
classCustomActor(CBPiActor):# Custom property which can be configured by the user
- gpio=Property.Number(label="Test")
-
- @action(key="name",parameters={})
- defmyAction(self):
+ definit(self):pass
- defstate(self):
- super().state()
+ defon(self,power=0):
+ logger.info("ACTOR %s ON"%self.id)
+ self.state=Truedefoff(self):
- print("OFF",self.gpio)
-
- # Code to swtich the actor off goes here
-
+ logger.info("ACTOR %s OFF "%self.id)self.state=False
- defon(self,power=100):
- print("ON",self.gpio)
- # Code to swtich the actor on goes here
+
+classGPIOActor(CBPiActor):
+
+ # Custom property which can be configured by the user
+
+ gpio=Property.Select("GPIO",options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],description="GPIO to which the actor is connected")
+
+ definit(self):
+ try:
+ GPIO.setup(int(self.gpio),GPIO.OUT)
+ GPIO.output(int(self.gpio),0)
+ exceptExceptionase:
+ raiseCBPiException("FAILD TO INIT ACTOR")
+
+ defon(self,power=0):
+
+ print("GPIO ON %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),1)self.state=True
+ defoff(self):
+ print("GPIO OFF %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),0)
+ self.state=False
+
+classGPIORelayBoardActor(CBPiActor):
+
+ # Custom property which can be configured by the user
+
+ gpio=Property.Select("GPIO",options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],description="GPIO to which the actor is connected")
+
+ definit(self):
+ try:
+ GPIO.setup(int(self.gpio),GPIO.OUT)
+ GPIO.output(int(self.gpio),1)
+ exceptExceptionase:
+ raiseCBPiException("FAILD TO INIT ACTOR")
+
+ defon(self,power=0):
+
+ print("GPIO ON %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),0)
+ self.state=True
+
+ defoff(self):
+ print("GPIO OFF %s"%str(self.gpio))
+ GPIO.output(int(self.gpio),1)
+ self.state=False
+
defsetup(cbpi):
@@ -256,41 +368,41 @@ For example the user can set the GPIO number or the 1Wire Id.
One core concept of CraftBeerPi 4.x is the CBPiEventBus.
It should be avoided to call method on a controller directly. Events should be fired and listener methods should be used.
This makes sure that all components are loosely coupled. New plugins can listen on events and extend or change the functionality easily.
@@ -188,6 +190,7 @@ This makes sure that all components are loosely coupled. New plugins can listen
Note
It’s imporante to add **kwargs as parameter to the listening method. This makes sure that maybe addtional event paramenter are not causing an exception.
+
A list of all registered events listeners can be found under: http://<IP_ADDRESS>:<PORT>/system/events
@@ -243,6 +251,10 @@ The build process is based on webpack and bable.
After server startup you can find the API documentaiton under: http://<IP_ADDRESS>:<PORT>/api/doc
This method in running in the background. It invokes the run_cycle method in the configured interval
It checks if a managed variable was modified in the last exection cycle. If yes, the method will persisit the new value of the
managed property
This method is executed in the defined interval.
That the place to put your step logic.
The method need to be overwritten in the Ccstom step implementaion
@@ -467,8 +348,8 @@ The method need to be overwritten in the Ccstom step implementaion