# Device Info Set

## discover_info_set()

`canlib.kvrlib.``discover_info_set`(delay=100, timeout=1000, addresses=None, report_stored=True)

## empty_info_set()

`canlib.kvrlib.``empty_info_set`()

## stored_info_set()

`canlib.kvrlib.``stored_info_set`()

## DeviceInfoSet

class `canlib.kvrlib.``DeviceInfoSet`(iterable=None)

  A mutable set of `DeviceInfo` objects that can be written to the registry

  There 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 a `canlib.kvrlib.Discovery`.

  Once a `DeviceInfoSet` has been created it can be modified as a normal set, and the `DeviceInfo` elements can also be modified. Once all modification is done, the set can be written to the registry with `DeviceInfoSet.store`.

  The main difference between `DeviceInfoSet` and normal sets is that it can only contain one `DeviceInfo` with a specific combination of EAN and serial number, even if they otherwise are not equal. This means that even if `info 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 use `DeviceInfoSet.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)

    Add a `DeviceInfo` to this `DeviceInfoSet`

    Parameters: | info (`DeviceInfo`) – The element to add to this set

    If the set already contains a `DeviceInfo` with the same EAN and serial number as `info`, the previous `DeviceInfo` will be discarded and replaced by `info`.

  `discard`(info)

    Remove an element. Do not raise an exception if absent.

  `find`(ean, serial)

    Find and return a specific `DeviceInfo` in this set

    Parameters: | ean (`canlib.ean.EAN`) – The EAN to search for serial (`int`) – The serial number to search for

    If no `DeviceInfo` with the EAN and serial number is found in this set, `canlib.kvrlib.DeviceNotInSetError` is raised.

    Note that there can never be more than one `DeviceInfo` with the same EAN and serial number in a `DeviceInfoSet`.

  `find_remove`(ean, serial)

    Find a specific `DeviceInfo` and remove it from this set

    Like `DeviceInfoSet.find` but immediately removes the `DeviceInfo` found from the set.

    Parameters: | ean (`canlib.ean.EAN`) – The EAN to search for serial (`int`) – The serial number to search for

  `has`(ean, serial)

    Check whether the set contains a specific `DeviceInfo`

    Similar to `DeviceInfoSet.find` but instead of returning a `DeviceInfo` or raising an exception, this function returns `True` or `False`.

    Parameters: | ean (`canlib.ean.EAN`) – The EAN to search for serial (`int`) – The serial number to search for

  `new_info`(ean, serial, **attrs)

    Create and return new `DeviceInfo` in this set

    Any 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 (`canlib.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 EAN `ean` and serial number `serial`, the previous `DeviceInfo` will be discarded and replaced by the new `DeviceInfo` created by this function.

  `store`()

    Store this set’s `DeviceInfo` objects in the registry

  `update`(*others)

    Update the set, adding elements from all others

    All `others` must contain nothing but `DeviceInfo` objects, or this function will raise `TypeError` without modifying this `DeviceInfoSet`.