smartrent.py


Namesmartrent.py JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/zacherythomas/smartrent.py
SummaryUnofficial Python API for SmartRent devices
upload_time2023-07-30 20:50:25
maintainer
docs_urlNone
authorZachery Thomas
requires_python>=3.6.1,<4.0.0
licenseMIT
keywords
VCS
bugtrack_url
requirements websockets aiohttp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SmartRent API

[![PyPI version][pypi-version-badge]](https://pypi.org/project/smartrent-py/)
[![Supported Python versions][supported-versions-badge]](https://pypi.org/project/smartrent-py/)
[![PyPI downloads monthly][m-downloads-badge]](https://pypistats.org/packages/smartrent-py)
[![GitHub License][license-badge]](LICENSE.txt)
[![Documentation Status][docs-badge]](https://smartrentpy.readthedocs.io/en/latest/?badge=latest)
[![Code style: black][black-badge]](https://github.com/psf/black)

`smartrent.py` is a simple library for SmartRent devices

Uses websockets for communication and supports async functions

Feel free to ⭐️ this repo to get notified about the latest features!

[📚 Read the docs! 📚](https://smartrentpy.readthedocs.io)
## Supported Devices
This client supports:
* 🔐 Door Locks
* 🌡 Thermostats
* 💧 Leak Sensors
* 💡 Binary Switches
* 🎚 Multilevel (Dimmer) Switches


## Usage

### Installation

```bash
pip install smartrent.py
```

### Getting an API Object
In order to get an api object to interact with, you must login with the `async_login` function. This starts and handles a web session with SmartRent.

```python
import asyncio

from smartrent import async_login

async def main():
    api = await async_login('<EMAIL>', '<PASSWORD>')

asyncio.run(main())
```

### Getting Devices
You can get lists of your devices from the api with the `get_locks`, `get_thermostats`, `get_switches` and `get_leak_sensors` functions. You can then interact with the devices with their getter and setter functions.

```python
import asyncio

from smartrent import async_login

async def main():
    api = await async_login('<EMAIL>', '<PASSWORD>')

    lock = api.get_locks()[0]
    locked = lock.get_locked()

    if not locked:
        await lock.async_set_locked(True)

asyncio.run(main())
```

### Automatic Updating
If you need to get live updates to your device object from SmartRent, you can do that by calling `start_updater`. You can stop getting updates by calling `stop_updater`.

You can also set a callback function via `set_update_callback` that will be called when an update is triggered.

For example, if you want to set your thermostat to `Dad Mode` you can trigger an event every time the `cooling_setpoint` is changed and just change it back to your own desired value.
```python
import asyncio

from smartrent import async_login

async def main():
    api = await async_login('<EMAIL>', '<PASSWORD>')

    thermo = api.get_thermostats()[0]
    thermo.start_updater()

    CONSTANT_COOL = 80

    async def on_evt():
        if CONSTANT_COOL != thermo.get_cooling_setpoint():
            await thermo.async_set_cooling_setpoint(CONSTANT_COOL)

    thermo.set_update_callback(on_evt)

    while True:
        await asyncio.sleep(60)

asyncio.run(main())
```

## Development
### Setting up dev enviornment

```
pip install -r requirements_test.txt
```

### Running the code formatter
[Black](https://github.com/psf/black) is used for quick and easy code formatting

```
black smartrent
```

## Special thanks
Much inspiration was taken from these projects:

[AMcPherran/SmartRent-MQTT-Bridge](https://github.com/AMcPherran/SmartRent-MQTT-Bridge)

[natanweinberger/smartrent-python](https://github.com/natanweinberger/smartrent-python)

[Burry/homebridge-smartrent](https://github.com/Burry/homebridge-smartrent)
## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).

# Adding Unsupported Devices!

This library is built in a way that it is easy to add any smartrent device. If you find that one of the devices you own is not supported, we should be able to add it to this libray.

Two things are needed to get the info to add a new device:
* We have to get some device info from smartrents api
* We need to get info about how the device reacts when it enters different states

Both of these can be done in one script.

You have to run `python3 ./tools/device_helper.py`

It will print out some output and a table with `Device ID`s and `Device Names`. The device you wish to add should be listed in that table.
```
Device ID:      Device Name:
==============================
2211234         Thermostat
2212345         Front Door - Lock
2212347         Washer - Leak Sensor
```

The program will then ask for a `Device ID` that you wish to track. Enter in the `Device ID` you want to gather information from.

```
Put in the Device ID you wish to track: 2211234
Joining topic for 2211234...
{'response': {}, 'status': 'ok'}
```

You can now change the state of your device either physically in your apartment/house or through the SmartRent app. For example, this is a thermostat's cooling point being turned up, and then the thermostat sending an update about the current humidity
```
ThermostatSetpoint  cooling_setpoint    77
MultiLvlSensor      current_humidity    53
```

Once you get a good amount of info, open up an issue describing that you wish to add support for a new device and paste all of the output from `device_helper.py`. Feel free to hide your `Device ID`s if you wish.


[pypi-version-badge]: https://img.shields.io/pypi/v/smartrent-py.svg?logo=pypi&logoColor=FFE873&style=for-the-badge
[supported-versions-badge]: https://img.shields.io/pypi/pyversions/smartrent-py.svg?logo=python&logoColor=FFE873&style=for-the-badge
[downloads-badge]: https://static.pepy.tech/personalized-badge/smartrent-py?period=total&units=international_system&left_color=grey&right_color=orange&left_text=total%20downloads&style=for-the-badge
[m-downloads-badge]: https://img.shields.io/pypi/dm/smartrent-py.svg?style=for-the-badge
[license-badge]: https://img.shields.io/github/license/ZacheryThomas/smartrent.py.svg?style=for-the-badge
[docs-badge]: https://readthedocs.org/projects/smartrentpy/badge/?version=latest&style=for-the-badge
[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zacherythomas/smartrent.py",
    "name": "smartrent.py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.1,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Zachery Thomas",
    "author_email": "zacherythomas12@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/94/f2/d74d07b7e0f651d46efc3782bffdfca8a721dc4c7e6faf57236afe665bd4/smartrent.py-0.4.3.tar.gz",
    "platform": null,
    "description": "# SmartRent API\n\n[![PyPI version][pypi-version-badge]](https://pypi.org/project/smartrent-py/)\n[![Supported Python versions][supported-versions-badge]](https://pypi.org/project/smartrent-py/)\n[![PyPI downloads monthly][m-downloads-badge]](https://pypistats.org/packages/smartrent-py)\n[![GitHub License][license-badge]](LICENSE.txt)\n[![Documentation Status][docs-badge]](https://smartrentpy.readthedocs.io/en/latest/?badge=latest)\n[![Code style: black][black-badge]](https://github.com/psf/black)\n\n`smartrent.py` is a simple library for SmartRent devices\n\nUses websockets for communication and supports async functions\n\nFeel free to \u2b50\ufe0f this repo to get notified about the latest features!\n\n[\ud83d\udcda Read the docs! \ud83d\udcda](https://smartrentpy.readthedocs.io)\n## Supported Devices\nThis client supports:\n* \ud83d\udd10 Door Locks\n* \ud83c\udf21 Thermostats\n* \ud83d\udca7 Leak Sensors\n* \ud83d\udca1 Binary Switches\n* \ud83c\udf9a Multilevel (Dimmer) Switches\n\n\n## Usage\n\n### Installation\n\n```bash\npip install smartrent.py\n```\n\n### Getting an API Object\nIn order to get an api object to interact with, you must login with the `async_login` function. This starts and handles a web session with SmartRent.\n\n```python\nimport asyncio\n\nfrom smartrent import async_login\n\nasync def main():\n    api = await async_login('<EMAIL>', '<PASSWORD>')\n\nasyncio.run(main())\n```\n\n### Getting Devices\nYou can get lists of your devices from the api with the `get_locks`, `get_thermostats`, `get_switches` and `get_leak_sensors` functions. You can then interact with the devices with their getter and setter functions.\n\n```python\nimport asyncio\n\nfrom smartrent import async_login\n\nasync def main():\n    api = await async_login('<EMAIL>', '<PASSWORD>')\n\n    lock = api.get_locks()[0]\n    locked = lock.get_locked()\n\n    if not locked:\n        await lock.async_set_locked(True)\n\nasyncio.run(main())\n```\n\n### Automatic Updating\nIf you need to get live updates to your device object from SmartRent, you can do that by calling `start_updater`. You can stop getting updates by calling `stop_updater`.\n\nYou can also set a callback function via `set_update_callback` that will be called when an update is triggered.\n\nFor example, if you want to set your thermostat to `Dad Mode` you can trigger an event every time the `cooling_setpoint` is changed and just change it back to your own desired value.\n```python\nimport asyncio\n\nfrom smartrent import async_login\n\nasync def main():\n    api = await async_login('<EMAIL>', '<PASSWORD>')\n\n    thermo = api.get_thermostats()[0]\n    thermo.start_updater()\n\n    CONSTANT_COOL = 80\n\n    async def on_evt():\n        if CONSTANT_COOL != thermo.get_cooling_setpoint():\n            await thermo.async_set_cooling_setpoint(CONSTANT_COOL)\n\n    thermo.set_update_callback(on_evt)\n\n    while True:\n        await asyncio.sleep(60)\n\nasyncio.run(main())\n```\n\n## Development\n### Setting up dev enviornment\n\n```\npip install -r requirements_test.txt\n```\n\n### Running the code formatter\n[Black](https://github.com/psf/black) is used for quick and easy code formatting\n\n```\nblack smartrent\n```\n\n## Special thanks\nMuch inspiration was taken from these projects:\n\n[AMcPherran/SmartRent-MQTT-Bridge](https://github.com/AMcPherran/SmartRent-MQTT-Bridge)\n\n[natanweinberger/smartrent-python](https://github.com/natanweinberger/smartrent-python)\n\n[Burry/homebridge-smartrent](https://github.com/Burry/homebridge-smartrent)\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).\n\n# Adding Unsupported Devices!\n\nThis library is built in a way that it is easy to add any smartrent device. If you find that one of the devices you own is not supported, we should be able to add it to this libray.\n\nTwo things are needed to get the info to add a new device:\n* We have to get some device info from smartrents api\n* We need to get info about how the device reacts when it enters different states\n\nBoth of these can be done in one script.\n\nYou have to run `python3 ./tools/device_helper.py`\n\nIt will print out some output and a table with `Device ID`s and `Device Names`. The device you wish to add should be listed in that table.\n```\nDevice ID:      Device Name:\n==============================\n2211234         Thermostat\n2212345         Front Door - Lock\n2212347         Washer - Leak Sensor\n```\n\nThe program will then ask for a `Device ID` that you wish to track. Enter in the `Device ID` you want to gather information from.\n\n```\nPut in the Device ID you wish to track: 2211234\nJoining topic for 2211234...\n{'response': {}, 'status': 'ok'}\n```\n\nYou can now change the state of your device either physically in your apartment/house or through the SmartRent app. For example, this is a thermostat's cooling point being turned up, and then the thermostat sending an update about the current humidity\n```\nThermostatSetpoint  cooling_setpoint    77\nMultiLvlSensor      current_humidity    53\n```\n\nOnce you get a good amount of info, open up an issue describing that you wish to add support for a new device and paste all of the output from `device_helper.py`. Feel free to hide your `Device ID`s if you wish.\n\n\n[pypi-version-badge]: https://img.shields.io/pypi/v/smartrent-py.svg?logo=pypi&logoColor=FFE873&style=for-the-badge\n[supported-versions-badge]: https://img.shields.io/pypi/pyversions/smartrent-py.svg?logo=python&logoColor=FFE873&style=for-the-badge\n[downloads-badge]: https://static.pepy.tech/personalized-badge/smartrent-py?period=total&units=international_system&left_color=grey&right_color=orange&left_text=total%20downloads&style=for-the-badge\n[m-downloads-badge]: https://img.shields.io/pypi/dm/smartrent-py.svg?style=for-the-badge\n[license-badge]: https://img.shields.io/github/license/ZacheryThomas/smartrent.py.svg?style=for-the-badge\n[docs-badge]: https://readthedocs.org/projects/smartrentpy/badge/?version=latest&style=for-the-badge\n[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Unofficial Python API for SmartRent devices",
    "version": "0.4.3",
    "project_urls": {
        "Documentation": "https://smartrentpy.readthedocs.io",
        "Homepage": "https://github.com/zacherythomas/smartrent.py",
        "Repository": "https://github.com/zacherythomas/smartrent.py"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "877fe5985babeb76476e886fde9d844de63ea6328ba048e3d2b340efbac1dbd2",
                "md5": "01e98fe39f4fa4df2312027e4bcfec01",
                "sha256": "58eac6224acff70ce219624b51eaaface1abac711eeed557c6bac736b82d4f83"
            },
            "downloads": -1,
            "filename": "smartrent.py-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01e98fe39f4fa4df2312027e4bcfec01",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.1,<4.0.0",
            "size": 15751,
            "upload_time": "2023-07-30T20:50:23",
            "upload_time_iso_8601": "2023-07-30T20:50:23.400284Z",
            "url": "https://files.pythonhosted.org/packages/87/7f/e5985babeb76476e886fde9d844de63ea6328ba048e3d2b340efbac1dbd2/smartrent.py-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "94f2d74d07b7e0f651d46efc3782bffdfca8a721dc4c7e6faf57236afe665bd4",
                "md5": "e236b285c79a938184b9a64a45360d39",
                "sha256": "c93ed809af2af7e0bca0a20abdadc72100a56bc5b68449821298c8b070f944df"
            },
            "downloads": -1,
            "filename": "smartrent.py-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e236b285c79a938184b9a64a45360d39",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.1,<4.0.0",
            "size": 14966,
            "upload_time": "2023-07-30T20:50:25",
            "upload_time_iso_8601": "2023-07-30T20:50:25.048978Z",
            "url": "https://files.pythonhosted.org/packages/94/f2/d74d07b7e0f651d46efc3782bffdfca8a721dc4c7e6faf57236afe665bd4/smartrent.py-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-30 20:50:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zacherythomas",
    "github_project": "smartrent.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "websockets",
            "specs": [
                [
                    ">=",
                    "11.0.1"
                ]
            ]
        },
        {
            "name": "aiohttp",
            "specs": [
                [
                    ">=",
                    "3.8.4"
                ]
            ]
        }
    ],
    "lcname": "smartrent.py"
}
        
Elapsed time: 0.10106s