import click
from caspia.node import components
from caspia.node.cli import utils
@utils.component_group_command(components.AnalogOutput)
def analogoutput(*args, **kwargs):
"""Communicate with an AnalogOutput Component."""
[docs]def print_state(st):
click.secho('Output is {}, value: {}.'.format('on' if st.is_on else 'off', st.value),
fg='green')
@analogoutput.command()
@utils.with_group_component
async def toggle(component):
"""Toggle the analog output."""
print_state(await component.toggle())
@analogoutput.command()
@utils.with_group_component
async def on(component):
"""Switch analog output on."""
print_state(await component.on())
@analogoutput.command()
@utils.with_group_component
async def off(component):
"""Switch analog output off."""
print_state(await component.off())
@analogoutput.command()
@utils.with_group_component
async def state(component):
"""Print current state of an analog output."""
print_state(await component.load_state())
@analogoutput.command(name='set')
@click.argument('value', type=float)
@utils.with_group_component
async def set_cmd(component, value):
"""Set current state of an analog output."""
print_state(await component.set(value))