asyncsleepiq


Nameasyncsleepiq JSON
Version 1.5.2 PyPI version JSON
download
home_pagehttp://github.com/kbickar/asyncsleepiq
SummaryASync SleepIQ API
upload_time2024-01-19 17:57:19
maintainer
docs_urlNone
authorKeilin Bickar
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements aiohttp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AsyncSleepIQ

AsyncSleepIQ is an library for accessing the SleepIQ API from Python. [SleepIQ](http://www.sleepnumber.com/sn/en/sleepiq-sleep-tracker) is an addon for [SleepNumber beds](http://www.sleepnumber.com/).

## Installation

```bash
pip install asyncsleepiq
```

## Usage

The library is structured with classes `SleepIQBed`, `SleepIQSleeper`, and `SleepIQFoundation` that get updated with data fetched through the API.

After creating an intsance of `AsyncSleepIQ()` the `login` function should be called, followed by the `init_beds()` function to initialize the data structures and fetch the static data from the API.  Following that, the `fetch_bed_statuses()` function can be called to get updated bed occupancy and sleep number values.

There are two authentication methods available: The older API with key parameter and the newer cookie-based Authentication header.  As of Feb-2022 both work equally well.

The `login()` function should only be called once when the program is started, the `fetch_bed_statuses()` can be called more frequently to get the bed state.  When implementing, do not poll the API by calling `login` each time, instead keep the same `AsyncSleepIQ` object and fetch data as needed.  The library will re-authenticate automtically if the original authentication expires. 

Here is a full example

```python
import asyncio
from asyncsleepiq import AsyncSleepIQ, LOGIN_KEY, LOGIN_COOKIE

email = "user@example.com"
password = "passw0rd"

async def main():        
    api = AsyncSleepIQ(login_method=LOGIN_COOKIE)

    print(f"Logging in as {email}...")
    await api.login(email, password)

    print("Initializing bed data...")
    await api.init_beds()
    await api.fetch_bed_statuses()
    print("Beds:")
    for bed in api.beds.values(): 
        print(bed)

    bed = list(api.beds.values())[0]
    await bed.fetch_pause_mode()
    print (f"Pause mode: {bed.paused}")
    await bed.set_pause_mode(not bed.paused)   
    await bed.fetch_pause_mode()
    print (f"New Pause mode: {bed.paused}") 

    print("Calibrating...")
    await bed.calibrate()
    print("Stopping pump...")
    await bed.stop_pump()

asyncio.get_event_loop().run_until_complete(main())
```

## Future Development

Without documentation for the API, development requires obvserving how other interfaces interact with it.  Given the hardware dependencies are fairly high, any future development requires someone with the appropriate bed to be able to obvserve and test against.

## Special Thanks

Thanks to all the other people that have tried to dig into this API, especially the projects:

- https://github.com/technicalpickles/sleepyq (python)
- https://github.com/erichelgeson/sleepiq (swagger)
- https://github.com/DeeeeLAN/homebridge-sleepiq (javascript)
- https://bitbucket.org/Esity/sleepiq/ (ruby)
- https://javalibs.com/artifact/org.syphr/sleepiq-api (java)

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/kbickar/asyncsleepiq",
    "name": "asyncsleepiq",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Keilin Bickar",
    "author_email": "trumpetgod@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a7/a4/f55d0868469781317422edb77083af05783389cfbe6e5ba5b9a40d6ea368/asyncsleepiq-1.5.2.tar.gz",
    "platform": null,
    "description": "# AsyncSleepIQ\n\nAsyncSleepIQ is an library for accessing the SleepIQ API from Python. [SleepIQ](http://www.sleepnumber.com/sn/en/sleepiq-sleep-tracker) is an addon for [SleepNumber beds](http://www.sleepnumber.com/).\n\n## Installation\n\n```bash\npip install asyncsleepiq\n```\n\n## Usage\n\nThe library is structured with classes `SleepIQBed`, `SleepIQSleeper`, and `SleepIQFoundation` that get updated with data fetched through the API.\n\nAfter creating an intsance of `AsyncSleepIQ()` the `login` function should be called, followed by the `init_beds()` function to initialize the data structures and fetch the static data from the API.  Following that, the `fetch_bed_statuses()` function can be called to get updated bed occupancy and sleep number values.\n\nThere are two authentication methods available: The older API with key parameter and the newer cookie-based Authentication header.  As of Feb-2022 both work equally well.\n\nThe `login()` function should only be called once when the program is started, the `fetch_bed_statuses()` can be called more frequently to get the bed state.  When implementing, do not poll the API by calling `login` each time, instead keep the same `AsyncSleepIQ` object and fetch data as needed.  The library will re-authenticate automtically if the original authentication expires. \n\nHere is a full example\n\n```python\nimport asyncio\nfrom asyncsleepiq import AsyncSleepIQ, LOGIN_KEY, LOGIN_COOKIE\n\nemail = \"user@example.com\"\npassword = \"passw0rd\"\n\nasync def main():        \n    api = AsyncSleepIQ(login_method=LOGIN_COOKIE)\n\n    print(f\"Logging in as {email}...\")\n    await api.login(email, password)\n\n    print(\"Initializing bed data...\")\n    await api.init_beds()\n    await api.fetch_bed_statuses()\n    print(\"Beds:\")\n    for bed in api.beds.values(): \n        print(bed)\n\n    bed = list(api.beds.values())[0]\n    await bed.fetch_pause_mode()\n    print (f\"Pause mode: {bed.paused}\")\n    await bed.set_pause_mode(not bed.paused)   \n    await bed.fetch_pause_mode()\n    print (f\"New Pause mode: {bed.paused}\") \n\n    print(\"Calibrating...\")\n    await bed.calibrate()\n    print(\"Stopping pump...\")\n    await bed.stop_pump()\n\nasyncio.get_event_loop().run_until_complete(main())\n```\n\n## Future Development\n\nWithout documentation for the API, development requires obvserving how other interfaces interact with it.  Given the hardware dependencies are fairly high, any future development requires someone with the appropriate bed to be able to obvserve and test against.\n\n## Special Thanks\n\nThanks to all the other people that have tried to dig into this API, especially the projects:\n\n- https://github.com/technicalpickles/sleepyq (python)\n- https://github.com/erichelgeson/sleepiq (swagger)\n- https://github.com/DeeeeLAN/homebridge-sleepiq (javascript)\n- https://bitbucket.org/Esity/sleepiq/ (ruby)\n- https://javalibs.com/artifact/org.syphr/sleepiq-api (java)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ASync SleepIQ API",
    "version": "1.5.2",
    "project_urls": {
        "Homepage": "http://github.com/kbickar/asyncsleepiq"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ef2ce5e37ad9696f460bc37e24b81de1d6e95416ad5fc899a6945214dc46094",
                "md5": "3a64e74e96f72f9071f1c588b5517a76",
                "sha256": "8a2ca6a844f0b81685e66b32ddaebc9e6e9fd2ca79abd6d4cfc4e57e67c68022"
            },
            "downloads": -1,
            "filename": "asyncsleepiq-1.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3a64e74e96f72f9071f1c588b5517a76",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 23281,
            "upload_time": "2024-01-19T17:57:18",
            "upload_time_iso_8601": "2024-01-19T17:57:18.158321Z",
            "url": "https://files.pythonhosted.org/packages/8e/f2/ce5e37ad9696f460bc37e24b81de1d6e95416ad5fc899a6945214dc46094/asyncsleepiq-1.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7a4f55d0868469781317422edb77083af05783389cfbe6e5ba5b9a40d6ea368",
                "md5": "65bbc726d2c2f9d8770da3723124c3a7",
                "sha256": "4305546180b6e4bc779df43c3ca08eda614c4fda25ea6bf0a23555013c16e242"
            },
            "downloads": -1,
            "filename": "asyncsleepiq-1.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "65bbc726d2c2f9d8770da3723124c3a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15839,
            "upload_time": "2024-01-19T17:57:19",
            "upload_time_iso_8601": "2024-01-19T17:57:19.948159Z",
            "url": "https://files.pythonhosted.org/packages/a7/a4/f55d0868469781317422edb77083af05783389cfbe6e5ba5b9a40d6ea368/asyncsleepiq-1.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-19 17:57:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kbickar",
    "github_project": "asyncsleepiq",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": []
        }
    ],
    "lcname": "asyncsleepiq"
}
        
Elapsed time: 0.42208s