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
.IEC61968
.Assets
.AssetFunction
import AssetFunction
23 class DeviceFunction(AssetFunction
):
24 """Function performed by a device such as a meter, communication equipment, controllers, etc.
27 def __init__(self
, disabled
=False, EndDeviceAsset
=None, Registers
=None, EndDeviceEvents
=None, *args
, **kw_args
):
28 """Initialises a new 'DeviceFunction' instance.
30 @param disabled: True if the device function is disabled (deactivated). Default is false (i.e., function is enabled).
31 @param EndDeviceAsset: End device asset that performs this function.
32 @param Registers: All registers for quantities metered by this device function.
33 @param EndDeviceEvents: All events reported by this device function.
35 #: True if the device function is disabled (deactivated). Default is false (i.e., function is enabled).
36 self
.disabled
= disabled
38 self
._EndDeviceAsset
= None
39 self
.EndDeviceAsset
= EndDeviceAsset
42 self
.Registers
= [] if Registers
is None else Registers
44 self
._EndDeviceEvents
= []
45 self
.EndDeviceEvents
= [] if EndDeviceEvents
is None else EndDeviceEvents
47 super(DeviceFunction
, self
).__init
__(*args
, **kw_args
)
50 _attr_types
= {"disabled": bool}
51 _defaults
= {"disabled": False}
53 _refs
= ["EndDeviceAsset", "Registers", "EndDeviceEvents"]
54 _many_refs
= ["Registers", "EndDeviceEvents"]
56 def getEndDeviceAsset(self
):
57 """End device asset that performs this function.
59 return self
._EndDeviceAsset
61 def setEndDeviceAsset(self
, value
):
62 if self
._EndDeviceAsset
is not None:
63 filtered
= [x
for x
in self
.EndDeviceAsset
.DeviceFunctions
if x
!= self
]
64 self
._EndDeviceAsset
._DeviceFunctions
= filtered
66 self
._EndDeviceAsset
= value
67 if self
._EndDeviceAsset
is not None:
68 if self
not in self
._EndDeviceAsset
._DeviceFunctions
:
69 self
._EndDeviceAsset
._DeviceFunctions
.append(self
)
71 EndDeviceAsset
= property(getEndDeviceAsset
, setEndDeviceAsset
)
73 def getRegisters(self
):
74 """All registers for quantities metered by this device function.
76 return self
._Registers
78 def setRegisters(self
, value
):
79 for x
in self
._Registers
:
80 x
.DeviceFunction
= None
82 y
._DeviceFunction
= self
83 self
._Registers
= value
85 Registers
= property(getRegisters
, setRegisters
)
87 def addRegisters(self
, *Registers
):
89 obj
.DeviceFunction
= self
91 def removeRegisters(self
, *Registers
):
93 obj
.DeviceFunction
= None
95 def getEndDeviceEvents(self
):
96 """All events reported by this device function.
98 return self
._EndDeviceEvents
100 def setEndDeviceEvents(self
, value
):
101 for x
in self
._EndDeviceEvents
:
102 x
.DeviceFunction
= None
104 y
._DeviceFunction
= self
105 self
._EndDeviceEvents
= value
107 EndDeviceEvents
= property(getEndDeviceEvents
, setEndDeviceEvents
)
109 def addEndDeviceEvents(self
, *EndDeviceEvents
):
110 for obj
in EndDeviceEvents
:
111 obj
.DeviceFunction
= self
113 def removeEndDeviceEvents(self
, *EndDeviceEvents
):
114 for obj
in EndDeviceEvents
:
115 obj
.DeviceFunction
= None