config module¶
-
class
vidhubcontrol.config.
Config
(**kwargs)[source]¶ Bases:
vidhubcontrol.config.ConfigBase
Config 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
Config
is 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
EventLoop
to 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
DictProperty
ofVidhubConfig
instances usingdevice_id
as keysType: dict
-
smartviews
¶ A
DictProperty
ofSmartViewConfig
instances usingdevice_id
as keysType: dict
-
smartscopes
¶ A
DictProperty
ofSmartScopeConfig
instances usingdevice_id
as keysType: dict
-
DEFAULT_FILENAME
= '~/vidhubcontrol.json'¶
-
coroutine
add_device
(backend)[source]¶ Adds a “backend” instance to the config
A subclass of
DeviceConfigBase
will be either created or updated from the given backend instance.If the
device_id
exists in the config, theDeviceConfigBase.backend
value of the matchingDeviceConfigBase
instance will be set to the givenbackend
. Otherwise, a newDeviceConfigBase
instance will be created using theDeviceConfigBase.from_existing()
classmethod.Parameters: backend – An instance of one of the subclasses of vidhubcontrol.backends.base.BackendBase
found 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
DeviceConfigBase
will 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.BackendBase
subclass
-
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_FILENAME
Returns: A Config
instance
-
coroutine
load_async
(filename=None, **kwargs)[source]¶ Creates a Config instance, loading data from the given filename
This coroutine method creates the
Config
instance and willawait
all start-up coroutines and futures before returning.Parameters: filename ( str
, optional) – The filename to read config data from, defaults toDEFAULT_FILENAME
Returns: A Config
instance
-
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 currentfilename
is used.Notes
If the
filename
argument is provided, it will replace the existingfilename
value.
-
class
vidhubcontrol.config.
DeviceConfigBase
(**kwargs)[source]¶ Bases:
vidhubcontrol.config.ConfigBase
Base class for device config storage
-
backend
¶ An instance of
vidhubcontrol.backends.base.BackendBase
True
if 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_type
andbackend_name
Returns: 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.BackendBase
Returns: An instance of DeviceConfigBase
-
-
class
vidhubcontrol.config.
VidhubConfig
(**kwargs)[source]¶ Bases:
vidhubcontrol.config.DeviceConfigBase
Config 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_type
andbackend_name
Returns: 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.BackendBase
Returns: An instance of DeviceConfigBase
-
-
class
vidhubcontrol.config.
SmartViewConfig
(**kwargs)[source]¶ Bases:
vidhubcontrol.config.DeviceConfigBase
Config container for SmartView devices
-
class
vidhubcontrol.config.
SmartScopeConfig
(**kwargs)[source]¶ Bases:
vidhubcontrol.config.DeviceConfigBase
Config container for SmartScope devices