Skip to content

Instantly share code, notes, and snippets.

@kristopolous
Created November 13, 2022 10:33
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 kristopolous/a540dbd0f656ac571d561ce77b5acd85 to your computer and use it in GitHub Desktop.
Save kristopolous/a540dbd0f656ac571d561ce77b5acd85 to your computer and use it in GitHub Desktop.
A simple Emporia command line interface
#!/usr/bin/python3
import pyemvue as pyem, json, sys
with open('keys.json') as f:
data = json.load(f)
v = pyem.PyEmVue()
v.login(id_token=data['id_token'],
access_token=data['access_token'],
refresh_token=data['refresh_token'],
token_storage_file='keys.json')
def toggle(which, action):
if action:
state = False if action == 'off' else True
else:
state = not outletList[which].outlet_on
v.update_outlet(outletList[which], state)
if len(sys.argv) > 1:
action = None
outletList = v.get_outlets()
for i in sys.argv[1:]:
if i.isnumeric():
toggle(int(i), action)
else:
action = i
ix = 0
print("")
for x in v.get_devices():
print(" {} {} {}".format(ix, '\u25A3' if x.outlet.outlet_on else '\u25A2', x.device_name))
ix += 1
print("")
@kristopolous
Copy link
Author

example output for 4 devices
smartplug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment