DoorOpenerPicoWeb

class DoorOpenerPicoWeb(credentials, discovery_payload)

Web subclass of DoorOpenerPicoNetwork, implements web server functionality.

__init__(credentials, discovery_payload)

Initialises the wireless interface amd MQTT client, loads login credentials, discovery payload and configuration options, initialises board hardware devices, sets up networking (including the web server) and indicates the board has started by flashing the control panel LEDs alternately.

Parameters:
  • credentials (dict) – Wireless network and MQTT login credentials.

  • discovery_payload (dict) – The discovery payload to be sent to the MQTT server.

Methods

__init__(credentials, discovery_payload)

Initialises the wireless interface amd MQTT client, loads login credentials, discovery payload and configuration options, initialises board hardware devices, sets up networking (including the web server) and indicates the board has started by flashing the control panel LEDs alternately.

_get_conf_keys()

Returns the keys that should be present in the configuration file, overridden from _get_conf_keys().

Returns:

The list of keys.

Return type:

list

_get_event_loop()

Adds suitable methods to the event loop and returns it. Overridden from _get_event_loop() to add a web server task.

Returns:

The event loop.

Return type:

class

_network_setup()

Initialises MQTT topic variables, connects to the wifi and MQTT broker, publishes the MQTT discovery payload so Home Assistant can create a suitable entity, sets the availability of the door opener and sets up the web server. Overridden from _network_setup().

async _send_state(socket, time=None, time_error=False)

Sends the current state of the door opener via websocket connection.

Parameters:
  • socket (WebSocket) – The websocket connection to use.

  • time (float) – The time taken to actuate the door (if applicable).

  • time_error (str) – Error message to indicate the door couldn’t actuate (if applicable).

_set_state(state)

Publishes the door state to the MQTT broker and sets LED activity appropriately (only in the case of the door being open or closed). Overrides _set_state().

This overridden method is a workaround and has the whole state setting procedure as trying to set LED to pulse while the web server is running with multiple super() calls results in recursion limit problems (stack size isn’t big enough and results in a crash). Don’t refactor this.

Parameters:

state (str) – State to set, can be “open”, “closed”, “opening” or “closing”.

async _time_actuation(socket)

Finds the amount of time the door takes to open or close and sends the result via websocket connection, useful for tuning reed switch timeout values.

Parameters:

socket (WebSocket) – The websocket connection to use.

_web_setup()

Initialises the webserver and all associated routes, also sets up the websocket route and sets up method dispatchers for any websocket messages recieved.