Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pc.py « devices - github.com/ClusterM/google-assistant-smart-home.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e21278930cb31a6fd3ef94104b9733ec8a05b662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import subprocess

def pc_query(custom_data):
    p = subprocess.run(["ping", "-c", "1", "192.168.0.2"], stdout=subprocess.PIPE)
    state = p.returncode == 0
    return {"on": state, "online": True}

def pc_action(custom_data, command, params):
    if command == "action.devices.commands.OnOff":
        if params['on']:
            subprocess.run(["wakeonlan", "-i", "192.168.0.255", "00:11:22:33:44:55"])
        else:
            subprocess.run(["sh", "-c", "echo shutdown -h | ssh clust@192.168.0.2"])
        return {"status": "SUCCESS", "states": {"on": params['on'], "online": True}}
    else:
        return {"status": "ERROR"}