Source code for caspia.node.cli.commands.cmd_relay

import click

from caspia.node import components
from caspia.node.cli import utils


@utils.component_group_command(components.relay.Relay)
def relay(*args, **kwargs):
    """Communicate with a Relay Component."""





@relay.command()
@utils.with_group_component
async def toggle(component):
    """Toggle relay."""
    print_state(await component.toggle())


@relay.command()
@utils.with_group_component
async def on(component):
    """Switch relay on."""
    print_state(await component.on())


@relay.command()
@utils.with_group_component
async def off(component):
    """Switch relay off."""
    print_state(await component.off())


@relay.command()
@utils.with_group_component
async def state(component):
    """Print current state of a relay."""
    print_state(await component.load_state())