Skip to main content

Asynchronous Python API for mFi mPower devices

Project description

Asynchronous Python API for mFi mPower devices

Reference

The "REST" API for mFi mPower devices are briefly explained here.

Usage example

import asyncio

import aiohttp

from mfi_mpower import MPowerDevice

async def main():

    data = {
        "host": "name_or_ip",
        "username": "ubnt",
        "password": "ubnt",
        "use_ssl": True,
        "verify_ssl": False,
    }

    async with aiohttp.ClientSession() as session:
        async with MPowerDevice(**data, session=session) as device:

            # Print device info
            print(device)

            # Print all sensors and their data
            sensors = await device.create_sensors()
            for sensor in sensors:
                print(sensor)

            # Print all switches and their state
            switches = await device.create_switches()
            for switch in switches:
                print(switch)

            # Turn port 1 off and toggle it afterwards back on
            switch1 = await device.create_switch(1)
            await switch1.set(False)
            await asyncio.sleep(5)
            await switch1.toggle()

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mfi-mpower-1.0.0.tar.gz (9.1 kB view hashes)

Uploaded Source

Built Distribution

mfi_mpower-1.0.0-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page