jvconnected.engine

class jvconnected.engine.Engine(*args, **kwargs)[source]

Bases: pydispatch.dispatch.Dispatcher

Top level component to handle config, discovery and device control

Properties
interfaces: dict DictProperty(dict)

Container for jvconnected.interfaces.base.Interface instances

devices: dict DictProperty(dict)

Container for Device instances

auto_add_devices: bool Property(bool)

If True, devices will be added automatically when discovered on the network. Otherwise, they must be added manually using add_device_from_conf()

Attributes
Events
on_config_device_added(conf_device)

Fired when an instance of DeviceConfig is added

on_device_discovered(conf_device)

Fired when a device is detected on the network. An instance of DeviceConfig is found (or created) and passed as the argument

on_device_added(device)

Fired when an instance of Device is added to devices

on_device_removed(device: jvconnected.device.Device, reason: RemovalReason)

Fired when an instance of Device is removed

Parameters
run_forever()[source]

Convenience method to open and run until interrupted

async open()[source]

Open all communication methods

async add_always_connected_devices()[source]

Create and open any devices with always_connect set to True

async close()[source]

Close the discovery engine and any running device clients

async add_device_from_conf(device_conf: jvconnected.config.DeviceConfig)[source]

Add a client Device instance from the given DeviceConfig and attempt to connect.

If auth information is incorrect or does not exist, display the error and remove the newly added device.

add_discovered_device(info: zeroconf.ServiceInfo) jvconnected.config.DeviceConfig[source]

Create a DeviceConfig and add it to discovered_devices

class jvconnected.engine.RemovalReason(value)[source]

Bases: enum.Enum

Possible values used in Engine.on_device_removed

UNKNOWN = 1

Unknown reason

OFFLINE = 2

The device is no longer on the network

TIMEOUT = 3

Communication was lost due to a timeout. Reconnection will be attempted

AUTH = 4

Authentication with the device failed, likely due to invalid credentials

SHUTDOWN = 5

The engine is shutting down

class jvconnected.engine.ReconnectStatus(device_id: str, state: jvconnected.engine.ConnectionState = ConnectionState.UNKNOWN, reason: jvconnected.engine.RemovalReason = RemovalReason.UNKNOWN, task: Optional[_asyncio.Task] = None, num_attempts: int = 0, lock: asyncio.locks.Lock = <factory>)[source]

Bases: object

Holds state used in device reconnect methods

device_id: str

The associated device id

state: jvconnected.engine.ConnectionState = 1

Current ConnectionState

reason: jvconnected.engine.RemovalReason = 1

The RemovalReason for disconnect

task: Optional[_asyncio.Task] = None

The current asyncio.Task scheduled to reconnect

num_attempts: int = 0

Number of reconnect attempts

class jvconnected.engine.ConnectionState(value)[source]

Bases: enum.Enum

State used in ReconnectStatus

UNKNOWN = 1

Unknown state

SCHEDULING = 2

A task is being scheduled to reconnect, but it has not begun execution

SLEEPING = 3

The ReconnectStatus.task is waiting before attempting to reconnect

ATTEMPTING = 4

The connection is being established

CONNECTED = 5

Connection attempt success

FAILED = 6

Connection has been lost