python library for accessing the openHAB REST API
Project description
python library for accessing the openHAB REST API
This library allows for easily accessing the OpenHAB REST API. A number of features are implemented but not all, this is work in progress.
Requirements
python >= 3.5
python :: dateutil
python :: requests
python :: typing
Note on openHAB1:
The current version is focused on OpenHAB 2.x; OpenHAB 1.x might still work, though this is not tested. If you require older OpenHAB support, please use an older version of this library.
Installation
Install the latest version using pip:
pip install python-openhab
Example
Example usage of the library:
from openhab import openHAB
base_url = 'http://localhost:8080/rest'
openhab = OpenHAB(base_url)
# fetch all items
items = openhab.fetch_all_items()
sunset = items.get('Sunset')
print(sunset.state)
# fetch a single item
item = openhab.get_item('light_switch')
# turn a switch on
item.on()
# send a state update (this only update the state)
item.state = 'OFF'
# send a command
item.command('ON')
# check if item state is NULL
if item.state is None and item.is_state_null():
pass
# check if item state is UNDEF
if item.state is None and item.is_state_undef():
pass
# fetch some group
lights_group = openhab.get_item('lights_group')
# send command to group
lights_group.on()
# send update to each member
for v in lights_group.members.values():
v.update('OFF')
Note on NULL and UNDEF
In OpenHAB items may have two states named NULL and UNDEF, which have distinct meanings but basically indicate that an item has no usable value. This library sets the state of an item, regardless of their OpenHAB value being NULL or UNDEF, to None. This in order to ease working with the library as we do cast certain types to native types.
In order to check if an item’s state is either NULL or UNDEF, you can use the helper functions:
item.is_state_null()
item.is_state_undef()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-openhab-2.13.0.tar.gz
.
File metadata
- Download URL: python-openhab-2.13.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2456dcd5f5b4fb7a5f3dc82e76376746e4b8e4f68384f356dbd42ceabbeb1334 |
|
MD5 | cf4e3c5d4f60f90d8a83eac08e2e2ecb |
|
BLAKE2b-256 | 50086d2ec29e121d2f5733fcd6fe1711084902a3923baae175415fcfd9abf8e3 |
File details
Details for the file python_openhab-2.13.0-py3-none-any.whl
.
File metadata
- Download URL: python_openhab-2.13.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77ffe45fa35d42ac3feb103289300395981beb6a3ba3e9562e826b5dad6038d6 |
|
MD5 | 7e447d0861e2b1c974296a9d5ad5c608 |
|
BLAKE2b-256 | 1af75024a1622286ebd3c9ece2ca9cd4dc2a14dc4e58d0d03a175ce8f0371b84 |