Skip to content

Instantly share code, notes, and snippets.

@kantlivelong
Created July 17, 2017 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kantlivelong/ee16819ae25bf4199511b1f445c4cdf1 to your computer and use it in GitHub Desktop.
Save kantlivelong/ee16819ae25bf4199511b1f445c4cdf1 to your computer and use it in GitHub Desktop.
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