1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

Added in gpiozero functionality and tested. (#245)

This commit is contained in:
tjohnsonhvac 2019-02-22 00:34:25 -05:00 committed by Joel Bender
parent 96c042f6bd
commit 1a1d19fe5d

View File

@ -2,7 +2,6 @@
""" """
Raspberry Pi Binary Input and Output Raspberry Pi Binary Input and Output
This sample application is BACnet server running on a Rasbperry Pi that This sample application is BACnet server running on a Rasbperry Pi that
associates a Button with a BinaryInputObject and a LED with a associates a Button with a BinaryInputObject and a LED with a
BinaryOutputObject. BinaryOutputObject.
@ -25,6 +24,8 @@ from bacpypes.errors import ExecutionError
from bacpypes.app import BIPSimpleApplication from bacpypes.app import BIPSimpleApplication
from bacpypes.local.device import LocalDeviceObject from bacpypes.local.device import LocalDeviceObject
from gpiozero import Button, LED
# some debugging # some debugging
_debug = 0 _debug = 0
_log = ModuleLogger(globals()) _log = ModuleLogger(globals())
@ -39,6 +40,9 @@ led_list = [(17, 17)]
# Mock classes # Mock classes
# #
'''
# We may want to look into the mock pin class of gpiozero.
# It will allow for testing without using an RPI board.
class Button: class Button:
def __init__(self, button_id): def __init__(self, button_id):
@ -48,7 +52,7 @@ class Button:
class LED: class LED:
def __init__(self, led_id): def __init__(self, led_id):
pass pass
'''
# #
# BIPresentValue # BIPresentValue
@ -74,11 +78,17 @@ class BIPresentValue(Property):
errorClass="property", errorCode="propertyIsNotAnArray" errorClass="property", errorCode="propertyIsNotAnArray"
) )
###TODO: obj._button is the Button object ###TODO: obj._button is the Button object
if _debug: if _debug:
BIPresentValue._debug(" - read button: %r", obj._button) BIPresentValue._debug(" - read button: %r", obj._button)
return "inactive" if obj._button.is_pressed:
return "active"
else:
return "inactive"
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
if _debug: if _debug:
@ -138,8 +148,16 @@ class BOPresentValue(Property):
errorClass="property", errorCode="propertyIsNotAnArray" errorClass="property", errorCode="propertyIsNotAnArray"
) )
###TODO: obj._led is the LED object ###TODO: obj._led is the LED object
return "inactive" if _debug:
BOPresentValue._debug(" - read led: %r", obj._led)
if obj._led.value == 1:
return "active"
else:
return "inactive"
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False): def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
if _debug: if _debug:
@ -162,7 +180,15 @@ class BOPresentValue(Property):
if _debug: if _debug:
BOPresentValue._debug(" - write led: %r", obj._led) BOPresentValue._debug(" - write led: %r", obj._led)
raise ExecutionError(errorClass="property", errorCode="writeAccessDenied") #raise ExecutionError(errorClass="property", errorCode="writeAccessDenied")
if value == "active":
obj._led.on()
elif value == "inactive":
obj._led.off()
else:
### TODO: insert correct value error. Below is a placeholder.
print("invalid value for led. Use 'active' to turn on or 'inactive' to turn off.")
# #