Created
July 17, 2017 19:17
-
-
Save kantlivelong/ee16819ae25bf4199511b1f445c4cdf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cli_commands(self, cli_group, pass_octoprint_ctx, *args, **kwargs): | |
import click | |
import sys | |
import requests.exceptions | |
from octoprint_client import Client, build_base_url | |
def _api_command(command): | |
host = cli_group.settings.get(["server", "host"]) | |
host = host if host != "0.0.0.0" else "127.0.0.1" | |
port = cli_group.settings.getInt(["server", "port"]) | |
baseurl = build_base_url(host=host, port=port, prefix="/api") | |
api_key = cli_group.settings.get(["api", "key"]) | |
client = Client(baseurl, api_key) | |
r = client.post_command("plugin/psucontrol", command) | |
try: | |
r.raise_for_status() | |
except requests.exceptions.HTTPError as e: | |
click.echo("HTTP Error, got {}".format(e)) | |
sys.exit(1) | |
return r | |
@click.command("on") | |
def turnPSUOn_command(): | |
"""Turn the PSU On""" | |
_api_command('turnPSUOn') | |
return [turnPSUOn_command] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment