geniushub-client


Namegeniushub-client JSON
Version 0.7.1 PyPI version JSON
download
home_pagehttps://github.com/manzanotti/geniushub-client
SummaryAn aiohttp-based client for Genius Hub systems
upload_time2023-10-30 14:30:18
maintainer
docs_urlNone
authorPaul Manzotti
requires_python>=3.9
licenseMIT
keywords genius geniushub heatgenius
VCS
bugtrack_url
requirements aiohttp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![CircleCI](https://circleci.com/gh/manzanotti/geniushub-client.svg?style=svg)](https://circleci.com/gh/manzanotti/geniushub-client) [![Join the chat at https://gitter.im/geniushub-client/community](https://badges.gitter.im/geniushub-client/community.svg)](https://gitter.im/geniushub-client/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/geniushub-client)

# geniushub-client
This is a Python library to provide access to a **Genius Hub** by abstracting its [RESTful API](https://my.geniushub.co.uk/docs). It uses **aiohttp** and is therefore async-friendly.

This library can use either the **_offical_ v1 API** with a [hub token](https://my.geniushub.co.uk/tokens), or the **_latest_ v3 API** (using your own [username and password](https://www.geniushub.co.uk/app)). In either case, the library will return v1-compatible results wherever possible (this is not a trivial task).

If you use the v3 API, you can interrogate the hub directly, rather than via Heat Genius' own servers. Note that the v3 API is undocumented, and so this functionality may break at any time. In fact, the v3 to v1 conversion if best efforts and may even be broken as is for some edge cases - it was tested with HW, on/off (i.e. smart plugs), and radiators only.

It is a WIP, and may be missing some functionality. In addition, there are some other limitations (see below).

It is based upon work by [@GeoffAtHome](https://github.com/manzanotti/geniushub-client/commits?author=GeoffAtHome) and [@zxdavb]](https://github.com/manzanotti/geniushub-client/commits?author=zxdavb) - thanks!

## Current limitations
Current limitations & to-dos include:
 - **ghclient.py** is not complete
 - schedules are read-only
 - when using the v3 API, zones sometimes have the wrong value for `occupied`

 The library will return v1 API responses wherever possible, however:
  1. the only code available to reverse-engineer is from the web app, but
  2. the Web app does not correlate completely with the v1 API (e.g. issue messages, occupied state)

Thus, always check your output against the corresponding v1 API response rather than the web app.

## Installation
Either clone this repository and run `python setup.py install`, or install from pip using `pip install geniushub-client`.

## Using the Library
See `ghclient.py` for example code. You can also use `ghclient.py` for ad-hoc queries:
```bash
python ghclient.py -?
```
There are two distinct options for accessing a Genius Hub:

Option 1: **hub token** only:
  - requires a hub token obtained from https://my.geniushub.co.uk/tokens
  - uses the v1 API - which is well-documented
  - interrogates Heat Genius' own servers (so is slower)

Option 2: hub **hostname/address** with **user credentials**:
  - requires your `username` & `password`, as used with https://www.geniushub.co.uk/app
  - uses the v3 API - results are WIP and may not be what you expect
  - interrogates the hub directly (so is faster), via port :1223

```bash
HUB_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInZlc..."
HUB_ADDRESS="my-geniushub.dyndns.com"
USERNAME="my-username"
PASSWORD="my-password"

python ghclient.py ${HUB_TOKEN} issues

python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} zones -v
```

You can compare any output to the 'official' API (v1 response):
```bash
curl -H "authorization: Bearer ${HUB_TOKEN}" -X GET https://my.geniushub.co.uk/v1/zones/summary
python ghclient.py ${HUB_TOKEN} zones

curl -H "authorization: Bearer ${HUB_TOKEN}" -X GET https://my.geniushub.co.uk/v1/devices
python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} devices -v

curl -H "authorization: Bearer ${HUB_TOKEN}" -X GET https://my.geniushub.co.uk/v1/issues
python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} issues
```

You can obtain the 'raw' v3 API responses (i.e. the JSON is not converted to the v1 schema):
```bash
python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} zones -vvv
python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} devices -vvv
```

To obtain the 'official' v3 API responses takes a little work.  First, use python to obtain a `HASH`:
```python
>>> from hashlib import sha256
>>> hash = sha256()
>>> hash.update(("my_username" + "my_password").encode('utf-8'))
>>> print(hash.hexdigest())
001b24f45b...
```
Then you can use **curl**:
```bash
curl --user ${USERNAME}:${HASH} -X GET http://${HUB_ADDRESS}:1223/v3/zones
```

## Advanced Features
 When used as a library, there is the option to utilize the referencing module's own `aiohttp.ClientSession()` (recommended).

 Here is an example, but see **ghclient.py** for a more complete example:
 ```python
import asyncio
import aiohttp
from geniushubclient import GeniusHub

my_session = aiohttp.ClientSession()

...

if not (username or password):
    hub = GeniusHub(hub_id=hub_address, username=username, password=password, session=my_session)
else:
    hub = GeniusHub(hub_id=hub_token, session=my_session)

await hub.update()  # enumerate all zones, devices and issues

hub.verbosity = 0  # same as v1/zones/summary, v1/devices/summary
print(hub.zones)

hub.verbosity = 1  # default, same as v1/zones, v1/devices, v1/issues
print(hub.devices)

print(hub.zone_by_id[3].data["temperature"])
print(hub.device_by_id["2-2"].data)

await my_session.close()
```

### Unit tests

Please see the README.md file in the tests folder for more details on unit tests protocol.

### QA/CI via CircleCI
QA includes comparing JSON from **cURL** with output from this app using **diff**, for example:
```bash
(venv) root@hostname:~/$ curl -X GET https://my.geniushub.co.uk/v1/zones -H "authorization: Bearer ${HUB_TOKEN}" | \
    python -c "import sys, json; print(json.dumps(json.load(sys.stdin, parse_float=lambda x: int(float(x))), indent=4, sort_keys=True))" > a.out

(venv) root@hostname:~/$ python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} zones -v | \
    python -c "import sys, json; print(json.dumps(json.load(sys.stdin, parse_float=lambda x: int(float(x))), indent=4, sort_keys=True))" > b.out

(venv) root@hostname:~/$ diff a.out b.out
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/manzanotti/geniushub-client",
    "name": "geniushub-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "genius,geniushub,heatgenius",
    "author": "Paul Manzotti",
    "author_email": "manzo@gorilla-tactics.com",
    "download_url": "https://files.pythonhosted.org/packages/a4/08/91577ed44a51010db08f4ec59ab8f31d49182bb5d7d2d729194b8c35057f/geniushub-client-0.7.1.tar.gz",
    "platform": null,
    "description": "[![CircleCI](https://circleci.com/gh/manzanotti/geniushub-client.svg?style=svg)](https://circleci.com/gh/manzanotti/geniushub-client) [![Join the chat at https://gitter.im/geniushub-client/community](https://badges.gitter.im/geniushub-client/community.svg)](https://gitter.im/geniushub-client/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/geniushub-client)\n\n# geniushub-client\nThis is a Python library to provide access to a **Genius Hub** by abstracting its [RESTful API](https://my.geniushub.co.uk/docs). It uses **aiohttp** and is therefore async-friendly.\n\nThis library can use either the **_offical_ v1 API** with a [hub token](https://my.geniushub.co.uk/tokens), or the **_latest_ v3 API** (using your own [username and password](https://www.geniushub.co.uk/app)). In either case, the library will return v1-compatible results wherever possible (this is not a trivial task).\n\nIf you use the v3 API, you can interrogate the hub directly, rather than via Heat Genius' own servers. Note that the v3 API is undocumented, and so this functionality may break at any time. In fact, the v3 to v1 conversion if best efforts and may even be broken as is for some edge cases - it was tested with HW, on/off (i.e. smart plugs), and radiators only.\n\nIt is a WIP, and may be missing some functionality. In addition, there are some other limitations (see below).\n\nIt is based upon work by [@GeoffAtHome](https://github.com/manzanotti/geniushub-client/commits?author=GeoffAtHome) and [@zxdavb]](https://github.com/manzanotti/geniushub-client/commits?author=zxdavb) - thanks!\n\n## Current limitations\nCurrent limitations & to-dos include:\n - **ghclient.py** is not complete\n - schedules are read-only\n - when using the v3 API, zones sometimes have the wrong value for `occupied`\n\n The library will return v1 API responses wherever possible, however:\n  1. the only code available to reverse-engineer is from the web app, but\n  2. the Web app does not correlate completely with the v1 API (e.g. issue messages, occupied state)\n\nThus, always check your output against the corresponding v1 API response rather than the web app.\n\n## Installation\nEither clone this repository and run `python setup.py install`, or install from pip using `pip install geniushub-client`.\n\n## Using the Library\nSee `ghclient.py` for example code. You can also use `ghclient.py` for ad-hoc queries:\n```bash\npython ghclient.py -?\n```\nThere are two distinct options for accessing a Genius Hub:\n\nOption 1: **hub token** only:\n  - requires a hub token obtained from https://my.geniushub.co.uk/tokens\n  - uses the v1 API - which is well-documented\n  - interrogates Heat Genius' own servers (so is slower)\n\nOption 2: hub **hostname/address** with **user credentials**:\n  - requires your `username` & `password`, as used with https://www.geniushub.co.uk/app\n  - uses the v3 API - results are WIP and may not be what you expect\n  - interrogates the hub directly (so is faster), via port :1223\n\n```bash\nHUB_TOKEN=\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInZlc...\"\nHUB_ADDRESS=\"my-geniushub.dyndns.com\"\nUSERNAME=\"my-username\"\nPASSWORD=\"my-password\"\n\npython ghclient.py ${HUB_TOKEN} issues\n\npython ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} zones -v\n```\n\nYou can compare any output to the 'official' API (v1 response):\n```bash\ncurl -H \"authorization: Bearer ${HUB_TOKEN}\" -X GET https://my.geniushub.co.uk/v1/zones/summary\npython ghclient.py ${HUB_TOKEN} zones\n\ncurl -H \"authorization: Bearer ${HUB_TOKEN}\" -X GET https://my.geniushub.co.uk/v1/devices\npython ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} devices -v\n\ncurl -H \"authorization: Bearer ${HUB_TOKEN}\" -X GET https://my.geniushub.co.uk/v1/issues\npython ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} issues\n```\n\nYou can obtain the 'raw' v3 API responses (i.e. the JSON is not converted to the v1 schema):\n```bash\npython ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} zones -vvv\npython ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} devices -vvv\n```\n\nTo obtain the 'official' v3 API responses takes a little work.  First, use python to obtain a `HASH`:\n```python\n>>> from hashlib import sha256\n>>> hash = sha256()\n>>> hash.update((\"my_username\" + \"my_password\").encode('utf-8'))\n>>> print(hash.hexdigest())\n001b24f45b...\n```\nThen you can use **curl**:\n```bash\ncurl --user ${USERNAME}:${HASH} -X GET http://${HUB_ADDRESS}:1223/v3/zones\n```\n\n## Advanced Features\n When used as a library, there is the option to utilize the referencing module's own `aiohttp.ClientSession()` (recommended).\n\n Here is an example, but see **ghclient.py** for a more complete example:\n ```python\nimport asyncio\nimport aiohttp\nfrom geniushubclient import GeniusHub\n\nmy_session = aiohttp.ClientSession()\n\n...\n\nif not (username or password):\n    hub = GeniusHub(hub_id=hub_address, username=username, password=password, session=my_session)\nelse:\n    hub = GeniusHub(hub_id=hub_token, session=my_session)\n\nawait hub.update()  # enumerate all zones, devices and issues\n\nhub.verbosity = 0  # same as v1/zones/summary, v1/devices/summary\nprint(hub.zones)\n\nhub.verbosity = 1  # default, same as v1/zones, v1/devices, v1/issues\nprint(hub.devices)\n\nprint(hub.zone_by_id[3].data[\"temperature\"])\nprint(hub.device_by_id[\"2-2\"].data)\n\nawait my_session.close()\n```\n\n### Unit tests\n\nPlease see the README.md file in the tests folder for more details on unit tests protocol.\n\n### QA/CI via CircleCI\nQA includes comparing JSON from **cURL** with output from this app using **diff**, for example:\n```bash\n(venv) root@hostname:~/$ curl -X GET https://my.geniushub.co.uk/v1/zones -H \"authorization: Bearer ${HUB_TOKEN}\" | \\\n    python -c \"import sys, json; print(json.dumps(json.load(sys.stdin, parse_float=lambda x: int(float(x))), indent=4, sort_keys=True))\" > a.out\n\n(venv) root@hostname:~/$ python ghclient.py ${HUB_ADDRESS} -u ${USERNAME} -p ${PASSWORD} zones -v | \\\n    python -c \"import sys, json; print(json.dumps(json.load(sys.stdin, parse_float=lambda x: int(float(x))), indent=4, sort_keys=True))\" > b.out\n\n(venv) root@hostname:~/$ diff a.out b.out\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An aiohttp-based client for Genius Hub systems",
    "version": "0.7.1",
    "project_urls": {
        "Bug Reports": "https://github.com/manzanotti/geniushub-client/issues",
        "Homepage": "https://github.com/manzanotti/geniushub-client",
        "Source": "https://github.com/manzanotti/geniushub-client"
    },
    "split_keywords": [
        "genius",
        "geniushub",
        "heatgenius"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1708ed92ea2d5756eff8388f3fff366940bb7d208441bc7f426969ed39fb58f8",
                "md5": "2686881f4e28238e564afe5c28bdd043",
                "sha256": "89de1623e53592eb374df411711361c38f11f2ebffc346949b56ab2103122228"
            },
            "downloads": -1,
            "filename": "geniushub_client-0.7.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2686881f4e28238e564afe5c28bdd043",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 36434,
            "upload_time": "2023-10-30T14:30:16",
            "upload_time_iso_8601": "2023-10-30T14:30:16.710118Z",
            "url": "https://files.pythonhosted.org/packages/17/08/ed92ea2d5756eff8388f3fff366940bb7d208441bc7f426969ed39fb58f8/geniushub_client-0.7.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a40891577ed44a51010db08f4ec59ab8f31d49182bb5d7d2d729194b8c35057f",
                "md5": "a932031ccf5f9a74a8f23425a998b769",
                "sha256": "22bd773edaac9e5f3a2b8d6675b825fcb90acaa7587eb5b8e088645c861cd8d6"
            },
            "downloads": -1,
            "filename": "geniushub-client-0.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a932031ccf5f9a74a8f23425a998b769",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 25008,
            "upload_time": "2023-10-30T14:30:18",
            "upload_time_iso_8601": "2023-10-30T14:30:18.169355Z",
            "url": "https://files.pythonhosted.org/packages/a4/08/91577ed44a51010db08f4ec59ab8f31d49182bb5d7d2d729194b8c35057f/geniushub-client-0.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 14:30:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "manzanotti",
    "github_project": "geniushub-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "circle": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    ">=",
                    "3.7.4"
                ]
            ]
        }
    ],
    "lcname": "geniushub-client"
}
        
Elapsed time: 0.14706s