/
random_objects.py
133 lines (93 loc) · 4.2 KB
/
random_objects.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import random
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
from bacpypes.primitivedata import Real
from bacpypes.object import AnalogValueObject, BinaryValueObject, MultiStateValueObject
from bacpypes.object import AnalogInputObject, BinaryInputObject, MultiStateInputObject
from bacpypes.object import AnalogOutputObject, BinaryOutputObject, MultiStateOutputObject
from bacpypes.object import Property, register_object_type
_debug = 1
_log = ModuleLogger(globals())
class RandomValueProperty(Property):
def __init__(self, identifier):
if _debug: RandomValueProperty._debug("__init__ %r", identifier)
Property.__init__(self, identifier, Real, default=0.0, optional=True, mutable=False)
def ReadProperty(self, obj, arrayIndex=None):
if _debug: RandomValueProperty._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex)
# access an array
if arrayIndex is not None:
raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
# return a random value
value = random.random() * 100.0
if _debug: RandomValueProperty._debug(" - value: %r", value)
return value
def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
if _debug: RandomValueProperty._debug("WriteProperty %r %r arrayIndex=%r priority=%r direct=%r", obj, value, arrayIndex, priority, direct)
raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')
class RandomInputProperty(RandomValueProperty):
pass
class RandomOutputProperty(RandomValueProperty):
pass
bacpypes_debugging(RandomValueProperty)
class RandomAnalogValueObject(AnalogValueObject):
properties = [
RandomValueProperty('presentValue'),
]
def __init__(self, **kwargs):
if _debug: RandomAnalogValueObject._debug("__init__ %r", kwargs)
AnalogValueObject.__init__(self, **kwargs)
class RandomBinaryValueObject(BinaryValueObject):
properties = [
RandomValueProperty('presentValue'),
]
def __init__(self, **kwargs):
if _debug: RandomBinaryValueObject._debug("__init__ %r", kwargs)
BinaryValueObject.__init__(self, **kwargs)
class RandomMultiStateValueObject(MultiStateValueObject):
properties = [
RandomValueProperty('presentValue'),
]
def __init__(self, **kwargs):
if _debug: RandomMultiStateValueObject._debug("__init__ %r", kwargs)
MultiStateValueObject.__init__(self, **kwargs)
class RandomAnalogInputObject(AnalogInputObject):
properties = [
RandomInputProperty('presentInput'),
]
def __init__(self, **kwargs):
if _debug: RandomAnalogInputObject._debug("__init__ %r", kwargs)
AnalogInputObject.__init__(self, **kwargs)
class RandomBinaryInputObject(BinaryInputObject):
properties = [
RandomInputProperty('presentInput'),
]
def __init__(self, **kwargs):
if _debug: RandomBinaryInputObject._debug("__init__ %r", kwargs)
BinaryInputObject.__init__(self, **kwargs)
class RandomMultiStateInputObject(MultiStateInputObject):
properties = [
RandomInputProperty('presentInput'),
]
def __init__(self, **kwargs):
if _debug: RandomMultiStateInputObject._debug("__init__ %r", kwargs)
MultiStateInputObject.__init__(self, **kwargs)
class RandomAnalogOutputObject(AnalogOutputObject):
properties = [
RandomOutputProperty('presentOutput'),
]
def __init__(self, **kwargs):
if _debug: RandomAnalogOutputObject._debug("__init__ %r", kwargs)
AnalogOutputObject.__init__(self, **kwargs)
class RandomBinaryOutputObject(BinaryOutputObject):
properties = [
RandomOutputProperty('presentOutput'),
]
def __init__(self, **kwargs):
if _debug: RandomBinaryOutputObject._debug("__init__ %r", kwargs)
BinaryOutputObject.__init__(self, **kwargs)
class RandomMultiStateOutputObject(MultiStateOutputObject):
properties = [
RandomOutputProperty('presentOutput'),
]
def __init__(self, **kwargs):
if _debug: RandomMultiStateOutputObject._debug("__init__ %r", kwargs)
MultiStateOutputObject.__init__(self, **kwargs)