#!/usr/bin/env python

from mfi import MPower
import trollius as asyncio

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('address', help="address", default="localhost", nargs="?")
    parser.add_argument('port', help="port", default=7682, nargs="?")
    parser.add_argument('username', help='username', default='ubnt', nargs="?")
    parser.add_argument('pwd', help='password', default='ubnt', nargs="?")
    parser.add_argument('--on', help='toggle output', action="store_true")
    parser.add_argument('--off', help='toggle output off', action="store_true")
    parser.add_argument('--output', help='output index', type=int, default=1)
    parser.add_argument('--num_outputs', help='number of outlets', type=int, default=8)

    args = parser.parse_args()

    mFI = MPower(args.address, args.port, args.username, args.pwd)

    outputs = []

    def output_changed(signal, sender, value):
        print("output {} changed to {}".format(sender.index, value))

    def outputs_changed(signal, sender, num_outputs):
        print("number of outputs: {}".format(num_outputs))

        for o in mFI.outputs:
            if not o in outputs:
                outputs.append(o)
                o.output_changed.connect(output_changed)

    mFI.num_outputs_changed.connect(outputs_changed)

    def connected():
        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)

    mFI.setOpenHandler(connected)

    @asyncio.coroutine
    def do_command():

        output = None

        while not mFI.output(args.output):
            yield asyncio.From(asyncio.sleep(0.1))
        
        output = mFI.output(args.output)      

        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)

        while not output.ready:
            yield asyncio.From(asyncio.sleep(0.1))

        if args.on:
            while not output.output:
                yield asyncio.From(asyncio.sleep(0.1))

        elif args.off:
            while output.output == True:
                yield asyncio.From(asyncio.sleep(0.1))
                
        else:
            while True:
                yield asyncio.From(asyncio.sleep(0.1))


    asyncio.get_event_loop().run_until_complete(do_command())

486675c416915df3e69483d3f146337285639506
<mask token>

<mask token>
if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('address', help='address', default='localhost',
        nargs='?')
    parser.add_argument('port', help='port', default=7682, nargs='?')
    parser.add_argument('username', help='username', default='ubnt', nargs='?')
    parser.add_argument('pwd', help='password', default='ubnt', nargs='?')
    parser.add_argument('--on', help='toggle output', action='store_true')
    parser.add_argument('--off', help='toggle output off', action='store_true')
    parser.add_argument('--output', help='output index', type=int, default=1)
    parser.add_argument('--num_outputs', help='number of outlets', type=int,
        default=8)
    args = parser.parse_args()
    mFI = MPower(args.address, args.port, args.username, args.pwd)
    outputs = []

    def output_changed(signal, sender, value):
        print('output {} changed to {}'.format(sender.index, value))

    def outputs_changed(signal, sender, num_outputs):
        print('number of outputs: {}'.format(num_outputs))
        for o in mFI.outputs:
            if not o in outputs:
                outputs.append(o)
                o.output_changed.connect(output_changed)
    mFI.num_outputs_changed.connect(outputs_changed)

    def connected():
        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)
    mFI.setOpenHandler(connected)

    @asyncio.coroutine
    def do_command():
        output = None
        while not mFI.output(args.output):
            yield asyncio.From(asyncio.sleep(0.1))
        output = mFI.output(args.output)
        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)
        while not output.ready:
            yield asyncio.From(asyncio.sleep(0.1))
        if args.on:
            while not output.output:
                yield asyncio.From(asyncio.sleep(0.1))
        elif args.off:
            while output.output == True:
                yield asyncio.From(asyncio.sleep(0.1))
        else:
            while True:
                yield asyncio.From(asyncio.sleep(0.1))
    asyncio.get_event_loop().run_until_complete(do_command())

from mfi import MPower
import trollius as asyncio
if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('address', help='address', default='localhost',
        nargs='?')
    parser.add_argument('port', help='port', default=7682, nargs='?')
    parser.add_argument('username', help='username', default='ubnt', nargs='?')
    parser.add_argument('pwd', help='password', default='ubnt', nargs='?')
    parser.add_argument('--on', help='toggle output', action='store_true')
    parser.add_argument('--off', help='toggle output off', action='store_true')
    parser.add_argument('--output', help='output index', type=int, default=1)
    parser.add_argument('--num_outputs', help='number of outlets', type=int,
        default=8)
    args = parser.parse_args()
    mFI = MPower(args.address, args.port, args.username, args.pwd)
    outputs = []

    def output_changed(signal, sender, value):
        print('output {} changed to {}'.format(sender.index, value))

    def outputs_changed(signal, sender, num_outputs):
        print('number of outputs: {}'.format(num_outputs))
        for o in mFI.outputs:
            if not o in outputs:
                outputs.append(o)
                o.output_changed.connect(output_changed)
    mFI.num_outputs_changed.connect(outputs_changed)

    def connected():
        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)
    mFI.setOpenHandler(connected)

    @asyncio.coroutine
    def do_command():
        output = None
        while not mFI.output(args.output):
            yield asyncio.From(asyncio.sleep(0.1))
        output = mFI.output(args.output)
        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)
        while not output.ready:
            yield asyncio.From(asyncio.sleep(0.1))
        if args.on:
            while not output.output:
                yield asyncio.From(asyncio.sleep(0.1))
        elif args.off:
            while output.output == True:
                yield asyncio.From(asyncio.sleep(0.1))
        else:
            while True:
                yield asyncio.From(asyncio.sleep(0.1))
    asyncio.get_event_loop().run_until_complete(do_command())

#!/usr/bin/env python

from mfi import MPower
import trollius as asyncio

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('address', help="address", default="localhost", nargs="?")
    parser.add_argument('port', help="port", default=7682, nargs="?")
    parser.add_argument('username', help='username', default='ubnt', nargs="?")
    parser.add_argument('pwd', help='password', default='ubnt', nargs="?")
    parser.add_argument('--on', help='toggle output', action="store_true")
    parser.add_argument('--off', help='toggle output off', action="store_true")
    parser.add_argument('--output', help='output index', type=int, default=1)
    parser.add_argument('--num_outputs', help='number of outlets', type=int, default=8)

    args = parser.parse_args()

    mFI = MPower(args.address, args.port, args.username, args.pwd)

    outputs = []

    def output_changed(signal, sender, value):
        print("output {} changed to {}".format(sender.index, value))

    def outputs_changed(signal, sender, num_outputs):
        print("number of outputs: {}".format(num_outputs))

        for o in mFI.outputs:
            if not o in outputs:
                outputs.append(o)
                o.output_changed.connect(output_changed)

    mFI.num_outputs_changed.connect(outputs_changed)

    def connected():
        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)

    mFI.setOpenHandler(connected)

    @asyncio.coroutine
    def do_command():

        output = None

        while not mFI.output(args.output):
            yield asyncio.From(asyncio.sleep(0.1))
        
        output = mFI.output(args.output)      

        if args.on:
            mFI.set_output(args.output, True)
        elif args.off:
            mFI.set_output(args.output, False)

        while not output.ready:
            yield asyncio.From(asyncio.sleep(0.1))

        if args.on:
            while not output.output:
                yield asyncio.From(asyncio.sleep(0.1))

        elif args.off:
            while output.output == True:
                yield asyncio.From(asyncio.sleep(0.1))
                
        else:
            while True:
                yield asyncio.From(asyncio.sleep(0.1))


    asyncio.get_event_loop().run_until_complete(do_command())
