Metadata-Version: 2.4
Name: mfi-mpower
Version: 2.3.2
Summary: Asynchronous Python API for mFi mPower devices
Author-email: pasbec <p.b-dev+mfi-mpower@mailbox.org>
License: MIT License
        
        Copyright (c) 2023 pasbec
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/pasbec/mfi
Keywords: ubiquiti,mfi,mpower
Platform: any
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: asyncssh
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: bump-my-version; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: pip-tools; extra == "dev"
Requires-Dist: pylint; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: wheel; extra == "dev"
Dynamic: license-file

# Asynchronous Python API for mFi mPower devices

## Notes

This package provides a _direct_ asynchronous API for Ubiquiti mFi mPower devices based on [AsyncSSH](https://asyncssh.readthedocs.io/en/latest/). 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](https://www.ui.com/download/mfi/mpower).

**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](http://www.openssh.com/legacy.html). There is also a [known bug](https://github.com/ronf/asyncssh/issues/263) 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](https://github.com/ronf/asyncssh/issues/132) as this would require user interaction.

## Basic example

```python
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:

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

asyncio.run(main())
```

## Better example

```python
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())
```
