Created
November 13, 2022 10:33
-
-
Save kristopolous/a540dbd0f656ac571d561ce77b5acd85 to your computer and use it in GitHub Desktop.
A simple Emporia command line interface
This file contains hidden or 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
#!/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("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example output for 4 devices
