somestuff-hassstuff 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- somestuff_hassstuff-0.1.0/.gitignore +180 -0
- somestuff_hassstuff-0.1.0/LICENSE.md +163 -0
- somestuff_hassstuff-0.1.0/PKG-INFO +108 -0
- somestuff_hassstuff-0.1.0/README.md +82 -0
- somestuff_hassstuff-0.1.0/pyproject.toml +53 -0
- somestuff_hassstuff-0.1.0/somestuff/hassstuff/README.md +82 -0
- somestuff_hassstuff-0.1.0/somestuff/hassstuff/__init__.py +3 -0
- somestuff_hassstuff-0.1.0/somestuff/hassstuff/__main__.py +3 -0
- somestuff_hassstuff-0.1.0/somestuff/hassstuff/cli.py +1138 -0
- somestuff_hassstuff-0.1.0/somestuff/hassstuff/client.py +355 -0
- somestuff_hassstuff-0.1.0/somestuff/hassstuff/py.typed +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**/.gtfs_cache
|
|
2
|
+
/*.local
|
|
3
|
+
.claude
|
|
4
|
+
|
|
5
|
+
/*gguf*
|
|
6
|
+
|
|
7
|
+
/docker-config
|
|
8
|
+
/docker_build_local.log
|
|
9
|
+
|
|
10
|
+
/ms?hit
|
|
11
|
+
*mstest*py
|
|
12
|
+
*_test.py
|
|
13
|
+
/umqtt
|
|
14
|
+
.idea/
|
|
15
|
+
/upydev_.config
|
|
16
|
+
*.local.*
|
|
17
|
+
/scripts/logdir/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Byte-compiled / optimized / DLL files
|
|
21
|
+
__pycache__/
|
|
22
|
+
*.py[cod]
|
|
23
|
+
*$py.class
|
|
24
|
+
|
|
25
|
+
# C extensions
|
|
26
|
+
*.so
|
|
27
|
+
|
|
28
|
+
# Distribution / packaging
|
|
29
|
+
.Python
|
|
30
|
+
build/
|
|
31
|
+
develop-eggs/
|
|
32
|
+
dist/
|
|
33
|
+
downloads/
|
|
34
|
+
eggs/
|
|
35
|
+
.eggs/
|
|
36
|
+
lib/
|
|
37
|
+
lib64/
|
|
38
|
+
parts/
|
|
39
|
+
sdist/
|
|
40
|
+
var/
|
|
41
|
+
wheels/
|
|
42
|
+
share/python-wheels/
|
|
43
|
+
*.egg-info/
|
|
44
|
+
.installed.cfg
|
|
45
|
+
*.egg
|
|
46
|
+
MANIFEST
|
|
47
|
+
|
|
48
|
+
# PyInstaller
|
|
49
|
+
# Usually these files are written by a python script from a template
|
|
50
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
51
|
+
*.manifest
|
|
52
|
+
*.spec
|
|
53
|
+
|
|
54
|
+
# Installer logs
|
|
55
|
+
pip-log.txt
|
|
56
|
+
pip-delete-this-directory.txt
|
|
57
|
+
|
|
58
|
+
# Unit test / coverage reports
|
|
59
|
+
htmlcov/
|
|
60
|
+
.tox/
|
|
61
|
+
.nox/
|
|
62
|
+
.coverage
|
|
63
|
+
.coverage.*
|
|
64
|
+
.cache
|
|
65
|
+
nosetests.xml
|
|
66
|
+
coverage.xml
|
|
67
|
+
*.cover
|
|
68
|
+
*.py,cover
|
|
69
|
+
.hypothesis/
|
|
70
|
+
.pytest_cache/
|
|
71
|
+
cover/
|
|
72
|
+
|
|
73
|
+
# Translations
|
|
74
|
+
*.mo
|
|
75
|
+
*.pot
|
|
76
|
+
|
|
77
|
+
# Django stuff:
|
|
78
|
+
*.log
|
|
79
|
+
local_settings.py
|
|
80
|
+
db.sqlite3
|
|
81
|
+
db.sqlite3-journal
|
|
82
|
+
|
|
83
|
+
# Flask stuff:
|
|
84
|
+
instance/
|
|
85
|
+
.webassets-cache
|
|
86
|
+
|
|
87
|
+
# Scrapy stuff:
|
|
88
|
+
.scrapy
|
|
89
|
+
|
|
90
|
+
# Sphinx documentation
|
|
91
|
+
docs/_build/
|
|
92
|
+
|
|
93
|
+
# PyBuilder
|
|
94
|
+
.pybuilder/
|
|
95
|
+
target/
|
|
96
|
+
|
|
97
|
+
# Jupyter Notebook
|
|
98
|
+
.ipynb_checkpoints
|
|
99
|
+
|
|
100
|
+
# IPython
|
|
101
|
+
profile_default/
|
|
102
|
+
ipython_config.py
|
|
103
|
+
|
|
104
|
+
# pyenv
|
|
105
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
106
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
107
|
+
# .python-version
|
|
108
|
+
|
|
109
|
+
# pipenv
|
|
110
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
111
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
112
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
113
|
+
# install all needed dependencies.
|
|
114
|
+
#Pipfile.lock
|
|
115
|
+
|
|
116
|
+
# poetry
|
|
117
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
118
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
119
|
+
# commonly ignored for libraries.
|
|
120
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
121
|
+
#poetry.lock
|
|
122
|
+
|
|
123
|
+
# pdm
|
|
124
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
125
|
+
#pdm.lock
|
|
126
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
127
|
+
# in version control.
|
|
128
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
129
|
+
.pdm.toml
|
|
130
|
+
|
|
131
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
132
|
+
__pypackages__/
|
|
133
|
+
|
|
134
|
+
# Celery stuff
|
|
135
|
+
celerybeat-schedule
|
|
136
|
+
celerybeat.pid
|
|
137
|
+
|
|
138
|
+
# SageMath parsed files
|
|
139
|
+
*.sage.py
|
|
140
|
+
|
|
141
|
+
# Environments
|
|
142
|
+
.env
|
|
143
|
+
.venv
|
|
144
|
+
env/
|
|
145
|
+
venv/
|
|
146
|
+
ENV/
|
|
147
|
+
env.bak/
|
|
148
|
+
venv.bak/
|
|
149
|
+
|
|
150
|
+
# Spyder project settings
|
|
151
|
+
.spyderproject
|
|
152
|
+
.spyproject
|
|
153
|
+
|
|
154
|
+
# Rope project settings
|
|
155
|
+
.ropeproject
|
|
156
|
+
|
|
157
|
+
# mkdocs documentation
|
|
158
|
+
/site
|
|
159
|
+
|
|
160
|
+
# mypy
|
|
161
|
+
.mypy_cache/
|
|
162
|
+
.dmypy.json
|
|
163
|
+
dmypy.json
|
|
164
|
+
|
|
165
|
+
# Pyre type checker
|
|
166
|
+
.pyre/
|
|
167
|
+
|
|
168
|
+
# pytype static type analyzer
|
|
169
|
+
.pytype/
|
|
170
|
+
|
|
171
|
+
# Cython debug symbols
|
|
172
|
+
cython_debug/
|
|
173
|
+
|
|
174
|
+
# PyCharm
|
|
175
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
176
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
177
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
178
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
179
|
+
#.idea/
|
|
180
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
GNU Lesser General Public License
|
|
2
|
+
=================================
|
|
3
|
+
|
|
4
|
+
_Version 3, 29 June 2007_
|
|
5
|
+
_Copyright © 2007 Free Software Foundation, Inc. <<http://fsf.org/>>_
|
|
6
|
+
|
|
7
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
8
|
+
of this license document, but changing it is not allowed.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates
|
|
12
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
13
|
+
License, supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
### 0. Additional Definitions
|
|
16
|
+
|
|
17
|
+
As used herein, “this License” refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the “GNU GPL” refers to version 3 of the GNU
|
|
19
|
+
General Public License.
|
|
20
|
+
|
|
21
|
+
“The Library” refers to a covered work governed by this License,
|
|
22
|
+
other than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An “Application” is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A “Combined Work” is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the “Linked
|
|
32
|
+
Version”.
|
|
33
|
+
|
|
34
|
+
The “Minimal Corresponding Source” for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The “Corresponding Application Code” for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
### 1. Exception to Section 3 of the GNU GPL
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
### 2. Conveying Modified Versions
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
* **a)** under this License, provided that you make a good faith effort to
|
|
58
|
+
ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
|
|
62
|
+
* **b)** under the GNU GPL, with none of the additional permissions of
|
|
63
|
+
this License applicable to that copy.
|
|
64
|
+
|
|
65
|
+
### 3. Object Code Incorporating Material from Library Header Files
|
|
66
|
+
|
|
67
|
+
The object code form of an Application may incorporate material from
|
|
68
|
+
a header file that is part of the Library. You may convey such object
|
|
69
|
+
code under terms of your choice, provided that, if the incorporated
|
|
70
|
+
material is not limited to numerical parameters, data structure
|
|
71
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
72
|
+
(ten or fewer lines in length), you do both of the following:
|
|
73
|
+
|
|
74
|
+
* **a)** Give prominent notice with each copy of the object code that the
|
|
75
|
+
Library is used in it and that the Library and its use are
|
|
76
|
+
covered by this License.
|
|
77
|
+
* **b)** Accompany the object code with a copy of the GNU GPL and this license
|
|
78
|
+
document.
|
|
79
|
+
|
|
80
|
+
### 4. Combined Works
|
|
81
|
+
|
|
82
|
+
You may convey a Combined Work under terms of your choice that,
|
|
83
|
+
taken together, effectively do not restrict modification of the
|
|
84
|
+
portions of the Library contained in the Combined Work and reverse
|
|
85
|
+
engineering for debugging such modifications, if you also do each of
|
|
86
|
+
the following:
|
|
87
|
+
|
|
88
|
+
* **a)** Give prominent notice with each copy of the Combined Work that
|
|
89
|
+
the Library is used in it and that the Library and its use are
|
|
90
|
+
covered by this License.
|
|
91
|
+
|
|
92
|
+
* **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
93
|
+
document.
|
|
94
|
+
|
|
95
|
+
* **c)** For a Combined Work that displays copyright notices during
|
|
96
|
+
execution, include the copyright notice for the Library among
|
|
97
|
+
these notices, as well as a reference directing the user to the
|
|
98
|
+
copies of the GNU GPL and this license document.
|
|
99
|
+
|
|
100
|
+
* **d)** Do one of the following:
|
|
101
|
+
- **0)** Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
- **1)** Use a suitable shared library mechanism for linking with the
|
|
109
|
+
Library. A suitable mechanism is one that **(a)** uses at run time
|
|
110
|
+
a copy of the Library already present on the user's computer
|
|
111
|
+
system, and **(b)** will operate properly with a modified version
|
|
112
|
+
of the Library that is interface-compatible with the Linked
|
|
113
|
+
Version.
|
|
114
|
+
|
|
115
|
+
* **e)** Provide Installation Information, but only if you would otherwise
|
|
116
|
+
be required to provide such information under section 6 of the
|
|
117
|
+
GNU GPL, and only to the extent that such information is
|
|
118
|
+
necessary to install and execute a modified version of the
|
|
119
|
+
Combined Work produced by recombining or relinking the
|
|
120
|
+
Application with a modified version of the Linked Version. (If
|
|
121
|
+
you use option **4d0**, the Installation Information must accompany
|
|
122
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
123
|
+
Code. If you use option **4d1**, you must provide the Installation
|
|
124
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
125
|
+
for conveying Corresponding Source.)
|
|
126
|
+
|
|
127
|
+
### 5. Combined Libraries
|
|
128
|
+
|
|
129
|
+
You may place library facilities that are a work based on the
|
|
130
|
+
Library side by side in a single library together with other library
|
|
131
|
+
facilities that are not Applications and are not covered by this
|
|
132
|
+
License, and convey such a combined library under terms of your
|
|
133
|
+
choice, if you do both of the following:
|
|
134
|
+
|
|
135
|
+
* **a)** Accompany the combined library with a copy of the same work based
|
|
136
|
+
on the Library, uncombined with any other library facilities,
|
|
137
|
+
conveyed under the terms of this License.
|
|
138
|
+
* **b)** Give prominent notice with the combined library that part of it
|
|
139
|
+
is a work based on the Library, and explaining where to find the
|
|
140
|
+
accompanying uncombined form of the same work.
|
|
141
|
+
|
|
142
|
+
### 6. Revised Versions of the GNU Lesser General Public License
|
|
143
|
+
|
|
144
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
145
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
146
|
+
versions will be similar in spirit to the present version, but may
|
|
147
|
+
differ in detail to address new problems or concerns.
|
|
148
|
+
|
|
149
|
+
Each version is given a distinguishing version number. If the
|
|
150
|
+
Library as you received it specifies that a certain numbered version
|
|
151
|
+
of the GNU Lesser General Public License “or any later version”
|
|
152
|
+
applies to it, you have the option of following the terms and
|
|
153
|
+
conditions either of that published version or of any later version
|
|
154
|
+
published by the Free Software Foundation. If the Library as you
|
|
155
|
+
received it does not specify a version number of the GNU Lesser
|
|
156
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
157
|
+
General Public License ever published by the Free Software Foundation.
|
|
158
|
+
|
|
159
|
+
If the Library as you received it specifies that a proxy can decide
|
|
160
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
161
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
162
|
+
permanent authorization for you to choose that version for the
|
|
163
|
+
Library.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: somestuff-hassstuff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Home Assistant over REST and WebSocket: typed clients plus a CLI for states, registries, helpers, automations, traces and Lovelace dashboards
|
|
5
|
+
Project-URL: Homepage, https://github.com/vroomfondel/somestuff
|
|
6
|
+
Project-URL: Repository, https://github.com/vroomfondel/somestuff
|
|
7
|
+
Project-URL: Issues, https://github.com/vroomfondel/somestuff/issues
|
|
8
|
+
Author-email: Henning Thieß <ht@xomox.cc>
|
|
9
|
+
License-File: LICENSE.md
|
|
10
|
+
Keywords: cli,hass,home-assistant,lovelace,rest,websocket
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Home Automation
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Requires-Dist: httpx>=0.28
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Requires-Dist: typer>=0.27
|
|
24
|
+
Requires-Dist: websockets>=16.0
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# hassstuff
|
|
28
|
+
|
|
29
|
+
Home Assistant over REST **and** WebSocket: thin typed clients (`somestuff.hassstuff.client`) and a CLI
|
|
30
|
+
(`hass-api`, or `python -m somestuff.hassstuff`). The WebSocket API covers what REST does not expose:
|
|
31
|
+
entity/device/area registry, helpers, Lovelace dashboards, traces.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
hass-api --help
|
|
35
|
+
hass-api <command> --help
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Connection
|
|
39
|
+
|
|
40
|
+
| Option | Env | Default |
|
|
41
|
+
|----------------|-------------------|---------------------------------------------------------------------------------------|
|
|
42
|
+
| `--url` | `HASS_URL` | content of `homeassistant_url.local.txt`, otherwise `http://homeassistant.local:8123` |
|
|
43
|
+
| `--token` | `HASS_TOKEN` | – |
|
|
44
|
+
| `--token-file` | `HASS_TOKEN_FILE` | `homeassistant_token.local.txt` |
|
|
45
|
+
| `--insecure` | – | TLS is verified |
|
|
46
|
+
| `--timeout` | – | `30` seconds |
|
|
47
|
+
|
|
48
|
+
Both `*.local.txt` files are searched in the current directory and every parent directory, each also under
|
|
49
|
+
`secrets.local/`. `--token` wins over `--token-file`. Global options go **before** the command:
|
|
50
|
+
`hass-api --url https://… --token abc states`.
|
|
51
|
+
|
|
52
|
+
## Commands
|
|
53
|
+
|
|
54
|
+
| Command | API | Purpose |
|
|
55
|
+
|---------------------------------------------------------|-----------|------------------------------------------------------------|
|
|
56
|
+
| `info` | REST + WS | Version, user, admin flag |
|
|
57
|
+
| `states [PATTERN] [--domain D] [--json]` | REST | States, pattern = substring or glob on ID/name |
|
|
58
|
+
| `state ENTITY [--yaml]` | REST | Full state object |
|
|
59
|
+
| `call DOMAIN.SERVICE [k=v …] [--data JSON]` | REST | Service call, `--return-response` for responses |
|
|
60
|
+
| `template 'JINJA'` | REST | Render a template server-side, `-` = stdin |
|
|
61
|
+
| `history ENTITY … [--hours N] [--attributes]` | REST | State history |
|
|
62
|
+
| `logbook [ENTITY] [--hours N]` | REST | Logbook including trigger (user, service, automation) |
|
|
63
|
+
| `areas` / `devices [PATTERN]` | WS | Areas, devices with area and model |
|
|
64
|
+
| `entities [PATTERN] [--area A] [--platform P]` | WS | Entity registry, area also inherited from the device |
|
|
65
|
+
| `entity-update ENTITY [--name …] [--area …] …` | WS | Name, icon, area, ID, enable/hide, labels |
|
|
66
|
+
| `helper list\|create\|update\|delete TYPE …` | WS | `input_*`, `counter`, `timer`, `schedule` |
|
|
67
|
+
| `automation list\|get\|put\|delete` | REST | UI automations, `put` shows a diff first |
|
|
68
|
+
| `script list\|get\|put\|delete` | REST | UI scripts, as above |
|
|
69
|
+
| `trace list [REF]` / `trace get REF [RUN_ID]` | REST + WS | Run traces, without `RUN_ID` the latest run |
|
|
70
|
+
| `dashboard list\|get [URL_PATH]\|save FILE [URL_PATH]` | WS | Lovelace dashboards in storage mode |
|
|
71
|
+
| `ws TYPE [k=v …] [--data JSON]` | WS | Any WebSocket command |
|
|
72
|
+
|
|
73
|
+
`k=v` values are parsed as JSON where possible (`max=300`, `options='["a","b"]'`), otherwise as text.
|
|
74
|
+
|
|
75
|
+
`REF` for automations/scripts: entity ID (`automation.foo`) **or** config ID. The config ID of an automation
|
|
76
|
+
is its `id` attribute, not the part after `automation.`; `automation list` shows both.
|
|
77
|
+
|
|
78
|
+
## Examples
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
hass-api entities --area Kitchen
|
|
82
|
+
hass-api logbook light.kitchen --hours 2 # who switched it?
|
|
83
|
+
hass-api trace get automation.morning_lights --yaml
|
|
84
|
+
hass-api automation get morning_lights --yaml > /tmp/a.yaml
|
|
85
|
+
hass-api automation put morning_lights /tmp/a.yaml --dry-run
|
|
86
|
+
hass-api helper create input_number name="Target" min=0 max=300 step=5 unit_of_measurement=°C
|
|
87
|
+
hass-api entity-update sensor.foo --area Kitchen --name "Kitchen temperature"
|
|
88
|
+
hass-api call logger.set_level homeassistant.components.mqtt=debug
|
|
89
|
+
hass-api dashboard get my-dashboard --yaml > /tmp/d.yaml
|
|
90
|
+
hass-api dashboard save /tmp/d.yaml my-dashboard --dry-run
|
|
91
|
+
hass-api ws config/label_registry/list
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Library
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from somestuff.hassstuff.client import HassConfig, HassRest, HassWebSocket, default_token_file, default_url, load_token
|
|
98
|
+
|
|
99
|
+
config = HassConfig(url=default_url(), token=load_token(None, default_token_file()))
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Limits
|
|
103
|
+
|
|
104
|
+
- `put`/`save` replace the whole object. First `get`, then edit, then `put` (without `--dry-run`).
|
|
105
|
+
- `delete` asks for confirmation, `--yes` skips it.
|
|
106
|
+
- Helpers created through config flows (template, utility meter, threshold, group …) do not go through
|
|
107
|
+
`helper`, only through `config_entries/flow` (possible via `ws`, but multi-step).
|
|
108
|
+
- YAML dashboards and hand-written automations in `automations.yaml` without `id` are not writable.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# hassstuff
|
|
2
|
+
|
|
3
|
+
Home Assistant over REST **and** WebSocket: thin typed clients (`somestuff.hassstuff.client`) and a CLI
|
|
4
|
+
(`hass-api`, or `python -m somestuff.hassstuff`). The WebSocket API covers what REST does not expose:
|
|
5
|
+
entity/device/area registry, helpers, Lovelace dashboards, traces.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
hass-api --help
|
|
9
|
+
hass-api <command> --help
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Connection
|
|
13
|
+
|
|
14
|
+
| Option | Env | Default |
|
|
15
|
+
|----------------|-------------------|---------------------------------------------------------------------------------------|
|
|
16
|
+
| `--url` | `HASS_URL` | content of `homeassistant_url.local.txt`, otherwise `http://homeassistant.local:8123` |
|
|
17
|
+
| `--token` | `HASS_TOKEN` | – |
|
|
18
|
+
| `--token-file` | `HASS_TOKEN_FILE` | `homeassistant_token.local.txt` |
|
|
19
|
+
| `--insecure` | – | TLS is verified |
|
|
20
|
+
| `--timeout` | – | `30` seconds |
|
|
21
|
+
|
|
22
|
+
Both `*.local.txt` files are searched in the current directory and every parent directory, each also under
|
|
23
|
+
`secrets.local/`. `--token` wins over `--token-file`. Global options go **before** the command:
|
|
24
|
+
`hass-api --url https://… --token abc states`.
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
| Command | API | Purpose |
|
|
29
|
+
|---------------------------------------------------------|-----------|------------------------------------------------------------|
|
|
30
|
+
| `info` | REST + WS | Version, user, admin flag |
|
|
31
|
+
| `states [PATTERN] [--domain D] [--json]` | REST | States, pattern = substring or glob on ID/name |
|
|
32
|
+
| `state ENTITY [--yaml]` | REST | Full state object |
|
|
33
|
+
| `call DOMAIN.SERVICE [k=v …] [--data JSON]` | REST | Service call, `--return-response` for responses |
|
|
34
|
+
| `template 'JINJA'` | REST | Render a template server-side, `-` = stdin |
|
|
35
|
+
| `history ENTITY … [--hours N] [--attributes]` | REST | State history |
|
|
36
|
+
| `logbook [ENTITY] [--hours N]` | REST | Logbook including trigger (user, service, automation) |
|
|
37
|
+
| `areas` / `devices [PATTERN]` | WS | Areas, devices with area and model |
|
|
38
|
+
| `entities [PATTERN] [--area A] [--platform P]` | WS | Entity registry, area also inherited from the device |
|
|
39
|
+
| `entity-update ENTITY [--name …] [--area …] …` | WS | Name, icon, area, ID, enable/hide, labels |
|
|
40
|
+
| `helper list\|create\|update\|delete TYPE …` | WS | `input_*`, `counter`, `timer`, `schedule` |
|
|
41
|
+
| `automation list\|get\|put\|delete` | REST | UI automations, `put` shows a diff first |
|
|
42
|
+
| `script list\|get\|put\|delete` | REST | UI scripts, as above |
|
|
43
|
+
| `trace list [REF]` / `trace get REF [RUN_ID]` | REST + WS | Run traces, without `RUN_ID` the latest run |
|
|
44
|
+
| `dashboard list\|get [URL_PATH]\|save FILE [URL_PATH]` | WS | Lovelace dashboards in storage mode |
|
|
45
|
+
| `ws TYPE [k=v …] [--data JSON]` | WS | Any WebSocket command |
|
|
46
|
+
|
|
47
|
+
`k=v` values are parsed as JSON where possible (`max=300`, `options='["a","b"]'`), otherwise as text.
|
|
48
|
+
|
|
49
|
+
`REF` for automations/scripts: entity ID (`automation.foo`) **or** config ID. The config ID of an automation
|
|
50
|
+
is its `id` attribute, not the part after `automation.`; `automation list` shows both.
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
hass-api entities --area Kitchen
|
|
56
|
+
hass-api logbook light.kitchen --hours 2 # who switched it?
|
|
57
|
+
hass-api trace get automation.morning_lights --yaml
|
|
58
|
+
hass-api automation get morning_lights --yaml > /tmp/a.yaml
|
|
59
|
+
hass-api automation put morning_lights /tmp/a.yaml --dry-run
|
|
60
|
+
hass-api helper create input_number name="Target" min=0 max=300 step=5 unit_of_measurement=°C
|
|
61
|
+
hass-api entity-update sensor.foo --area Kitchen --name "Kitchen temperature"
|
|
62
|
+
hass-api call logger.set_level homeassistant.components.mqtt=debug
|
|
63
|
+
hass-api dashboard get my-dashboard --yaml > /tmp/d.yaml
|
|
64
|
+
hass-api dashboard save /tmp/d.yaml my-dashboard --dry-run
|
|
65
|
+
hass-api ws config/label_registry/list
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Library
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from somestuff.hassstuff.client import HassConfig, HassRest, HassWebSocket, default_token_file, default_url, load_token
|
|
72
|
+
|
|
73
|
+
config = HassConfig(url=default_url(), token=load_token(None, default_token_file()))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Limits
|
|
77
|
+
|
|
78
|
+
- `put`/`save` replace the whole object. First `get`, then edit, then `put` (without `--dry-run`).
|
|
79
|
+
- `delete` asks for confirmation, `--yes` skips it.
|
|
80
|
+
- Helpers created through config flows (template, utility meter, threshold, group …) do not go through
|
|
81
|
+
`helper`, only through `config_entries/flow` (possible via `ws`, but multi-step).
|
|
82
|
+
- YAML dashboards and hand-written automations in `automations.yaml` without `id` are not writable.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "somestuff-hassstuff"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Home Assistant over REST and WebSocket: typed clients plus a CLI for states, registries, helpers, automations, traces and Lovelace dashboards"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.13"
|
|
11
|
+
authors = [{ name = "Henning Thieß", email = "ht@xomox.cc" }]
|
|
12
|
+
license-files = ["LICENSE.md"]
|
|
13
|
+
keywords = ["home-assistant", "hass", "websocket", "rest", "lovelace", "cli"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: System Administrators",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Topic :: Home Automation",
|
|
21
|
+
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
|
|
22
|
+
"Operating System :: POSIX :: Linux",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.28",
|
|
27
|
+
"PyYAML>=6.0",
|
|
28
|
+
"typer>=0.27",
|
|
29
|
+
"websockets>=16.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
hass-api = "somestuff.hassstuff.cli:run"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/vroomfondel/somestuff"
|
|
37
|
+
Repository = "https://github.com/vroomfondel/somestuff"
|
|
38
|
+
Issues = "https://github.com/vroomfondel/somestuff/issues"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.version]
|
|
41
|
+
path = "somestuff/hassstuff/__init__.py"
|
|
42
|
+
|
|
43
|
+
# Build-level selection governs sdist AND wheel; a wheel-only `packages` leaves the sdist unscoped.
|
|
44
|
+
# A target-level `exclude` replaces the build-level list instead of extending it, so each target carries the full set.
|
|
45
|
+
[tool.hatch.build]
|
|
46
|
+
packages = ["somestuff"]
|
|
47
|
+
exclude = ["**/__pycache__", "**/*.pyc", "**/*.local.*", "**/*_deployment.yml", "**/*_cronjob.yml", "**/*.example", "**/*.example.yaml", "**/*.sh"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
exclude = ["**/__pycache__", "**/*.pyc", "**/*.local.*", "**/*_deployment.yml", "**/*_cronjob.yml", "**/*.example", "**/*.example.yaml", "**/*.sh"]
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.wheel]
|
|
53
|
+
exclude = ["**/__pycache__", "**/*.pyc", "**/*.local.*", "**/*_deployment.yml", "**/*_cronjob.yml", "**/*.example", "**/*.example.yaml", "**/*.sh", "**/README.md"]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# hassstuff
|
|
2
|
+
|
|
3
|
+
Home Assistant over REST **and** WebSocket: thin typed clients (`somestuff.hassstuff.client`) and a CLI
|
|
4
|
+
(`hass-api`, or `python -m somestuff.hassstuff`). The WebSocket API covers what REST does not expose:
|
|
5
|
+
entity/device/area registry, helpers, Lovelace dashboards, traces.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
hass-api --help
|
|
9
|
+
hass-api <command> --help
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Connection
|
|
13
|
+
|
|
14
|
+
| Option | Env | Default |
|
|
15
|
+
|----------------|-------------------|---------------------------------------------------------------------------------------|
|
|
16
|
+
| `--url` | `HASS_URL` | content of `homeassistant_url.local.txt`, otherwise `http://homeassistant.local:8123` |
|
|
17
|
+
| `--token` | `HASS_TOKEN` | – |
|
|
18
|
+
| `--token-file` | `HASS_TOKEN_FILE` | `homeassistant_token.local.txt` |
|
|
19
|
+
| `--insecure` | – | TLS is verified |
|
|
20
|
+
| `--timeout` | – | `30` seconds |
|
|
21
|
+
|
|
22
|
+
Both `*.local.txt` files are searched in the current directory and every parent directory, each also under
|
|
23
|
+
`secrets.local/`. `--token` wins over `--token-file`. Global options go **before** the command:
|
|
24
|
+
`hass-api --url https://… --token abc states`.
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
| Command | API | Purpose |
|
|
29
|
+
|---------------------------------------------------------|-----------|------------------------------------------------------------|
|
|
30
|
+
| `info` | REST + WS | Version, user, admin flag |
|
|
31
|
+
| `states [PATTERN] [--domain D] [--json]` | REST | States, pattern = substring or glob on ID/name |
|
|
32
|
+
| `state ENTITY [--yaml]` | REST | Full state object |
|
|
33
|
+
| `call DOMAIN.SERVICE [k=v …] [--data JSON]` | REST | Service call, `--return-response` for responses |
|
|
34
|
+
| `template 'JINJA'` | REST | Render a template server-side, `-` = stdin |
|
|
35
|
+
| `history ENTITY … [--hours N] [--attributes]` | REST | State history |
|
|
36
|
+
| `logbook [ENTITY] [--hours N]` | REST | Logbook including trigger (user, service, automation) |
|
|
37
|
+
| `areas` / `devices [PATTERN]` | WS | Areas, devices with area and model |
|
|
38
|
+
| `entities [PATTERN] [--area A] [--platform P]` | WS | Entity registry, area also inherited from the device |
|
|
39
|
+
| `entity-update ENTITY [--name …] [--area …] …` | WS | Name, icon, area, ID, enable/hide, labels |
|
|
40
|
+
| `helper list\|create\|update\|delete TYPE …` | WS | `input_*`, `counter`, `timer`, `schedule` |
|
|
41
|
+
| `automation list\|get\|put\|delete` | REST | UI automations, `put` shows a diff first |
|
|
42
|
+
| `script list\|get\|put\|delete` | REST | UI scripts, as above |
|
|
43
|
+
| `trace list [REF]` / `trace get REF [RUN_ID]` | REST + WS | Run traces, without `RUN_ID` the latest run |
|
|
44
|
+
| `dashboard list\|get [URL_PATH]\|save FILE [URL_PATH]` | WS | Lovelace dashboards in storage mode |
|
|
45
|
+
| `ws TYPE [k=v …] [--data JSON]` | WS | Any WebSocket command |
|
|
46
|
+
|
|
47
|
+
`k=v` values are parsed as JSON where possible (`max=300`, `options='["a","b"]'`), otherwise as text.
|
|
48
|
+
|
|
49
|
+
`REF` for automations/scripts: entity ID (`automation.foo`) **or** config ID. The config ID of an automation
|
|
50
|
+
is its `id` attribute, not the part after `automation.`; `automation list` shows both.
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
hass-api entities --area Kitchen
|
|
56
|
+
hass-api logbook light.kitchen --hours 2 # who switched it?
|
|
57
|
+
hass-api trace get automation.morning_lights --yaml
|
|
58
|
+
hass-api automation get morning_lights --yaml > /tmp/a.yaml
|
|
59
|
+
hass-api automation put morning_lights /tmp/a.yaml --dry-run
|
|
60
|
+
hass-api helper create input_number name="Target" min=0 max=300 step=5 unit_of_measurement=°C
|
|
61
|
+
hass-api entity-update sensor.foo --area Kitchen --name "Kitchen temperature"
|
|
62
|
+
hass-api call logger.set_level homeassistant.components.mqtt=debug
|
|
63
|
+
hass-api dashboard get my-dashboard --yaml > /tmp/d.yaml
|
|
64
|
+
hass-api dashboard save /tmp/d.yaml my-dashboard --dry-run
|
|
65
|
+
hass-api ws config/label_registry/list
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Library
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from somestuff.hassstuff.client import HassConfig, HassRest, HassWebSocket, default_token_file, default_url, load_token
|
|
72
|
+
|
|
73
|
+
config = HassConfig(url=default_url(), token=load_token(None, default_token_file()))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Limits
|
|
77
|
+
|
|
78
|
+
- `put`/`save` replace the whole object. First `get`, then edit, then `put` (without `--dry-run`).
|
|
79
|
+
- `delete` asks for confirmation, `--yes` skips it.
|
|
80
|
+
- Helpers created through config flows (template, utility meter, threshold, group …) do not go through
|
|
81
|
+
`helper`, only through `config_entries/flow` (possible via `ws`, but multi-step).
|
|
82
|
+
- YAML dashboards and hand-written automations in `automations.yaml` without `id` are not writable.
|