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
31 changes: 31 additions & 0 deletions .github/workflows/code_rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Code Standards

on:
pull_request:
workflow_dispatch:

jobs:
code_styling:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v2
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install
- name: Run Black
run: black homeassistant_api --check
- name: Run iSort
run: isort homeassistant_api --check-only
- name: Run Flake8
run: flake8 homeassistant_api
- name: Run MyPy
run: mypy homeassistant_api --show-error-codes
- name: Run PyLint
run: pylint homeassistant_api
26 changes: 0 additions & 26 deletions .github/workflows/flake8.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ vscode:
extensions:
- ms-python.python
- matangover.mypy
ports:
- port: 8000
visibility: public
onOpen: ignore
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ repos:
- repo: https://github.com/pre-commit/mirrors-mypy
hooks:
- id: mypy
additional_dependencies:
- types-requests
- types-simplejson
rev: 'v0.931'
- repo: https://github.com/pre-commit/pre-commit-hooks
hooks:
Expand All @@ -22,4 +25,5 @@ repos:
- repo: https://github.com/PyCQA/pylint
rev: 'v2.12.2'
hooks:
- id: pylint
- id: pylint
language: system
5 changes: 4 additions & 1 deletion docs/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

@import '../basic.css';
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono&family=Roboto+Condensed:wght@700&family=Source+Sans+Pro&display=swap');

Expand All @@ -8,9 +9,11 @@ img {
border-radius: 10px;
}

/*
div.sphinxsidebarwrapper {
margin-right: 30px;
}
*/

div.sphinxsidebar {
width: 260px;
Expand Down Expand Up @@ -46,7 +49,7 @@ div.sphinxsidebar {
.rst-content .toctree-wrapper > p.caption, h1, h2, h3, h4, h5, h6, legend {
margin-top: 0;
font-weight: 700;
font-family: 'Roboto Condensed', sans-serif;
/*font-family: 'Roboto Condensed', sans-serif;*/
}

body {
Expand Down
3 changes: 0 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ Data Models
.. autoclass:: homeassistant_api._async.AsyncEntity
:members:

.. autoclass:: homeassistant_api._async.AsyncState
:members:

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

Expand Down
19 changes: 10 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration file for the Sphinx documentation builder.
"""Configuration file for the Sphinx documentation builder."""
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
Expand All @@ -13,22 +13,23 @@
import os
import sys

import toml # type: ignore[import]

sys.path.insert(0, os.path.abspath("../"))
sys.path.append(os.path.abspath("extensions"))

from homeassistant_api import __version__

# -- Project information -----------------------------------------------------

project = "Homeassistant API"
copyright = "2021, Nate Larsen"
copyright = "2021, Nate Larsen" # pylint: disable=redefined-builtin
author = "Nate Larsen"

# The full version, including alpha/beta/rc tags

version = __version__
release = version

try:
data = toml.load("../pyproject.toml")
release = version = data["tool"]["poetry"]["version"]
except KeyError:
release = version = "1.0.0"

# -- General configuration ---------------------------------------------------

Expand All @@ -42,7 +43,7 @@
else "v" + version
)

extensions = ["sphinx.ext.autodoc", "resourcelinks"]
extensions = ["sphinx.ext.autodoc", "resourcelinks", "sphinx_autodoc_typehints"]

resource_links = {
"repo": "https://github.com/GrandMoff100/HomeassistantAPI/",
Expand Down
25 changes: 0 additions & 25 deletions docs/credits.rst

This file was deleted.

4 changes: 0 additions & 4 deletions docs/doc_requirements.txt

This file was deleted.

7 changes: 3 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Index
quickstart
usage
faq
api
processing
credits


Expand Down Expand Up @@ -58,7 +56,8 @@ Contributing
-------------

We very warmly welcome contributions.
If you have an idea or some code you want to add to the project please fork :resource:`the repository <repo>`, make your changes, and open a pull request.
Most likely your changes will get merged if your code passes flake8 without any errors, and adds some functionality to the project.
If you have an idea or some code you want to add to the project please fork :resource:`the repository <repo>`, make your changes, and open a pull request.
Most likely your changes will get merged if your code passes flake8 without any errors, and adds some functionality to the project.
We'd love to incorporate your unique ideas and perspective!

We would love to give a special shoutout to `<FoxNerdSaysMoo> https://github.com/FoxNerdSaysMoo` for contributions to some of the awesome theme styling on these docs!
40 changes: 27 additions & 13 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
Usage
###########


The Basics...
**************

This library is centered around the :code:`Client` class.
Once you have have your api base url and Long Lived Access Token from homeassistant we can start to do stuff.
The rest of this guide assumes you have the :code:`Client` saved to a :code:`client` variable like this.
Most of these examples require some integrations to be setup inside homeassistant for them to actually work.
The rest of this guide assumes you have the :code:`Client` (or :code:`AsyncClient`) saved to a :code:`client` variable like this.
Most of these examples require some integrations to be setup inside homeassistant for the examples to actually work.


.. code-block:: python
Expand All @@ -20,17 +24,14 @@ Most of these examples require some integrations to be setup inside homeassistan
client = Client(URL, TOKEN)


How To Use...
**************

Client
========
The most commonly used features of this library include triggering services and getting and modifying entity states.

Services
---------
.. code-block:: python

domains = client.get_domains()
# {'homeassistant': <Domain homeassistant>, 'notify': <Domain notify>}

Expand Down Expand Up @@ -62,10 +63,10 @@ Entities

new_state = client.set_state(state='my ToaTallY Whatever vAlUe 12t87932', group_id='my_favorite_colors', entity_slug='number_one')
# <EntityState "my ToaTallY Whatever vAlUe 12t87932" entity_id="my_favorite_colors.number_one">

# Alternatively you can set state from the entity class itself
from homeassistant_api import State

# If you are wondering where door came from its about 15 lines up.
door.state.state = 'My new state'
door.state.attributes['open_height'] = '23'
Expand All @@ -75,9 +76,9 @@ Entities

AsyncClient
=============
Before you run this code you need to install the :code:`homeassistant_api[async]`
And here is the async counterpart to the usage above.
Except if you want to run async code in the console using await you need to install :code:`aioconsole` and then run :code:`$ apython`
Before you run this code you need to install the :code:`homeassistant_api[async]` (it just installs :code:`aiohttp`).
Here is the async counterpart to the usage above.
Except how to run async code in the console without starting an eventloop yourself you ask? You can install :code:`aioconsole` and then run :code:`$ apython`


Services
Expand Down Expand Up @@ -119,12 +120,25 @@ Entities

new_state = await client.set_state(state='my ToaTallY Whatever vAlUe 12t87932', group_id='my_favorite_colors', entity_slug='number_one')
# <EntityState "my ToaTallY Whatever vAlUe 12t87932" entity_id="my_favorite_colors.number_one">

# Alternatively you can set state from the entity class itself
from homeassistant_api import State

# If you are wondering where door came from its about 15 lines up.
door.state.state = 'My new state'
door.state.attributes['open_height'] = '23'
await door.set_state(door.state)
# <EntityState "My new state" entity_id="cover.garage_door">


What's Next?
*************

Browse below to learn more about what you can do with :code:`homeassistant_api`.


.. toctree::
:maxdepth: 2

processing
api
6 changes: 5 additions & 1 deletion examples/myq_grarage_door.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from homeassistant_api import Client

client = Client(os.getenv("API_URL"), os.getenv("TOKEN"))
api_url = os.getenv("API_URL")
token = os.getenv("TOKEN")

if api_url is not None and token is not None:
client = Client(api_url, token)

# Gets open garage service
open_garage = client.get_domains().cover.open_garage
Expand Down
4 changes: 3 additions & 1 deletion homeassistant_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .client import Client, RawClient
"""Imports all module stuff for convenience."""
from ._async import AsyncClient
from .client import Client
from .errors import (
APIConfigurationError,
EndpointNotFoundError,
Expand Down
10 changes: 2 additions & 8 deletions homeassistant_api/_async/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""Imports obejcts from the async sub-module for convenience."""
from .asyncclient import AsyncClient
from .models import (
AsyncDomain,
AsyncEntity,
AsyncEvent,
AsyncGroup,
AsyncService,
AsyncState,
)
from .models import AsyncDomain, AsyncEntity, AsyncEvent, AsyncGroup, AsyncService
Loading