DoorOpenerPicoBase¶
- class DoorOpenerPicoBase¶
Base class for the door opener, superclass of
DoorOpenerPicoNetworkandDoorOpenerPicoWeb.- __init__()¶
Loads configuration options, initialises board hardware devices and indicates the board has started by flashing the control panel LEDs alternately.
Methods
__init__()Loads configuration options, initialises board hardware devices and indicates the board has started by flashing the control panel LEDs alternately.
- _check_state()¶
Checks the state of the reed switches, the left and right switches have to be mutually exclusively activated for the state to be determined as open or closed.
- Returns:
The current state of the door as indicated by the sensors, can be “open”, “closed” or “error”.
- Return type:
str
- _clear_leds()¶
Turns off all the LEDs.
- _close()¶
Closes the door. Checks the sensors to determine that the door is actually open first, notifies with an error otherwise.
- _debug()¶
Prints out the state of the door opener, useful for debugging.
- _error_leds()¶
Blinks the red LED to indicate that the door could not successfully open or close.
- _force_closed()¶
Closes the door, doesn’t check the sensors first to determine whether to continue.
- _force_open()¶
Opens the door, doesn’t check the sensors first to determine whether to continue.
- _force_open_or_closed(state)¶
Opens or closes the door, doesn’t check the sensors first to determine whether to continue. Verifies the door opened or closed, displays error otherwise.
- Parameters:
state (str) – The intended state of the door, can be “open” or “closed”.
- _get_conf_keys()¶
Returns the keys that should be present in the configuration file, this method is overridden with additional keys in subclasses.
- Returns:
The list of keys.
- Return type:
list
- _get_event_loop()¶
Adds suitable methods to the event loop and returns it. Overridden with additional tasks (network specific, web server specific) in subclasses.
- Returns:
The event loop.
- Return type:
class
- _init_hardware()¶
Initialises the door opener hardware such as switches, LEDs, the servo and the relay.
- _load_config()¶
Validates the config file exists, contains the right keys with associated values, checks some assertions and returns the parsed config file.
- Returns:
The parsed conf file.
- Return type:
dict
- _loop()¶
Gets the main event loop and runs it forever.
- _open()¶
Opens the door if it is closed, or shows an error otherwise.
- _print_debug(message)¶
Prints a given debug message to the console (including date/time if enabled), wrapper around
print_debug().- Parameters:
message (str) – The message to print.
- _set_state(state)¶
Sets the LED activity appropriately, overridden in subclasses.
- Parameters:
state (str) – State to set, can be “open”, “closed”, “opening” or “closing”.
- _show_error()¶
Signifies the door is in the error state, flashes the red LED. Overridden in subclasses.
- _show_startup()¶
Signifies successful startup by flashing the LEDs alternately and printing to the console, sets the door state and starts the main event loop.
- _startup_leds(on_time=0.5, loops=2)¶
Indicates that the door opener has started by flashing the green and red LEDs alternately.
- Parameters:
on_time (float) – The time that each LED is on for, in seconds.
loops (int) – The number of times that the green and red LED should alternately flash (e.g. 2 means green -> red -> green -> red).
- _stop_servo()¶
Sets the servo to the stop position, stops the servo and disables the power relay that supplies the servo with power.
- async _switch_pressed()¶
Coroutine, checks if the door switch is pressed, checks that the door is open or closed and if so toggles the state, otherwise indicates an error with LEDs and a message.
- _toggle_door()¶
Toggles the door open or closed based on the state that the sensors report.
- _wait_for_reed(reed, timeout=0)¶
Returns either when the given reed switch is pressed, or when the timeout is reached.
- Parameters:
reed (Button) – A Button instance representing the relevant reed switch (left or right).
timeout (float) – Time after which the method returns if the reed is not yet activated, in seconds.