Skip to main content

Unofficial python SDK for Brunt, this package allows you to control your Brunt devices from code.

Project description

PyPI version

Brunt

Unofficial python SDK for Brunt, based on the NPM version here https://github.com/MattJeanes/brunt-api

This package allows you to control your Brunt devices from code.

Sample script

This script shows the usage and how to use the output of the calls, off course if you already know the name of your device you do not need to call getThings.

This script checks the current position of a blind called 'Blind' and if that is 100 (fully open), sets it to 90 and vice versa.

from brunt import BruntClient, BruntClientAsync

bapi = BruntClient() 
# bapi = BruntClientAsync()
print("Calling Brunt")

bapi.login('username', 'password')
# await bapi.async_login('username', 'password')
print("    Logged in, gettings things.")

things = bapi.get_things()['things']
# things = await bapi.async_get_things()['things']
print(f"    { len(things) } thing(s) found.")

state = bapi.get_state(thing='Blind')['thing']
# state = await bapi.async_get_state(thing='Blind')['thing']
print(f"    Current status of { state['NAME'] } is position { state['currentPosition'] }")
newPos = 100
if int(state['currentPosition']) == 100:
    newPos = 90
print(f"    Setting { state['NAME'] } to position { newPos }")

res = bapi.change_request_position(newPos, thing='Blind')
# res = await bapi.async_change_request_position(newPos, thing='Blind')
print('    Success!' if res else '    Fail!')
    

BruntClient & BruntClientAsync

from brunt import BruntClient
BruntClient(username, password)

or 

from brunt import BruntClientAsync
BruntClientAsync(username, password, session)

Constructor for the API wrapper.

If you supply username and password here, they are stored, but not used. Auto logging in then does work when calling another method, no explicit login needed.

:param username: the username of your Brunt account :param password: the password of your Brunt account

Async only :param session: aiohttp.ClientSession object

login

BruntClient.login(self, username, password)
await BruntClient.async_login(self, username, password)

Login method using username and password

:param username: the username of your Brunt account :param password: the password of your Brunt account

:return: True if successful :raises: errors from Requests call

get_things

BruntClient.get_things(self)
await BruntClient.async_get_things(self)

Get the things registered in your account

:return: List of Things :raises: errors from Requests call

get_state

BruntClient.get_state(self, thing="Blind")
await BruntClient.async_get_state(self, thing="Blind")

Get the state of a thing, by NAME or thingUri

:param thing: a string with the NAME of the thing, which is then checked against the names of all the things. :param thingUri: Uri (string) of the thing you are getting the state from, not checked against getThings.

:return: a Thing. :raises: ValueError if the requested thing does not exists. NameError if not logged in. SyntaxError when not exactly one of the params is given.

change_request_position

BruntClient.change_request_position(self, request_position, thing="Blind")
await BruntClient.async_change_request_position(self, request_position, thing="Blind")

Changes the position of the thing. Internally calls the changeKey method with key set to requestPosition and value set to request_position

:param request_position: The new position for the slide (0-100) :param thing: a string with the name of the thing, which is then checked against the names of all the things. :param thingUri: Uri (string) of the thing you are getting the state from, not checked against getThings.

:return: a dict with 'result'. :raises: ValueError if the requested thing does not exists or the position is not between 0 and 100. NameError if not logged in. SyntaxError when not exactly one of the params is given.

change_key

BruntClient.change_key(self, key="requestPosition", value="100", thing="Blind")
await BruntClient.async_change_key(self, key="requestPosition", value="100", thing="Blind")

Change a variable of the thing by supplying the key and value. Mostly included for future additions.

:param key: The key of the value you want to change :param value: The new value :param thing: a string with the name of the thing, which is then checked using getThings. :param thingUri: Uri (string) of the thing you are getting the state from, not checked against getThings. :return: a dict with 'result'. :raises: ValueError if the requested thing does not exists or the position is not between 0 and 100. NameError if not logged in. SyntaxError when not exactly one of the params is given.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brunt-1.2.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

brunt-1.2.0-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file brunt-1.2.0.tar.gz.

File metadata

  • Download URL: brunt-1.2.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for brunt-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e704627dc7b9c0a50c67ae90f1d320b14f99f2b2fc9bf1ef0461b141dcf1bce9
MD5 1aa63eb53c34471ec3412c2812b5e5c5
BLAKE2b-256 3e78050066a1f560ddc99e7ed2ea144cc241e0735f24e58709898e544bacfd93

See more details on using hashes here.

File details

Details for the file brunt-1.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: brunt-1.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for brunt-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 81c7b573989f8220e68e1252b2c79ac151168756512a07a2f76fc88921bcffa1
MD5 e59489a581978aef91b80acc784d19bd
BLAKE2b-256 dd061d9d65902163697c616d83c28a70c1893d324ddd9c80e9331bc168c03f4a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page