config module¶
-
class
vidhubcontrol.config.Config(**kwargs)[source]¶ Bases:
vidhubcontrol.config.ConfigBaseConfig store for devices
Handles storage of device connection information and any user-defined values for the backends defined in the backends module. Data is stored in JSON format.
During
start(), all previously stored devices will be loaded and begin communication. Devices are also discovered using Zeroconf through the discovery module.Since each device has a unique id, network address changes (due to DHCP, etc) are handled appropriately.
The configuration data is stored when:
- A device is added or removed
- A change is detected for a device’s network address
- Any user-defined device value changes (device name, presets, etc)
The recommended method to start
Configis through theload_async()method.Example
import asyncio from vidhubcontrol.config import Config loop = asyncio.get_event_loop() conf = loop.run_until_complete(Config.load_async(loop=loop))
Keyword Arguments: - filename (
str, optional) – Filename to load/save config data to. If not given, defaults toDEFAULT_FILENAME - loop – The
EventLoopto use. If not given, the value fromasyncio.get_event_loop()will be used. - auto_start (bool) – If
True(default), thestart()method will be added to the asyncio event loop on initialization.
-
vidhubs¶ A
DictPropertyofVidhubConfiginstances usingdevice_idas keysType: dict
-
smartviews¶ A
DictPropertyofSmartViewConfiginstances usingdevice_idas keysType: dict
-
smartscopes¶ A
DictPropertyofSmartScopeConfiginstances usingdevice_idas keysType: dict
-
DEFAULT_FILENAME= '~/vidhubcontrol.json'¶
-
coroutine
add_device(backend)[source]¶ Adds a “backend” instance to the config
A subclass of
DeviceConfigBasewill be either created or updated from the given backend instance.If the
device_idexists in the config, theDeviceConfigBase.backendvalue of the matchingDeviceConfigBaseinstance will be set to the givenbackend. Otherwise, a newDeviceConfigBaseinstance will be created using theDeviceConfigBase.from_existing()classmethod.Parameters: backend – An instance of one of the subclasses of vidhubcontrol.backends.base.BackendBasefound in backends package
-
coroutine
build_backend(device_type, backend_name, **kwargs)[source]¶ Creates a “backend” instance
The supplied keyword arguments are used to create the instance object which will be created using its
create()classmethod.The appropriate subclass of
DeviceConfigBasewill be created and stored to the config usingadd_device().Parameters: - device_type (str) – Device type to create. Choices are “vidhub”, “smartview”, “smartscope”
- backend_name (str) – The class name of the backend as found in backends package
Returns: An instance of a
vidhubcontrol.backends.base.BackendBasesubclass
-
classmethod
load(filename=None, **kwargs)[source]¶ Creates a Config instance, loading data from the given filename
Parameters: filename ( str, optional) – The filename to read config data from, defaults toConfig.DEFAULT_FILENAMEReturns: A Configinstance
-
coroutine
load_async(filename=None, **kwargs)[source]¶ Creates a Config instance, loading data from the given filename
This coroutine method creates the
Configinstance and willawaitall start-up coroutines and futures before returning.Parameters: filename ( str, optional) – The filename to read config data from, defaults toDEFAULT_FILENAMEReturns: A Configinstance
-
save(filename=None)[source]¶ Saves the config data to the given filename
Parameters: filename ( str, optional) – The filename to write config data to. If not supplied, the currentfilenameis used.Notes
If the
filenameargument is provided, it will replace the existingfilenamevalue.
-
class
vidhubcontrol.config.DeviceConfigBase(**kwargs)[source]¶ Bases:
vidhubcontrol.config.ConfigBaseBase class for device config storage
-
backend¶ An instance of
vidhubcontrol.backends.base.BackendBase
Trueif communication with the device could not be establishedType: bool
-
coroutine
build_backend(cls=None, **kwargs)[source]¶ Creates a backend instance asynchronously
Keyword arguments will be passed to the
vidhubcontrol.backends.base.BackendBase.create_async()method.Parameters: cls (optional) – A subclass of BackendBase. If not present, the class will be determined from existing values ofdevice_typeandbackend_nameReturns: An instance of vidhubcontrol.backends.base.BackendBase
-
coroutine
create(**kwargs)[source]¶ Creates device config and backend instances asynchronously
Keyword arguments passed to this classmethod are passed to the init method and will be used to set its attributes.
If a “backend” keyword argument is supplied, it should be a running instance of
vidhubcontrol.backends.base.BackendBase. It will then be used to collect config values from.If “backend” is not present, the appropriate one will be created using
build_backend().Returns: An instance of DeviceConfigBase
-
coroutine
from_existing(backend, **kwargs)[source]¶ Creates a device config object from an existing backend
Keyword arguments will be passed to the
create()methodParameters: backend – An instance of vidhubcontrol.backends.base.BackendBaseReturns: An instance of DeviceConfigBase
-
-
class
vidhubcontrol.config.VidhubConfig(**kwargs)[source]¶ Bases:
vidhubcontrol.config.DeviceConfigBaseConfig container for VideoHub devices
-
presets¶ Preset data collected from the device
presets. Will be used on initialization to populate the preset data to the deviceType: list
-
coroutine
build_backend(cls=None, **kwargs)[source]¶ Creates a backend instance asynchronously
Keyword arguments will be passed to the
vidhubcontrol.backends.base.BackendBase.create_async()method.Parameters: cls (optional) – A subclass of BackendBase. If not present, the class will be determined from existing values ofdevice_typeandbackend_nameReturns: An instance of vidhubcontrol.backends.base.BackendBase
-
coroutine
create(**kwargs)[source]¶ Creates device config and backend instances asynchronously
Keyword arguments passed to this classmethod are passed to the init method and will be used to set its attributes.
If a “backend” keyword argument is supplied, it should be a running instance of
vidhubcontrol.backends.base.BackendBase. It will then be used to collect config values from.If “backend” is not present, the appropriate one will be created using
build_backend().Returns: An instance of DeviceConfigBase
-
coroutine
from_existing(backend, **kwargs)[source]¶ Creates a device config object from an existing backend
Keyword arguments will be passed to the
create()methodParameters: backend – An instance of vidhubcontrol.backends.base.BackendBaseReturns: An instance of DeviceConfigBase
-
-
class
vidhubcontrol.config.SmartViewConfig(**kwargs)[source]¶ Bases:
vidhubcontrol.config.DeviceConfigBaseConfig container for SmartView devices
-
class
vidhubcontrol.config.SmartScopeConfig(**kwargs)[source]¶ Bases:
vidhubcontrol.config.DeviceConfigBaseConfig container for SmartScope devices