vidhubcontrol.config
¶
- class vidhubcontrol.config.Config(*args, **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())
- Keyword Arguments
filename (
str
, optional) – Filename to load/save config data to. If not given, defaults toDEFAULT_FILENAME
- vidhubs¶
A
DictProperty
ofVidhubConfig
instances usingdevice_id
as keys- Type
- smartviews¶
A
DictProperty
ofSmartViewConfig
instances usingdevice_id
as keys- Type
- smartscopes¶
A
DictProperty
ofSmartScopeConfig
instances usingdevice_id
as keys- Type
- all_devices¶
A
DictProperty
containing all devices fromvidhubs
,smartviews
andsmartscopes
- Type
- DEFAULT_FILENAME = '~/vidhubcontrol.json'¶
- async 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 vidhubcontrol.backends
- async 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 vidhubcontrol.backends
- Returns
An instance of a
vidhubcontrol.backends.base.BackendBase
subclass
- connection_manager: vidhubcontrol.common.ConnectionManager¶
Connection manager
- property connection_state: vidhubcontrol.common.ConnectionState¶
The current
state
of theconnection_manager
- 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
- async classmethod 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(*args, **kwargs)[source]¶
Bases:
vidhubcontrol.config.ConfigBase
Base class for device config storage
- backend¶
An instance of
vidhubcontrol.backends.base.BackendBase
- async 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
- connection_manager: vidhubcontrol.common.SyncronizedConnectionManager¶
A connection manager that syncronizes its state with the
backend
- property connection_state: vidhubcontrol.common.ConnectionState¶
The current
state
of theconnection_manager
- async classmethod 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
- async classmethod from_existing(backend, **kwargs)[source]¶
Creates a device config object from an existing backend
Keyword arguments will be passed to the
create()
method- Parameters
backend – An instance of
vidhubcontrol.backends.base.BackendBase
- Returns
An instance of
DeviceConfigBase
- class vidhubcontrol.config.SmartScopeConfig(*args, **kwargs)[source]¶
Bases:
vidhubcontrol.config.DeviceConfigBase
Config container for SmartScope devices
- class vidhubcontrol.config.SmartViewConfig(*args, **kwargs)[source]¶
Bases:
vidhubcontrol.config.DeviceConfigBase
Config container for SmartView devices
- class vidhubcontrol.config.VidhubConfig(*args, **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 device- Type
List[Dict]
- async 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
- async classmethod 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
- async classmethod from_existing(backend, **kwargs)[source]¶
Creates a device config object from an existing backend
Keyword arguments will be passed to the
create()
method- Parameters
backend – An instance of
vidhubcontrol.backends.base.BackendBase
- Returns
An instance of
DeviceConfigBase