Skip to content

Commit e00872b

Browse files
committed
initial docs for readthedocs
1 parent e5588a0 commit e00872b

File tree

10 files changed

+1338
-0
lines changed

10 files changed

+1338
-0
lines changed

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'pyscript'
21+
copyright = '2020, Craig Barratt'
22+
author = 'Craig Barratt'
23+
24+
# The full version, including alpha/beta/rc tags
25+
release = '0.21'
26+
27+
28+
# -- General configuration ---------------------------------------------------
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = [
34+
]
35+
36+
# Add any paths that contain templates here, relative to this directory.
37+
templates_path = ['_templates']
38+
39+
# List of patterns, relative to source directory, that match files and
40+
# directories to ignore when looking for source files.
41+
# This pattern also affects html_static_path and html_extra_path.
42+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
43+
44+
45+
# -- Options for HTML output -------------------------------------------------
46+
47+
# The theme to use for HTML and HTML Help pages. See the documentation for
48+
# a list of builtin themes.
49+
#
50+
html_theme = 'alabaster'
51+
52+
# Add any paths that contain custom static files (such as style sheets) here,
53+
# relative to this directory. They are copied after the builtin static files,
54+
# so a file named "default.css" will overwrite the builtin "default.css".
55+
html_static_path = ['_static']

docs/configuration.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Configuration
2+
=============
3+
4+
- Add ``pyscript:`` to ``<config>/configuration.yaml``; pyscript has
5+
one optional configuration parameter that allows any python package
6+
to be imported if set, eg:
7+
8+
.. code:: yaml
9+
10+
pyscript:
11+
allow_all_imports: true
12+
13+
- Create the folder ``<config>/pyscript``
14+
- Add files with a suffix of ``.py`` in the folder ``<config>/pyscript``.
15+
- Restart HASS.
16+
- Whenever you change a script file, make a ``reload`` service call to ``pyscript``.
17+
- Watch the HASS log for ``pyscript`` errors and logger output from your scripts.

docs/contributing.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Contributing
2+
============
3+
4+
Contributions are welcome! You are encouraged to submit PRs, bug
5+
reports, feature requests or add to the Wiki with examples and
6+
tutorials. It would be fun to hear about unique and clever applications
7+
you develop. Please see this
8+
`README <https://github.com/custom-components/pyscript/tree/master/tests>`__
9+
for setting up a development environment and running tests.

docs/index.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Pyscript: Python Scripting for Home Assistant
2+
=============================================
3+
4+
|GitHub Release| |License| |hacs| |Project Maintenance|
5+
6+
Overview
7+
--------
8+
9+
This HACS custom integration allows you to write Python functions and
10+
scripts that can implement a wide range of automation, logic and
11+
triggers. State variables are bound to Python variables and services are
12+
callable as Python functions, so it’s easy and concise to implement
13+
logic.
14+
15+
Functions you write can be configured to be called as a service or run
16+
upon time, state-change or event triggers. Functions can also call any
17+
service, fire events and set state variables. Functions can sleep or
18+
wait for additional changes in state variables or events, without
19+
slowing or affecting other operations. You can think of these functions
20+
as small programs that run in parallel, independently of each other, and
21+
they could be active for extended periods of time.
22+
23+
State, event and time triggers are specified by Python function
24+
decorators (the “@” lines immediately before each function definition).
25+
A state trigger can be any Python expression using state variables - the
26+
trigger is evaluated only when a state variable it references changes,
27+
and the trigger occurs when the expression is true or non-zero. A time
28+
trigger could be a single event (eg: date and time), a repetitive event
29+
(eg: at a particular time each day or weekday, daily relative to sunrise
30+
or sunset or any regular time period within an optional range) or using
31+
cron syntax (where events occur periodically based on a concise
32+
specification of ranges of minutes, hours, days of week, days of month
33+
and months). An event trigger specifies the event type, and an optional
34+
Python trigger test based on the event data that runs the Python
35+
function if true.
36+
37+
Pyscript implements a Python interpreter using the ast parser output, in
38+
a fully async manner. That allows several of the “magic” features to be
39+
implemented in a seamless Pythonic manner, such as binding of variables
40+
to states and functions to services. Pyscript supports imports, although
41+
by default the valid import list is restricted for security reasons
42+
(there is a configuration option ``allow_all_imports`` to allow all
43+
imports). Pyscript supports all language features except generators and
44+
``yield``. Pyscript provides a handful of additional built-in functions
45+
that connect to HASS features, like logging, accessing state variables
46+
as strings (if you need to compute their names dynamically), sleeping
47+
and waiting for triggers.
48+
49+
Pyscript also provides a kernel that interfaces with the Jupyter
50+
front-ends (eg, notebook, console and lab). That allows you to develop
51+
and test pyscript code interactively. Plus you can interact with much of
52+
HASS by looking at state variables, calling services etc, in a similar
53+
way to `HASS
54+
CLI <https://github.com/home-assistant-ecosystem/home-assistant-cli>`__,
55+
although the CLI provides status on many other parts of HASS.
56+
57+
For more information about the Jupyter kernel, see the
58+
`README <https://github.com/craigbarratt/hass-pyscript-jupyter/blob/master/README.md>`__.
59+
There is also a `Jupyter notebook
60+
tutorial <https://nbviewer.jupyter.org/github/craigbarratt/hass-pyscript-jupyter/blob/master/pyscript_tutorial.ipynb>`__,
61+
which can be downloaded and run interactively in Jupyter notebook
62+
connected to your live HASS with pyscript.
63+
64+
Pyscript provides functionality that complements the existing
65+
automations, templates and triggers. Pyscript is most similar to
66+
`AppDaemon <https://appdaemon.readthedocs.io/en/latest/>`__, and some
67+
similarities and differences are discussed in this `Wiki
68+
page <https://github.com/custom-components/pyscript/wiki/Comparing-Pyscript-to-AppDaemon>`__.
69+
Pyscript with Jupyter makes it extremely easy to learn, use and debug.
70+
Pyscripts presents a simplified and more integrated binding for Python
71+
scripting than `Python
72+
Scripts <https://www.home-assistant.io/integrations/python_script>`__,
73+
which requires a lot more expertise and scaffolding using direct access
74+
to Home Assistant internals.
75+
76+
Contents
77+
~~~~~~~~
78+
79+
.. toctree::
80+
:maxdepth: 3
81+
82+
installation
83+
configuration
84+
tutorial
85+
reference
86+
contributing
87+
useful_links
88+
89+
.. |GitHub Release| image:: https://img.shields.io/github/release/custom-components/pyscript.svg?style=for-the-badge
90+
:target: https://github.com/custom-components/pyscript/releases
91+
.. |License| image:: https://img.shields.io/github/license/custom-components/pyscript.svg?style=for-the-badge
92+
:target: https://github.com/custom-components/pyscript/blob/master/LICENSE
93+
.. |hacs| image:: https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge
94+
:target: https://github.com/custom-components/hacs
95+
.. |Project Maintenance| image:: https://img.shields.io/badge/maintainer-%40craigbarratt-blue.svg?style=for-the-badge
96+
:target: https://github.com/craigbarratt

docs/installation.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Installation
2+
============
3+
4+
Option 1: HACS
5+
--------------
6+
7+
Under HACS -> Integrations, select “+”, search for ``pyscript`` and
8+
install it.
9+
10+
Option 2: Manual
11+
----------------
12+
13+
From the `latest
14+
release <https://github.com/custom-components/pyscript/releases>`__
15+
download the zip file ``hass-custom-pyscript.zip``
16+
17+
.. code:: bash
18+
19+
cd YOUR_HASS_CONFIG_DIRECTORY # same place as configuration.yaml
20+
mkdir -p custom_components/pyscript
21+
cd custom_components/pyscript
22+
unzip hass-custom-pyscript.zip
23+
24+
Alternatively, you can install the current GitHub master version by
25+
cloning and copying:
26+
27+
.. code:: bash
28+
29+
mkdir SOME_LOCAL_WORKSPACE
30+
cd SOME_LOCAL_WORKSPACE
31+
git clone https://github.com/custom-components/pyscript.git
32+
mkdir -p YOUR_HASS_CONFIG_DIRECTORY/custom_components
33+
cp -pr pyscript/custom_components/pyscript YOUR_HASS_CONFIG_DIRECTORY/custom_components
34+
35+
Install Jupyter Kernel
36+
----------------------
37+
38+
Installing the Pyscript Jupyter kernel is optional but highly recommended.
39+
The steps to install and use it are in this
40+
`README <https://github.com/craigbarratt/hass-pyscript-jupyter/blob/master/README.md>`__.

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

0 commit comments

Comments
 (0)