powersensor_local.devices

Classes

PowersensorDevices([broadcast_address])

Abstraction interface for the unified event stream from all Powersensor devices on the local network.

class powersensor_local.devices.PowersensorDevices(broadcast_address='<broadcast>')[source]

Bases: object

Abstraction interface for the unified event stream from all Powersensor devices on the local network.

async rescan()[source]

Performs a fresh scan of the network to discover added devices, or devices which have changed their IP address for some reason.

async start(async_event_callback)[source]

Registers the async event callback function and starts the scan of the local network to discover present devices. The callback is of the form

Parameters:

async_event_callback : Callable

A callable asynchronous method for handling json messages. Example:

async def your_callback(event: dict):
    pass

Known Events:

  • scan_complete

    Indicates the discovery of Powersensor devices has completed. Emitted in response to start() and rescan() calls. The number of found gateways (plugs) is reported.:

    { event: "scan_complete", gateway_count: N }
    
  • device_found

    A new device found on the network. The order found devices are announced is not fixed.:

    { event: "device_found",
      device_type: "plug" or "sensor",
      mac: "...",
    }
    

    An optional field named “via” is present for sensor devices, and shows the MAC address of the gateway the sensor is communicating via.

  • device_lost

    A device appears to no longer be present on the network.:

    { event: "device_lost", mac: "..." }
    

Additionally, all events described in xlatemsg.translate_raw_message may be issued. The event name is inserted into the field ‘event’.

The start function returns the number of found gateway plugs. Powersensor devices aren’t found directly as they are typically not on the network, but are instead detected when they relay data through a plug via long-range radio.

async stop()[source]

Stops the event streaming and disconnects from the devices. To restart the event streaming, call start() again.

subscribe(mac)[source]

Subscribes to events from the device with the given MAC address.

unsubscribe(mac)[source]

Unsubscribes from events from the given MAC address.