Device Info Set¶
discover_info_set()¶
empty_info_set()¶
stored_info_set()¶
DeviceInfoSet¶
- class canlib.kvrlib.DeviceInfoSet(iterable=None)[source]¶
A mutable set of
DeviceInfo
objects that can be written to the registryThere are three different functions for creating
DeviceInfoSet
objects:empty_info_set
: Creates an empty set.stored_info_set
: Creates a set from the device information stored in the registry.discover_info_set
: Create a set from the results of aDiscovery
.
Once a
DeviceInfoSet
has been created it can be modified as a normal set, and theDeviceInfo
elements can also be modified. Once all modification is done, the set can be written to the registry withDeviceInfoSet.store
.The main difference between
DeviceInfoSet
and normal sets is that it can only contain oneDeviceInfo
with a specific combination of EAN and serial number, even if they otherwise are not equal. This means that even ifinfo in infoset
evaluates to true, that exact object may not be in the set, and modifying it may not change the set.To retrieve a specific
DeviceInfo
from the set useDeviceInfoSet.find
:info = infoset.find(ean='01234-5', serial=42)
Modifying the resulting
DeviceInfo
will then change the contents of the set.Instances of this class can also be used as context managers, in which case they will write their content to the registry when the context exists.
- add(info)[source]¶
Add a
DeviceInfo
to thisDeviceInfoSet
- Parameters
info (
DeviceInfo
) – The element to add to this set
If the set already contains a
DeviceInfo
with the same EAN and serial number asinfo
, the previousDeviceInfo
will be discarded and replaced byinfo
.
- find(ean, serial)[source]¶
Find and return a specific
DeviceInfo
in this set- Parameters
ean (
EAN
) – The EAN to search forserial (
int
) – The serial number to search for
If no
DeviceInfo
with the EAN and serial number is found in this set,DeviceNotInSetError
is raised.Note that there can never be more than one
DeviceInfo
with the same EAN and serial number in aDeviceInfoSet
.
- find_remove(ean, serial)[source]¶
Find a specific
DeviceInfo
and remove it from this setLike
DeviceInfoSet.find
but immediately removes theDeviceInfo
found from the set.- Parameters
ean (
EAN
) – The EAN to search forserial (
int
) – The serial number to search for
- has(ean, serial)[source]¶
Check whether the set contains a specific
DeviceInfo
Similar to
DeviceInfoSet.find
but instead of returning aDeviceInfo
or raising an exception, this function returnsTrue
orFalse
.- Parameters
ean (
EAN
) – The EAN to search forserial (
int
) – The serial number to search for
- new_info(ean, serial, **attrs)[source]¶
Create and return new
DeviceInfo
in this setAny attribute of the
DeviceInfo
that should have a specific value can be passed as keyword arguments to this function.The EAN and serial number must be provided.
- Parameters
ean (
EAN
) – The EAN of the info (DeviceInfo.ean
)serial (
int
) – The serial number of the info (DeviceInfo.serial
)attrs – Any other attributes to be set on the
DeviceInfo
If the set already contains a
DeviceInfo
with the EANean
and serial numberserial
, the previousDeviceInfo
will be discarded and replaced by the newDeviceInfo
created by this function.
- store()[source]¶
Store this set’s
DeviceInfo
objects in the registry
- update(*others)[source]¶
Update the set, adding elements from all others
All
others
must contain nothing butDeviceInfo
objects, or this function will raiseTypeError
without modifying thisDeviceInfoSet
.