Metadata-Version: 2.3
Name: hubspace-async
Version: 0.1.2
Summary: Talk to the HubSpace API asynchronously
Project-URL: Repository, https://github.com/Expl0dingBanana/hubspace-async
Project-URL: Changelog, https://github.com/Expl0dingBanana/hubspace-async/CHANGELOG.md
Author-email: Chris Dohmen <chris.dohmen11@gmail.com>
Maintainer-email: Chris Dohmen <chris.dohmen11@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2024 Chris Dohmen
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: AUTHORS.rst
License-File: LICENSE.txt
Keywords: HubSpace
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Requires-Dist: aiohttp
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-cov; extra == 'test'
Requires-Dist: pytest-mock; extra == 'test'
Requires-Dist: responses; extra == 'test'
Description-Content-Type: text/x-rst

==============
hubspace-async
==============


    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 <https://github.com/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
-------------------------------

.. code-block:: python

    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

.. code-block:: json

   [{"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.


.. code-block:: python


   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))
