1 # Copyright (C) 2010 Richard Lincoln
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
17 from CIM14
.IEC61970
.Core
.ConductingEquipment
import ConductingEquipment
19 class Switch(ConductingEquipment
):
20 """A generic device designed to close, or open, or both, one or more electric circuits.
23 def __init__(self
, switchOnCount
=0, switchOnDate
='', retained
=False, normalOpen
=False, SwitchingOperations
=None, CompositeSwitch
=None, ConnectDisconnectFunctions
=None, SwitchSchedules
=None, *args
, **kw_args
):
24 """Initialises a new 'Switch' instance.
26 @param switchOnCount: The switch on count since the switch was last reset or initialized.
27 @param switchOnDate: The date and time when the switch was last switched on.
28 @param retained: Branch is retained in a bus branch model.
29 @param normalOpen: The attribute is used in cases when no Measurement for the status value is present. If the Switch has a status measurment the Discrete.normalValue is expected to match with the Switch.normalOpen.
30 @param SwitchingOperations: A switch may be operated by many schedules.
31 @param CompositeSwitch: Composite switch this Switch belongs to
32 @param ConnectDisconnectFunctions:
33 @param SwitchSchedules: A Switch can be associated with SwitchSchedules.
35 #: The switch on count since the switch was last reset or initialized.
36 self
.switchOnCount
= switchOnCount
38 #: The date and time when the switch was last switched on.
39 self
.switchOnDate
= switchOnDate
41 #: Branch is retained in a bus branch model.
42 self
.retained
= retained
44 #: The attribute is used in cases when no Measurement for the status value is present. If the Switch has a status measurment the Discrete.normalValue is expected to match with the Switch.normalOpen.
45 self
.normalOpen
= normalOpen
47 self
._SwitchingOperations
= []
48 self
.SwitchingOperations
= [] if SwitchingOperations
is None else SwitchingOperations
50 self
._CompositeSwitch
= None
51 self
.CompositeSwitch
= CompositeSwitch
53 self
._ConnectDisconnectFunctions
= []
54 self
.ConnectDisconnectFunctions
= [] if ConnectDisconnectFunctions
is None else ConnectDisconnectFunctions
56 self
._SwitchSchedules
= []
57 self
.SwitchSchedules
= [] if SwitchSchedules
is None else SwitchSchedules
59 super(Switch
, self
).__init
__(*args
, **kw_args
)
61 _attrs
= ["switchOnCount", "switchOnDate", "retained", "normalOpen"]
62 _attr_types
= {"switchOnCount": int, "switchOnDate": str, "retained": bool, "normalOpen": bool}
63 _defaults
= {"switchOnCount": 0, "switchOnDate": '', "retained": False, "normalOpen": False}
65 _refs
= ["SwitchingOperations", "CompositeSwitch", "ConnectDisconnectFunctions", "SwitchSchedules"]
66 _many_refs
= ["SwitchingOperations", "ConnectDisconnectFunctions", "SwitchSchedules"]
68 def getSwitchingOperations(self
):
69 """A switch may be operated by many schedules.
71 return self
._SwitchingOperations
73 def setSwitchingOperations(self
, value
):
74 for p
in self
._SwitchingOperations
:
75 filtered
= [q
for q
in p
.Switches
if q
!= self
]
76 self
._SwitchingOperations
._Switches
= filtered
78 if self
not in r
._Switches
:
79 r
._Switches
.append(self
)
80 self
._SwitchingOperations
= value
82 SwitchingOperations
= property(getSwitchingOperations
, setSwitchingOperations
)
84 def addSwitchingOperations(self
, *SwitchingOperations
):
85 for obj
in SwitchingOperations
:
86 if self
not in obj
._Switches
:
87 obj
._Switches
.append(self
)
88 self
._SwitchingOperations
.append(obj
)
90 def removeSwitchingOperations(self
, *SwitchingOperations
):
91 for obj
in SwitchingOperations
:
92 if self
in obj
._Switches
:
93 obj
._Switches
.remove(self
)
94 self
._SwitchingOperations
.remove(obj
)
96 def getCompositeSwitch(self
):
97 """Composite switch this Switch belongs to
99 return self
._CompositeSwitch
101 def setCompositeSwitch(self
, value
):
102 if self
._CompositeSwitch
is not None:
103 filtered
= [x
for x
in self
.CompositeSwitch
.Switches
if x
!= self
]
104 self
._CompositeSwitch
._Switches
= filtered
106 self
._CompositeSwitch
= value
107 if self
._CompositeSwitch
is not None:
108 self
._CompositeSwitch
._Switches
.append(self
)
110 CompositeSwitch
= property(getCompositeSwitch
, setCompositeSwitch
)
112 def getConnectDisconnectFunctions(self
):
114 return self
._ConnectDisconnectFunctions
116 def setConnectDisconnectFunctions(self
, value
):
117 for p
in self
._ConnectDisconnectFunctions
:
118 filtered
= [q
for q
in p
.Switches
if q
!= self
]
119 self
._ConnectDisconnectFunctions
._Switches
= filtered
121 if self
not in r
._Switches
:
122 r
._Switches
.append(self
)
123 self
._ConnectDisconnectFunctions
= value
125 ConnectDisconnectFunctions
= property(getConnectDisconnectFunctions
, setConnectDisconnectFunctions
)
127 def addConnectDisconnectFunctions(self
, *ConnectDisconnectFunctions
):
128 for obj
in ConnectDisconnectFunctions
:
129 if self
not in obj
._Switches
:
130 obj
._Switches
.append(self
)
131 self
._ConnectDisconnectFunctions
.append(obj
)
133 def removeConnectDisconnectFunctions(self
, *ConnectDisconnectFunctions
):
134 for obj
in ConnectDisconnectFunctions
:
135 if self
in obj
._Switches
:
136 obj
._Switches
.remove(self
)
137 self
._ConnectDisconnectFunctions
.remove(obj
)
139 def getSwitchSchedules(self
):
140 """A Switch can be associated with SwitchSchedules.
142 return self
._SwitchSchedules
144 def setSwitchSchedules(self
, value
):
145 for x
in self
._SwitchSchedules
:
149 self
._SwitchSchedules
= value
151 SwitchSchedules
= property(getSwitchSchedules
, setSwitchSchedules
)
153 def addSwitchSchedules(self
, *SwitchSchedules
):
154 for obj
in SwitchSchedules
:
156 self
._SwitchSchedules
.append(obj
)
158 def removeSwitchSchedules(self
, *SwitchSchedules
):
159 for obj
in SwitchSchedules
:
161 self
._SwitchSchedules
.remove(obj
)