1 # Copyright (C) 2010-2011 Richard Lincoln
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 from CIM14
.IEC61970
.Meas
.Measurement
import Measurement
23 class Discrete(Measurement
):
24 """Discrete represents a discrete Measurement, i.e. a Measurement reprsenting discrete values, e.g. a Breaker position.
27 def __init__(self
, normalValue
=0, minValue
=0, maxValue
=0, Command
=None, DiscreteValues
=None, ValueAliasSet
=None, *args
, **kw_args
):
28 """Initialises a new 'Discrete' instance.
30 @param normalValue: Normal measurement value, e.g., used for percentage calculations.
31 @param minValue: Normal value range minimum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values
32 @param maxValue: Normal value range maximum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values.
33 @param Command: The Control variable associated with the Measurement.
34 @param DiscreteValues: The values connected to this measurement.
35 @param ValueAliasSet: The ValueAliasSet used for translation of a MeasurementValue.value to a name
37 #: Normal measurement value, e.g., used for percentage calculations.
38 self
.normalValue
= normalValue
40 #: Normal value range minimum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values
41 self
.minValue
= minValue
43 #: Normal value range maximum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values.
44 self
.maxValue
= maxValue
47 self
.Command
= Command
49 self
._DiscreteValues
= []
50 self
.DiscreteValues
= [] if DiscreteValues
is None else DiscreteValues
52 self
._ValueAliasSet
= None
53 self
.ValueAliasSet
= ValueAliasSet
55 super(Discrete
, self
).__init
__(*args
, **kw_args
)
57 _attrs
= ["normalValue", "minValue", "maxValue"]
58 _attr_types
= {"normalValue": int, "minValue": int, "maxValue": int}
59 _defaults
= {"normalValue": 0, "minValue": 0, "maxValue": 0}
61 _refs
= ["Command", "DiscreteValues", "ValueAliasSet"]
62 _many_refs
= ["DiscreteValues"]
65 """The Control variable associated with the Measurement.
69 def setCommand(self
, value
):
70 if self
._Command
is not None:
71 self
._Command
._Discrete
= None
74 if self
._Command
is not None:
75 self
._Command
.Discrete
= None
76 self
._Command
._Discrete
= self
78 Command
= property(getCommand
, setCommand
)
80 def getDiscreteValues(self
):
81 """The values connected to this measurement.
83 return self
._DiscreteValues
85 def setDiscreteValues(self
, value
):
86 for x
in self
._DiscreteValues
:
90 self
._DiscreteValues
= value
92 DiscreteValues
= property(getDiscreteValues
, setDiscreteValues
)
94 def addDiscreteValues(self
, *DiscreteValues
):
95 for obj
in DiscreteValues
:
98 def removeDiscreteValues(self
, *DiscreteValues
):
99 for obj
in DiscreteValues
:
102 def getValueAliasSet(self
):
103 """The ValueAliasSet used for translation of a MeasurementValue.value to a name
105 return self
._ValueAliasSet
107 def setValueAliasSet(self
, value
):
108 if self
._ValueAliasSet
is not None:
109 filtered
= [x
for x
in self
.ValueAliasSet
.Discretes
if x
!= self
]
110 self
._ValueAliasSet
._Discretes
= filtered
112 self
._ValueAliasSet
= value
113 if self
._ValueAliasSet
is not None:
114 if self
not in self
._ValueAliasSet
._Discretes
:
115 self
._ValueAliasSet
._Discretes
.append(self
)
117 ValueAliasSet
= property(getValueAliasSet
, setValueAliasSet
)