Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ dev ]
branches: [dev]
pull_request:
# The branches below must be a subset of the branches above
branches: [ dev ]
branches: [dev]
schedule:
- cron: '17 7 * * 1'
- cron: "17 7 * * 1"

jobs:
analyze:
Expand All @@ -32,39 +32,39 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: ["python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
5 changes: 4 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ jobs:
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: poetry publish --build -username $TWINE_USERNAME --password TWINE_PASSWORD
run: |
poetry publish --build \
--username $TWINE_USERNAME \
--password TWINE_PASSWORD
50 changes: 33 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
# Changelog

**v2.0.0**
- Added Data Models
- Added Documentation
- Added functions for all endpoints
## v3.0.0

**v2.1.0**
- Added Event support
- Added Rigorous CI/CD tools, i.e. `black`, `isort`, `mypy`, `pre-commit`, `pylint`, `flake8`.
- Renamed `AsyncClient` methods with `async_<method>` convention.
- `Client` and `AsyncClient` can be initialized without confirming the API's status.
- `Client` and `AsyncClient` are now both context managers that function the exact same.
- Both clients now share previously redundant model conversion methods.
- Reversed CHANGELOG order (most recent first).

**v2.2.0**
- Implemented async support with `homeassistant_api._async.AsyncClient`
## v2.4.0.post2

**v2.3.0**
- Bug fixes (see closed issues between releases)
- Added global request kwargs parameter to Client objects (see [docs](https://homeassistantapi.readthedocs.io/en/latest/api.html))
- Fixed wrong check in malformed_id function

## v2.4.0.post1

- Replaced `text/plain` with `application/octet-stream` in docs and processing module.
- Added message content to UnrecognizedStatusCodeError to help with user debugging

## v2.4.0

**v2.4.0**
- Bug fixes (see closed issues between releases)
- Added a processing framework for hooking into mimetype processing
- Fixed some issues with some ``AsyncClient`` methods

**v2.4.0.post1**
- Replaced `text/plain` with `application/octet-stream` in docs and processing module.
- Added message content to UnrecognizedStatusCodeError to help with user debugging
## v2.3.0

**v2.4.0.post2**
- Fixed wrong check in malformed_id function
- Bug fixes (see closed issues between releases)
- Added global request kwargs parameter to Client objects (see [docs](homeassistantapi.rtfd.io/en/latest/api.html#homeassistant_api.Client))

## v2.2.0

- Implemented async support with `homeassistant_api._async.AsyncClient`

## v2.1.0

- Added Event support

## v2.0.0

- Added Data Models
- Added Documentation
- Added functions for all endpoints
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
![GitHub release (latest by date)](https://img.shields.io/github/v/release/GrandMoff100/HomeassistantAPI?style=for-the-badge)
![GitHub release (latest by date)](https://img.shields.io/github/downloads/GrandMoff100/HomeassistantAPI/latest/total?style=for-the-badge)

![Homeassistant Logo](https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true)
![Home AssistantLogo](https://github.com/GrandMoff100/HomeAssistantAPI/blob/7edb4e6298d37bda19c08b807613c6d351788491/docs/images/homeassistant-logo.png?raw=true)

Python Wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)

Expand Down
29 changes: 19 additions & 10 deletions docs/processing.rst → docs/advanced.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
*******************
Advanced Section
*******************

Persistent Caching
********************


Response Processing
**********************
Homeassistant API uses functions called processors.
Home Assistant API uses functions called processors.
These functions take a Response object as a parameter and return the python data type associated with the content-type header.

How To Register Response Processors (Converters)
Expand All @@ -15,16 +23,16 @@ To register a response processor you need to import the Processing class and the
from homeassistant_api.processing import process_json


@Processing.processor("application/octet-stream", override=True)
@Processing.processor("application/octet-stream")
def text_processor(response):
return response.text.lower()

@Processing.async_processor("text/csv")
@Processing.processor("text/csv")
async def async_text_processor(response):
text = await response.text()
return [line.split(",") for line in text.splitlines()]

@Processing.processor("application/json", override=True)
@Processing.processor("application/json")
def json_processor(response):
print("I processed a json response!)
return process_json(response)
Expand All @@ -34,14 +42,15 @@ To register a response processor you need to import the Processing class and the
print(client.get_entities())


In this example.
In this example.
The first processor (a function wrapped with the processor decorator) is going to be called when we receive a response that has that as its :code:`Content-Type` header.
Because :code:`homeassistant_api` provides processors for :code:`application/octet-stream` and :code:`application/json` by default,
we need to tell :code:`homeassistant_api` to override the default processor with :code:`override=True`.
:code:`homeassistant_api` provides processors for :code:`application/octet-stream` and :code:`application/json` by default,
But :code:`@Processing.processor` gives the most recently registered processor the highest precedence when choosing a processor for a response.
So our processor here will be chosen over the default processors.

The second processor is an async processor that only gets called when AsyncClient receives a response that has :code:`text/csv` as its :code:`Content-Type` header.
If you wanted to override :code:`homeassistant_api`'s default json processing using the :code:`json` module with a different way to process json data.
Such as using instead, the :code:`ujson` module (which is faster but more limiting).
The second processor is an async processor that only gets called when Client receives an async response that has :code:`text/csv` as its :code:`Content-Type` header.
If you wanted, you could not use :code:`homeassistant_api`'s default json processing using the :code:`json` module,
and use instead the :code:`ujson` module (which is faster but more restrictive).

The third processor function implements the default processor function for the :code:`application/json` mimetype after printing a string.
If you wanted to run some intermediate processing.
Expand Down
70 changes: 22 additions & 48 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,85 +1,59 @@
Code Reference
***************

.. currentmodule:: homeassistant_api


Clients
--------

.. autoclass:: Client
:members:
:inherited-members:

.. autoclass:: homeassistant_api._async.AsyncClient
.. autoclass:: homeassistant_api.Client
:members:
:inherited-members:


Data Models
------------

.. autoclass:: Domain
:members:
.. automodule:: homeassistant_api.models

.. autoclass:: Service
:members:
.. autoclass:: Domain

.. autoclass:: Group
:members:
.. autoclass:: Service

.. autoclass:: Entity
:members:
.. autoclass:: Group

.. autoclass:: State
:members:
.. autoclass:: Entity

.. autoclass:: Event
:members:
.. autoclass:: History

.. autoclass:: State

.. autoclass:: homeassistant_api._async.AsyncDomain
:members:
.. autoclass:: Event

.. autoclass:: homeassistant_api._async.AsyncService
:members:

.. autoclass:: homeassistant_api._async.AsyncGroup
:members:

.. autoclass:: homeassistant_api._async.AsyncEntity
:members:
.. automodule:: homeassistant_api._async.models

.. autoclass:: homeassistant_api._async.AsyncEvent
:members:
.. autoclass:: AsyncDomain

.. autoclass:: AsyncService

Processing
-----------
.. autoclass:: AsyncGroup

.. autoclass:: AsyncEntity

.. autoclass:: Processing
:members:
.. autoclass:: AsyncEvent


Exceptions
Processing
-----------

.. autoclass:: homeassistant_api.errors.RequestError

.. autoclass:: homeassistant_api.errors.MalformedDataError

.. autoclass:: homeassistant_api.errors.MalformedInputError

.. autoclass:: homeassistant_api.errors.APIConfigurationError

.. autoclass:: homeassistant_api.errors.ParameterMissingError

.. autoclass:: homeassistant_api.errors.UnexpectedStatusCodeError
.. autoclass:: homeassistant_api.processing.Processing
:members:

.. autoclass:: homeassistant_api.errors.UnauthorizedError

.. autoclass:: homeassistant_api.errors.EndpointNotFoundError
Exceptions
-----------

.. autoclass:: homeassistant_api.errors.MethodNotAllowedError
.. automodule:: homeassistant_api.errors
:members:

1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"issues": "https://github.com/GrandMoff100/HomeassistantAPI/issues",
"discussions": "https://github.com/GrandMoff100/HomeassistantAPI/discussions",
"examples": f"https://github.com/GrandMoff100/HomeassistantAPI/tree/{branch}/examples",
"new_pr": "https://github.com/GrandMoff100/HomeAssistantAPI/compare",
}

# Add any paths that contain templates here, relative to this directory.
Expand Down
Loading