panoptes.pocs.utils.service package

Submodules

panoptes.pocs.utils.service.power module

FastAPI service exposing power board status, readings, and control endpoints.

This module initializes a PowerBoard instance during application lifespan and periodically records telemetry to the database. It exposes simple REST endpoints for querying current status/readings and for toggling relays via POST/GET.

class panoptes.pocs.utils.service.power.RelayAction(*values)[source]

Bases: StrEnum

Enumeration of supported relay actions.

turn_off = 'turn_off'
turn_on = 'turn_on'
class panoptes.pocs.utils.service.power.RelayCommand(*, relay: str | int, command: RelayAction)[source]

Bases: BaseModel

Command payload for controlling a relay.

relay

Relay label or index.

Type:

str | int

command

Action to perform on the relay.

Type:

RelayAction

command: RelayAction
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

relay: str | int
panoptes.pocs.utils.service.power.control_relay(relay_command: RelayCommand, power_board: Annotated[PowerBoard, Depends(dependency=get_power_board, use_cache=True, scope=None)])[source]

Control a relay via a POST request.

Parameters:
  • relay_command (RelayCommand) – The relay identifier and action to perform.

  • power_board (PowerBoardDep) – The active PowerBoard instance.

Returns:

Echo of the command that was executed upon success.

Return type:

RelayCommand

panoptes.pocs.utils.service.power.control_relay_url(relay: int | str, power_board: Annotated[PowerBoard, Depends(dependency=get_power_board, use_cache=True, scope=None)], command: str = 'turn_on')[source]

Control a relay via a GET request.

Parameters:
  • relay (int | str) – The relay index or label to control.

  • power_board (PowerBoardDep) – The active PowerBoard instance.

  • command (str) – The action to perform, e.g. “turn_on” or “turn_off”.

Returns:

Echo of the command that was executed upon success.

Return type:

RelayCommand

Raises:

HTTPException – 422 if the command string is not a valid RelayAction.

panoptes.pocs.utils.service.power.do_command(relay_command: RelayCommand, power_board: PowerBoard)[source]

Control a relay.

This function performs the actual relay control and is used by both request types.

Parameters:
  • relay_command (RelayCommand) – The relay identifier and action to execute.

  • power_board (PowerBoard) – The active PowerBoard instance.

Returns:

Echo of the command that was executed.

Return type:

RelayCommand

panoptes.pocs.utils.service.power.get_power_board(request: Request) PowerBoard[source]

Dependency that retrieves the PowerBoard from application state.

Parameters:

request (Request) – The incoming FastAPI request.

Returns:

The active PowerBoard instance.

Return type:

PowerBoard

panoptes.pocs.utils.service.power.lifespan(app: FastAPI)[source]

Context manager for the FastAPI application’s lifespan.

This will connect to the power board and start a background thread that periodically records readings at a configured interval.

Parameters:

app (FastAPI) – The FastAPI application instance.

Yields:

None – Control to FastAPI while the app is running.

async panoptes.pocs.utils.service.power.readings(power_board: Annotated[PowerBoard, Depends(dependency=get_power_board, use_cache=True, scope=None)])[source]

Return the current readings as a dict.

async panoptes.pocs.utils.service.power.root(power_board: Annotated[PowerBoard, Depends(dependency=get_power_board, use_cache=True, scope=None)])[source]

Returns the power board status.

panoptes.pocs.utils.service.weather module

Module contents