Skip to main content

Talk to the Myko API asynchronously

Project description

Creates a session to HubSpace and handles authentication

This project was designed to asynchronously connect to the HubSpace API and retrieve data. The implementation was based on jdeath/Hubspace-Homeassistant but converted to async and cleaned up.

Examples

These examples provide sample usage when running from the python shell. If the code is running within an async loop, gathering the loop and telling it to run is not required.

Gather all devices from the API

import logging

import hubspace_async
import asyncio


# TRACE messages in logs
hubspace_async.logger.setLevel(logging.HS_TRACE)
hubspace_async.logger.addHandler(logging.StreamHandler())

try:
    loop = asyncio.get_event_loop()
except RunTimeError:
    loop = asyncio.new_event_loop()

username = "<username>"
password = "<password>

async def get_devices(username, password):
    connection = hubspace_async.HubSpaceConnection(username, password)
    return await connection.devices



loop.run_until_complete(get_devices(username, password))

A sample output would look like

[{"id": "blah1"}, {"id": "blah2"}]

After running this code, the following attributes will be populated:

  • homes: Dictionary of all homes from the API response

  • rooms: Dictionary of all rooms from the API response

  • devices: Dictionary of all devices from the API response

Updating a devices state

In this example we will turn a light on. The request requires the use of functionInstance for it to work. However some updates may not require this field.

from hubspace_async import connection, HubSpaceState
import asyncio


conn = connection.HubSpaceConnection("username", "password")
state = HubSpaceState(
     functionClass="power",
     functionInstance="light-power",
     value="on",
 )
child_id = "abc123"
loop.run_until_complete(conn.set_device_state(child_id, new_states))

CLI Commands

A CLI is provided for testing your credentials and connection to hubspace. For all commands, click needs to be installed. The easiest way to install click is by using the cli extras.

pip install hubspace-async[cli]

Testing Auth

To test auth, run the following command: python -m hubspace_async.cli --username "<username>" --password "<password>" auth-flow

If successful, the message “Token has been successfully generated” will be displayed.

Testing Connectivity

To test connectivity, run the following command: python -m hubspace_async.cli --username "<username>" --password "<password>" auth-flow

If successful, an account id with several hyphens will appear.

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

myko_async-0.4.1.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

myko_async-0.4.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file myko_async-0.4.1.tar.gz.

File metadata

  • Download URL: myko_async-0.4.1.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for myko_async-0.4.1.tar.gz
Algorithm Hash digest
SHA256 91375992f8df926840ca764b84509e071013a2611fa33ac1af9e3c635701d5ef
MD5 5c860039cf4d63181f14fc449dfd847a
BLAKE2b-256 f08188ccbd84c7029933b0d67fde4e5d273062edca9ca54e6af28a0330b5293f

See more details on using hashes here.

File details

Details for the file myko_async-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: myko_async-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for myko_async-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59f9b94c34c973799d160db45d4546cf043779ac8b205fffa01a4790d42d8eeb
MD5 afbf246cb7f42678ecdd459ebb96b090
BLAKE2b-256 8a976e7c613d88a89a9c12662e79817fdd31cedcaded2bda3d1d709ba203fb32

See more details on using hashes here.

Supported by

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