mfi-mpower


Namemfi-mpower JSON
Version 1.2.3 PyPI version JSON
download
home_page
SummaryAsynchronous Python API for mFi mPower devices
upload_time2023-01-08 14:42:23
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMIT 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.
keywords ubiquiti mfi mpower
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Asynchronous Python API for mFi mPower devices

## Notes

This package provides a _direct_ asynchronous API for Ubiquiti mFi mPower devices based on [AIOHTTP](https://docs.aiohttp.org/en/stable/) and [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 are quite unhurried and use OpenSSL 1.0.0g (18 Jan 2012) as well as Dropbear SSH 0.51 (27 Mar 2008).**

SLL connections are thus limited to TLSv1.0. The mFi mPower package pins the cipher use explicitly to `AES128-SHA` in order to get the fastest 2048 bit strength and avoid DES and RC4. This results in the highest possible rating according to the [nmap enum-cipher-script](https://nmap.org/nsedoc/scripts/ssl-enum-ciphers.html). The default device certificate is self-signed and too weak (512 bit) for todays standards. SSL certificate verification is therefore disabled by default. The certificate can however be replaced with your own.

As mFi mPower devices are usually communicating only in a local network and not via the internet, some old SSL still seems to be much better than no encryption at all.

**Be aware that SSL is only supported until TLSv1.0 is eventually removed from Python - at least unless someone finds a way to replace the OpenSSL binary with a more recent version until then.**

A brief description of the old "REST" API can be found in the [UI Community](https://community.ui.com/questions/mPower-mFi-Switch-and-mFi-In-Wall-Outlet-HTTP-API/824c1c63-b7e6-44ed-b19a-f1d68cd07269) but some additional "reverse engineering" was necessary to extract device info. There still seems no way to extract board or model information without SSH. Any hints are very much appreciated!

To extract board information 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
import aiohttp

from mfi_mpower.device import MPowerDevice

async def main():

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

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

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

## Better example

```python
import asyncio
import aiohttp

from mfi_mpower.device import MPowerDevice

async def query(host: str) -> None:
    """Async query"""

    data = {
        "username": "ubnt",
        "password": "ubnt",
        "use_ssl": True,
        "verify_ssl": False,
        "board_info": None,
    }

    data["host"] = host

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

            # Print device info
            print(device)

            # Print device board data
            print(device.board)

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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mfi-mpower",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "ubiquiti,mfi,mpower",
    "author": "",
    "author_email": "\"P. Beckstein\" <p.b-dev+mfi-mpower@mailbox.org>",
    "download_url": "https://files.pythonhosted.org/packages/dd/2a/52308710f24c4f314d8f445b44b16f427d9a7f44e7b2548096f8b7bd8305/mfi-mpower-1.2.3.tar.gz",
    "platform": "any",
    "description": "# Asynchronous Python API for mFi mPower devices\r\n\r\n## Notes\r\n\r\nThis package provides a _direct_ asynchronous API for Ubiquiti mFi mPower devices based on [AIOHTTP](https://docs.aiohttp.org/en/stable/) and [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).\r\n\r\n**Please note that even with the latest available mFi firmware, Ubiquiti mFi mPower Devices are quite unhurried and use OpenSSL 1.0.0g (18 Jan 2012) as well as Dropbear SSH 0.51 (27 Mar 2008).**\r\n\r\nSLL connections are thus limited to TLSv1.0. The mFi mPower package pins the cipher use explicitly to `AES128-SHA` in order to get the fastest 2048 bit strength and avoid DES and RC4. This results in the highest possible rating according to the [nmap enum-cipher-script](https://nmap.org/nsedoc/scripts/ssl-enum-ciphers.html). The default device certificate is self-signed and too weak (512 bit) for todays standards. SSL certificate verification is therefore disabled by default. The certificate can however be replaced with your own.\r\n\r\nAs mFi mPower devices are usually communicating only in a local network and not via the internet, some old SSL still seems to be much better than no encryption at all.\r\n\r\n**Be aware that SSL is only supported until TLSv1.0 is eventually removed from Python - at least unless someone finds a way to replace the OpenSSL binary with a more recent version until then.**\r\n\r\nA brief description of the old \"REST\" API can be found in the [UI Community](https://community.ui.com/questions/mPower-mFi-Switch-and-mFi-In-Wall-Outlet-HTTP-API/824c1c63-b7e6-44ed-b19a-f1d68cd07269) but some additional \"reverse engineering\" was necessary to extract device info. There still seems no way to extract board or model information without SSH. Any hints are very much appreciated!\r\n\r\nTo extract board information 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.\r\n\r\n## Basic example\r\n\r\n```python\r\nimport asyncio\r\nimport aiohttp\r\n\r\nfrom mfi_mpower.device import MPowerDevice\r\n\r\nasync def main():\r\n\r\n    data = {\r\n        \"host\": \"name_or_ip\",\r\n        \"username\": \"ubnt\",\r\n        \"password\": \"ubnt\",\r\n        \"use_ssl\": True,\r\n        \"verify_ssl\": False,\r\n        \"board_info\": None,\r\n    }\r\n\r\n    async with aiohttp.ClientSession() as session:\r\n        async with MPowerDevice(**data, session=session) as device:\r\n\r\n            # Turn port 1 off and toggle it afterwards back on\r\n            switch1 = await device.create_switch(1)\r\n            await switch1.set(False)\r\n            await asyncio.sleep(5)\r\n            await switch1.toggle()\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n## Better example\r\n\r\n```python\r\nimport asyncio\r\nimport aiohttp\r\n\r\nfrom mfi_mpower.device import MPowerDevice\r\n\r\nasync def query(host: str) -> None:\r\n    \"\"\"Async query\"\"\"\r\n\r\n    data = {\r\n        \"username\": \"ubnt\",\r\n        \"password\": \"ubnt\",\r\n        \"use_ssl\": True,\r\n        \"verify_ssl\": False,\r\n        \"board_info\": None,\r\n    }\r\n\r\n    data[\"host\"] = host\r\n\r\n    async with aiohttp.ClientSession() as session:\r\n        async with MPowerDevice(**data, session=session) as device:\r\n\r\n            # Print device info\r\n            print(device)\r\n\r\n            # Print device board data\r\n            print(device.board)\r\n\r\n            # Print all switches and their state\r\n            switches = await device.create_switches()\r\n            for switch in switches:\r\n                print(switch)\r\n\r\n            # Print all sensors and their data\r\n            sensors = await device.create_sensors()\r\n            for sensor in sensors:\r\n                print(sensor)\r\n\r\n\r\nasync def main() -> None:\r\n    \"\"\"Async main\"\"\"\r\n\r\n    hosts = [\r\n        \"host1\", \"host2\", \"host3\",\r\n        \"host4\", \"host5\", \"host6\",\r\n    ]\r\n\r\n    await asyncio.gather(*[query(host) for host in hosts])\r\n\r\nasyncio.run(main())\r\n```\r\n",
    "bugtrack_url": null,
    "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. ",
    "summary": "Asynchronous Python API for mFi mPower devices",
    "version": "1.2.3",
    "split_keywords": [
        "ubiquiti",
        "mfi",
        "mpower"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1bc3fe6195a00937799e2a8c631758b12aa3375b9e788abffd06f427dfefd054",
                "md5": "37a1d78ae68aadb87b500957da06eefd",
                "sha256": "d2ae8f47228dcc18acdecbe77f962461379f341ff6921625a0dae65535068ab4"
            },
            "downloads": -1,
            "filename": "mfi_mpower-1.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "37a1d78ae68aadb87b500957da06eefd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 11714,
            "upload_time": "2023-01-08T14:42:22",
            "upload_time_iso_8601": "2023-01-08T14:42:22.225267Z",
            "url": "https://files.pythonhosted.org/packages/1b/c3/fe6195a00937799e2a8c631758b12aa3375b9e788abffd06f427dfefd054/mfi_mpower-1.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd2a52308710f24c4f314d8f445b44b16f427d9a7f44e7b2548096f8b7bd8305",
                "md5": "2e182183dfe10fcbc9c294c1a3210d65",
                "sha256": "7880840f4ea71fc4ab6990a7f3c7857548c900d7d547ec774c0c0215c9c476ed"
            },
            "downloads": -1,
            "filename": "mfi-mpower-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2e182183dfe10fcbc9c294c1a3210d65",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 12429,
            "upload_time": "2023-01-08T14:42:23",
            "upload_time_iso_8601": "2023-01-08T14:42:23.932275Z",
            "url": "https://files.pythonhosted.org/packages/dd/2a/52308710f24c4f314d8f445b44b16f427d9a7f44e7b2548096f8b7bd8305/mfi-mpower-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-08 14:42:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "mfi-mpower"
}
        
Elapsed time: 0.03563s