jvconnected.common

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

Bases: IntFlag

State used in ReconnectStatus

UNKNOWN = 1

Unknown state

SCHEDULING = 2

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

SLEEPING = 4

The ReconnectStatus.task is waiting before attempting to reconnect

ATTEMPTING = 8

The connection is being established

CONNECTED = 16

Connection attempt success

FAILED = 32

Connection has been lost

DISCONNECT = 64

User manually disconnected

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

Bases: Enum

Possible values used in engine.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

USER = 5

User manually removed the device

SHUTDOWN = 6

The engine is shutting down

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

Bases: object

Holds state used in device reconnect methods

device_id: str

The associated device id

state: ConnectionState = 1

Current ConnectionState

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

async set_state(state: ConnectionState)[source]

Set the state

async wait_for_state(state: ConnectionState, timeout: float | int | None = None)[source]

Wait for a specific state value(s)

Parameters
  • state (ConnectionState) – May be a single ConnectionState member or a combination of multiple members (using bitwise OR |)

  • timeout (float | int | None) – If not None, wait the given number of seconds for the state. Otherwise, wait indefinitely.

Raises

asyncio.TimeoutError – If the state was not set within the given timeout

async wait_for_connect_or_failure(timeout: float | int | None = None)[source]

Shortcut to wait for CONNECTED or FAILED