async def sc(ctx, device):
    """(p)sc <device_name> - Get screen capture of device and upload to channel."""
    name = str(device)
    if name == 'all':
        for k, v in devices.items():
            MyOut = subprocess.Popen(
                ['idevicescreenshot', '-u', v, k + '.png'],
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT)
            stdout = MyOut.communicate()
            await bot.send_file(discord.Object(id=bot_channel), k + '.png')
            await bot.send_message(discord.Object(id=bot_channel), k)
    else:
        try:
            MyOut = subprocess.Popen([
                'idevicescreenshot', '-u',
                devices.get(name), device + '.png'
            ],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
            stdout = MyOut.communicate()
            await bot.send_file(discord.Object(id=bot_channel), name + '.png')
        except:
            await bot.send_message(discord.Object(id=bot_channel),
                                   "No device named " + name + " found.")
Beispiel #2
0
def action(target, command):
    """Swith lamp/switch on/off
    target: string
       Name of the lamp/switch to act on: must be either 'all' or a name defined the 'devices' dict

    action: string
       Either 'on' or 'off'
    """
    try:
        if (target == 'all'):
            for name, ip in devices.items():
                Core().sendCommand(ip, command)
        else:
            Core().sendCommand(devices[target], command)
    except Exception as e:
        QMessageBox.critical(None, 'Error', str(e))
Beispiel #3
0
#!/usr/bin/env python3
#
#Turn TP-Link Kasaa lights and plugs on and off
#Clem Lorteau - 2019-05-21

import argparse
import sys
from tplink import Core
from config import devices

ap = argparse.ArgumentParser(description='Turn lights on/off')
ap.add_argument('target',
                metavar='target',
                type=str,
                help='the name of the light to switch on/off, or \'all\'')
ap.add_argument('command', metavar='on/off', type=str, help='on or off')
args = ap.parse_args()

if (args.target == 'all'):
    for name, ip in devices.items():
        Core().sendCommand(ip, args.command)
else:
    Core().sendCommand(devices[args.target], args.command)

if (args.command != 'on' and args.command != 'off'):
    print('Invalid command')
    sys.exit(-1)