Device Info Set¶
discover_info_set()¶
DeviceInfoSet¶
-
class
canlib.kvrlib.DeviceInfoSet(iterable=None)[source]¶ A mutable set of
DeviceInfoobjects that can be written to the registryThere are three different functions for creating
DeviceInfoSetobjects: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
DeviceInfoSethas been created it can be modified as a normal set, and theDeviceInfoelements can also be modified. Once all modification is done, the set can be written to the registry withDeviceInfoSet.store.The main difference between
DeviceInfoSetand normal sets is that it can only contain oneDeviceInfowith a specific combination of EAN and serial number, even if they otherwise are not equal. This means that even ifinfo in infosetevaluates to true, that exact object may not be in the set, and modifying it may not change the set.To retrieve a specific
DeviceInfofrom the set useDeviceInfoSet.find:info = infoset.find(ean='01234-5', serial=42)
Modifying the resulting
DeviceInfowill 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
DeviceInfoto thisDeviceInfoSetParameters: info ( DeviceInfo) – The element to add to this setIf the set already contains a
DeviceInfowith the same EAN and serial number asinfo, the previousDeviceInfowill be discarded and replaced byinfo.
-
find(ean, serial)[source]¶ Find and return a specific
DeviceInfoin this setParameters: - ean (
EAN) – The EAN to search for - serial (
int) – The serial number to search for
If no
DeviceInfowith the EAN and serial number is found in this set,DeviceNotInSetErroris raised.Note that there can never be more than one
DeviceInfowith the same EAN and serial number in aDeviceInfoSet.- ean (
-
find_remove(ean, serial)[source]¶ Find a specific
DeviceInfoand remove it from this setLike
DeviceInfoSet.findbut immediately removes theDeviceInfofound from the set.Parameters: - ean (
EAN) – The EAN to search for - serial (
int) – The serial number to search for
- ean (
-
has(ean, serial)[source]¶ Check whether the set contains a specific
DeviceInfoSimilar to
DeviceInfoSet.findbut instead of returning aDeviceInfoor raising an exception, this function returnsTrueorFalse.Parameters: - ean (
EAN) – The EAN to search for - serial (
int) – The serial number to search for
- ean (
-
new_info(ean, serial, **attrs)[source]¶ Create and return new
DeviceInfoin this setAny attribute of the
DeviceInfothat 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
DeviceInfowith the EANeanand serial numberserial, the previousDeviceInfowill be discarded and replaced by the newDeviceInfocreated by this function.- ean (
-
store()[source]¶ Store this set’s
DeviceInfoobjects in the registry
-
update(*others)[source]¶ Update the set, adding elements from all others
All
othersmust contain nothing butDeviceInfoobjects, or this function will raiseTypeErrorwithout modifying thisDeviceInfoSet.