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 the load_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 to DEFAULT_FILENAME
  • loop – The EventLoop to use. If not given, the value from asyncio.get_event_loop() will be used.
  • auto_start (bool) – If True (default), the start() method will be added to the asyncio event loop on initialization.
vidhubs

A DictProperty of VidhubConfig instances using device_id as keys

Type:dict
smartviews

A DictProperty of SmartViewConfig instances using device_id as keys

Type:dict
smartscopes

A DictProperty of SmartScopeConfig instances using device_id as keys

Type: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, the DeviceConfigBase.backend value of the matching DeviceConfigBase instance will be set to the given backend. Otherwise, a new DeviceConfigBase instance will be created using the DeviceConfigBase.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 using add_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 to Config.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 will await all start-up coroutines and futures before returning.

Parameters:filename (str, optional) – The filename to read config data from, defaults to DEFAULT_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 current filename is used.

Notes

If the filename argument is provided, it will replace the existing filename value.

coroutine start(**kwargs)[source]

Starts the device backends and discovery routines

Keyword arguments passed to the initialization will be used here, but can be overridden in this method. They will also be passed to _initialize_backends().

coroutine stop()[source]

Stops all device backends and discovery routines

class vidhubcontrol.config.DeviceConfigBase(**kwargs)[source]

Bases: vidhubcontrol.config.ConfigBase

Base class for device config storage

config

A reference to the parent Config instance

backend

An instance of vidhubcontrol.backends.base.BackendBase

backend_name

The class name of the backend, used when loading from saved config data

Type:str
hostaddr

The IPv4 address of the device

Type:str
hostport

The port address of the device

Type:int
device_name

User-defined name to store with the device, defaults to the device_id value

Type:str
device_id

The unique id as reported by the device

Type:str
backend_unavailable

True if communication with the device could not be established

Type: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 of device_type and backend_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() method

Parameters: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 device

Type: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 of device_type and backend_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() method

Parameters: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