Asynchronous Python API for mFi mPower devices
Project description
Asynchronous Python API for mFi mPower devices
Notes
This package provides a direct asynchronous API for Ubiquiti mFi mPower devices based on AsyncSSH. The mFi product line which are is sadly EOL since 2015 and the latest available mFi firmware is version 2.1.11, which can be found here.
Please note that even with the latest available mFi firmware, Ubiquiti mFi mPower Devices use OpenSSL 1.0.0g (18 Jan 2012) and Dropbear SSH 0.51 (27 Mar 2008).
To extract information and control the devices via SSH, only the ssh-rsa host key algorithm in combination with the diffie-hellman-group1-sha1 key exchange is supported. The latter is available as legacy option. There is also a known bug in older Dropbear versions which truncates the list of offered key algorithms. The mFi mPower package therefore limits the offered key algorithms to ssh-rsa and the encryption algorithm to aes128-cbc. Known host checks will be disabled as this would require user interaction.
Basic example
import asyncio
from mfi_mpower.device import MPowerDevice
async def main():
data = {
"host": "name_or_ip",
"username": "ubnt",
"password": "ubnt",
}
async with MPowerDevice(**data) as device:
# Test LED control
await device.set_led(MPowerLED.YELLOW)
await asyncio.sleep(5)
await device.set_led(MPowerLED.LOCKED_OFF)
# Create switch for port 1
switch = await device.create_switch(1)
# Test lock control
await switch.lock()
await asyncio.sleep(5)
await switch.unlock()
# Test output control
await switch.turn_off()
await asyncio.sleep(5)
await switch.toggle()
asyncio.run(main())
Better example
import asyncio
from mfi_mpower.device import MPowerDevice
async def query(host: str) -> None:
"""Async query"""
data = {
"host": host,
"username": "ubnt",
"password": "ubnt",
}
async with MPowerDevice(**data) as device:
# Print device info
print(device)
# Print all switches and their state
switches = await device.create_switches()
for switch in switches:
print(switch)
# Print all sensors and their data
sensors = await device.create_sensors()
for sensor in sensors:
print(sensor)
async def main() -> None:
"""Async main"""
hosts = [
"host1", "host2", "host3",
"host4", "host5", "host6",
]
await asyncio.gather(*[query(host) for host in hosts])
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mfi_mpower-3.2.2.tar.gz.
File metadata
- Download URL: mfi_mpower-3.2.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5f6b5e7d4a518f402e78f50e446871b4602100963f5139973222842ac2a85c6
|
|
| MD5 |
7704eab12c34c788520a9125b2fbed0f
|
|
| BLAKE2b-256 |
734ccf1318446f5d04a3481bb0ccfc868924d8ca206545c65411196a4743025d
|
File details
Details for the file mfi_mpower-3.2.2-py3-none-any.whl.
File metadata
- Download URL: mfi_mpower-3.2.2-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf658acbf5ed12c51cd5ba03cf4f4b68b073069303caac327d95795b770c5dc3
|
|
| MD5 |
cfacd23e28518e02a2ab6bd7db70f7d1
|
|
| BLAKE2b-256 |
8bb031743ecefb7288c7951e276d26f862fe53f94ef9d6539b007362cff242e7
|