48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
|
from fastapi import APIRouter
|
||
|
import src.modules.Rel4HVI4.service as service
|
||
|
from typing import Dict
|
||
|
|
||
|
|
||
|
|
||
|
router = APIRouter(prefix="/rel4hvi4", tags=["Modules --> Rel4HVI4"])
|
||
|
|
||
|
|
||
|
|
||
|
@router.post("/relay/all/{state}", description="Set all relays to required state (1/0)")
|
||
|
def post_relay_all(state: bool):
|
||
|
service.set_relay_all(value=state)
|
||
|
|
||
|
@router.post("/relay/{stack}/{state}", description="Set all relays on specified card to required state (1/0)")
|
||
|
def post_relay_stack(stack: int, state: bool):
|
||
|
service.set_relay_stack(stack=stack, value=state)
|
||
|
|
||
|
@router.post("/relay/{stack}/{channel}/{state}", description="Set all relays on specified card to required state (1/0)")
|
||
|
def post_relay_stack(stack: int, channel, state: bool):
|
||
|
service.set_relay(stack=stack, relay=channel, value=state)
|
||
|
|
||
|
|
||
|
@router.get("/relay/all", description="Get state of all relays", response_model=Dict[int, Dict[int, bool]])
|
||
|
def get_relay_all():
|
||
|
return service.read_relay_all()
|
||
|
|
||
|
@router.get("/relay/{stack}", description="Get all relays state of specified card", response_model=Dict[int, bool])
|
||
|
def get_relay_stack(stack: int):
|
||
|
return service.read_relay_stack(stack=stack)
|
||
|
|
||
|
@router.get("/relay/{stack}/{channel}", description="Get state of selected relay", response_model=bool)
|
||
|
def get_relay(stack: int, channel: int):
|
||
|
return service.read_relay(stack=stack, relay=channel)
|
||
|
|
||
|
|
||
|
|
||
|
@router.get("/opto/all", description="Get input state of all opto inputs", response_model=Dict[int, Dict[int, bool]])
|
||
|
def get_opto_all():
|
||
|
return service.read_opto_all()
|
||
|
|
||
|
@router.get("/opto/{stack}", description="Get input state all opto inputs on selected card", response_model=Dict[int, bool])
|
||
|
def get_opto_stack(stack: int):
|
||
|
return service.read_opto_stack(stack=stack)
|
||
|
|
||
|
@router.get("/opto/{stack}/{channel}", description="Get state of selected input", response_model=bool)
|
||
|
def get_opto(stack: int, channel: int):
|
||
|
return service.read_opto(stack=stack, opto=channel)
|