mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
First pass for scripts to rule them all
This commit is contained in:
4
script/bootstrap
Executable file
4
script/bootstrap
Executable file
@ -0,0 +1,4 @@
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
script/bootstrap_server
|
||||
script/bootstrap_frontend
|
5
script/bootstrap_frontend
Executable file
5
script/bootstrap_frontend
Executable file
@ -0,0 +1,5 @@
|
||||
echo "Bootstrapping frontend..."
|
||||
cd homeassistant/components/frontend/www_static/home-assistant-polymer
|
||||
npm install
|
||||
npm run setup_js_dev
|
||||
cd ../../../../..
|
10
script/bootstrap_server
Normal file
10
script/bootstrap_server
Normal file
@ -0,0 +1,10 @@
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "Update the submodule to latest version..."
|
||||
git submodule update
|
||||
|
||||
echo "Installing dependencies..."
|
||||
python3 -m pip install --upgrade -r requirements_all.txt
|
||||
|
||||
echo "Installing development dependencies.."
|
||||
python3 -m pip install --upgrade flake8 pylint coveralls py.test
|
20
script/build_frontend
Executable file
20
script/build_frontend
Executable file
@ -0,0 +1,20 @@
|
||||
# Builds the frontend for production
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
cd homeassistant/components/frontend/www_static/home-assistant-polymer
|
||||
npm run frontend_prod
|
||||
|
||||
cp bower_components/webcomponentsjs/webcomponents-lite.min.js ..
|
||||
cp build/frontend.html ..
|
||||
|
||||
# Generate the MD5 hash of the new frontend
|
||||
cd ../..
|
||||
echo '""" DO NOT MODIFY. Auto-generated by build_frontend script """' > version.py
|
||||
if [ $(command -v md5) ]; then
|
||||
echo 'VERSION = "'`md5 -q www_static/frontend.html`'"' >> version.py
|
||||
elif [ $(command -v md5sum) ]; then
|
||||
echo 'VERSION = "'`md5sum www_static/frontend.html | cut -c-32`'"' >> version.py
|
||||
else
|
||||
echo 'Could not find an MD5 utility'
|
||||
fi
|
27
script/build_python_openzwave
Executable file
27
script/build_python_openzwave
Executable file
@ -0,0 +1,27 @@
|
||||
# Sets up and builds python open zwave to be used with Home Assistant
|
||||
# Dependencies that need to be installed:
|
||||
# apt-get install cython3 libudev-dev python-sphinx python3-setuptools
|
||||
# pip3 install cython
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if [ ! -d build ]; then
|
||||
mkdir build
|
||||
fi
|
||||
|
||||
cd build
|
||||
|
||||
if [ -d python-openzwave ]; then
|
||||
cd python-openzwave
|
||||
git pull --recurse-submodules=yes
|
||||
git submodule update --init --recursive
|
||||
else
|
||||
git clone --recursive https://github.com/balloob/python-openzwave.git
|
||||
cd python-openzwave
|
||||
fi
|
||||
|
||||
# Fix an issue with openzwave
|
||||
sed -i '253s/.*//' openzwave/cpp/src/value_classes/ValueID.h
|
||||
|
||||
./compile.sh --python3
|
||||
./install.sh --python3
|
3
script/cibuild
Executable file
3
script/cibuild
Executable file
@ -0,0 +1,3 @@
|
||||
script/bootstrap_server
|
||||
script/test coverage
|
||||
coveralls
|
28
script/dev_docker
Executable file
28
script/dev_docker
Executable file
@ -0,0 +1,28 @@
|
||||
# Build and run Home Assinstant in Docker
|
||||
|
||||
# Optional: pass in a timezone as first argument
|
||||
# If not given will attempt to mount /etc/localtime
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
docker build -t home-assistant-dev .
|
||||
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
docker run \
|
||||
--net=host \
|
||||
--device=/dev/ttyUSB0:/zwaveusbstick:rwm \
|
||||
-e "TZ=$1" \
|
||||
-v `pwd`:/usr/src/app \
|
||||
-v `pwd`/config:/config \
|
||||
-t -i home-assistant-dev
|
||||
|
||||
else
|
||||
docker run \
|
||||
--net=host \
|
||||
-v /etc/localtime:/etc/localtime:ro \
|
||||
-v `pwd`:/usr/src/app \
|
||||
-v `pwd`/config:/config \
|
||||
-t -i home-assistant-dev
|
||||
|
||||
fi
|
16
script/dev_openzwave_docker
Executable file
16
script/dev_openzwave_docker
Executable file
@ -0,0 +1,16 @@
|
||||
# Open a docker that can be used to debug/dev python-openzwave
|
||||
# Pass in a command line argument to build
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
docker build -t home-assistant-dev .
|
||||
fi
|
||||
|
||||
docker run \
|
||||
--device=/dev/ttyUSB0:/zwaveusbstick:rwm \
|
||||
-v `pwd`:/usr/src/app \
|
||||
-p 8123:8123 \
|
||||
-t -i home-assistant-dev \
|
||||
/bin/bash
|
97
script/get_entities.py
Executable file
97
script/get_entities.py
Executable file
@ -0,0 +1,97 @@
|
||||
#! /usr/bin/python
|
||||
"""
|
||||
Query the Home Assistant API for available entities then print them and any
|
||||
desired attributes to the screen.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import getpass
|
||||
import argparse
|
||||
try:
|
||||
from urllib2 import urlopen
|
||||
PYTHON = 2
|
||||
except ImportError:
|
||||
from urllib.request import urlopen
|
||||
PYTHON = 3
|
||||
import json
|
||||
|
||||
|
||||
def main(password, askpass, attrs, address, port):
|
||||
""" fetch Home Assistant api json page and post process """
|
||||
# ask for password
|
||||
if askpass:
|
||||
password = getpass.getpass('Home Assistant API Password: ')
|
||||
|
||||
# fetch API result
|
||||
url = mk_url(address, port, password)
|
||||
response = urlopen(url).read()
|
||||
if PYTHON == 3:
|
||||
response = response.decode('utf-8')
|
||||
data = json.loads(response)
|
||||
|
||||
# parse data
|
||||
output = {'entity_id': []}
|
||||
output.update([(attr, []) for attr in attrs])
|
||||
for item in data:
|
||||
output['entity_id'].append(item['entity_id'])
|
||||
for attr in attrs:
|
||||
output[attr].append(item['attributes'].get(attr, ''))
|
||||
|
||||
# output data
|
||||
print_table(output, ['entity_id'] + attrs)
|
||||
|
||||
|
||||
def print_table(data, columns):
|
||||
""" format and print a table of data from a dictionary """
|
||||
# get column lengths
|
||||
lengths = {}
|
||||
for key, value in data.items():
|
||||
lengths[key] = max([len(str(val)) for val in value] + [len(key)])
|
||||
|
||||
# print header
|
||||
for item in columns:
|
||||
itemup = item.upper()
|
||||
sys.stdout.write(itemup + ' ' * (lengths[item] - len(item) + 4))
|
||||
sys.stdout.write('\n')
|
||||
|
||||
# print body
|
||||
for ind in range(len(data[columns[0]])):
|
||||
for item in columns:
|
||||
val = str(data[item][ind])
|
||||
sys.stdout.write(val + ' ' * (lengths[item] - len(val) + 4))
|
||||
sys.stdout.write("\n")
|
||||
|
||||
|
||||
def mk_url(address, port, password):
|
||||
""" construct the url call for the api states page """
|
||||
url = ''
|
||||
if address.startswith('http://'):
|
||||
url += address
|
||||
else:
|
||||
url += 'http://' + address
|
||||
url += ':' + port + '/api/states?'
|
||||
if password is not None:
|
||||
url += 'api_password=' + password
|
||||
return url
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
all_options = {'password': None, 'askpass': False, 'attrs': [],
|
||||
'address': 'localhost', 'port': '8123'}
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('attrs', metavar='ATTRIBUTE', type=str, nargs='*',
|
||||
help='an attribute to read from the state')
|
||||
parser.add_argument('--password', dest='password', default=None,
|
||||
type=str, help='API password for the HA server')
|
||||
parser.add_argument('--ask-password', dest='askpass', default=False,
|
||||
action='store_const', const=True,
|
||||
help='prompt for HA API password')
|
||||
parser.add_argument('--addr', dest='address',
|
||||
default='localhost', type=str,
|
||||
help='address of the HA server')
|
||||
parser.add_argument('--port', dest='port', default='8123',
|
||||
type=str, help='port that HA is hosting on')
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args.password, args.askpass, args.attrs, args.address, args.port)
|
101
script/hass-daemon
Executable file
101
script/hass-daemon
Executable file
@ -0,0 +1,101 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: hass
|
||||
# Required-Start: $local_fs $network $named $time $syslog
|
||||
# Required-Stop: $local_fs $network $named $time $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Description: Home\ Assistant
|
||||
### END INIT INFO
|
||||
|
||||
# /etc/init.d Service Script for Home Assistant
|
||||
# Created with: https://gist.github.com/naholyr/4275302#file-new-service-sh
|
||||
#
|
||||
# Installation:
|
||||
# 1) If any commands need to run before executing hass (like loading a
|
||||
# virutal environment), put them in PRE_EXEC. This command must end with
|
||||
# a semicolon.
|
||||
# 2) Set RUN_AS to the username that should be used to execute hass.
|
||||
# 3) Copy this script to /etc/init.d/
|
||||
# sudo cp hass-daemon /etc/init.d/hass-daemon
|
||||
# sudo chmod +x /etc/init.d/hass-daemon
|
||||
# 4) Register the daemon with Linux
|
||||
# sudo update-rc.d hass-daemon defaults
|
||||
# 5) Install this service
|
||||
# sudo service hass-daemon install
|
||||
# 6) Restart Machine
|
||||
#
|
||||
# After installation, HA should start automatically. If HA does not start,
|
||||
# check the log file output for errors.
|
||||
# /var/opt/homeassistant/home-assistant.log
|
||||
|
||||
PRE_EXEC=""
|
||||
RUN_AS="USER"
|
||||
PID_FILE="/var/run/hass.pid"
|
||||
CONFIG_DIR="/var/opt/homeassistant"
|
||||
FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon"
|
||||
|
||||
start() {
|
||||
if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE); then
|
||||
echo 'Service already running' >&2
|
||||
return 1
|
||||
fi
|
||||
echo 'Starting service…' >&2
|
||||
local CMD="$PRE_EXEC hass $FLAGS;"
|
||||
su -c "$CMD" $RUN_AS
|
||||
echo 'Service started' >&2
|
||||
}
|
||||
|
||||
stop() {
|
||||
if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE"); then
|
||||
echo 'Service not running' >&2
|
||||
return 1
|
||||
fi
|
||||
echo 'Stopping service…' >&2
|
||||
kill -3 $(cat "$PID_FILE")
|
||||
echo 'Service stopped' >&2
|
||||
}
|
||||
|
||||
install() {
|
||||
echo "Installing Home Assistant Daemon (hass-daemon)"
|
||||
echo "999999" > $PID_FILE
|
||||
chown $RUN_AS $PID_FILE
|
||||
mkdir -p $CONFIG_DIR
|
||||
chown $RUN_AS $CONFIG_DIR
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
|
||||
local SURE
|
||||
read SURE
|
||||
if [ "$SURE" = "yes" ]; then
|
||||
stop
|
||||
rm -fv "$PID_FILE"
|
||||
echo "Notice: The config directory has not been removed"
|
||||
echo $CONFIG_DIR
|
||||
update-rc.d -f hass-daemon remove
|
||||
rm -fv "$0"
|
||||
echo "Home Assistant Daemon has been removed. Home Assistant is still installed."
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
install)
|
||||
install
|
||||
;;
|
||||
uninstall)
|
||||
uninstall
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|install|uninstall}"
|
||||
esac
|
9
script/lint
Executable file
9
script/lint
Executable file
@ -0,0 +1,9 @@
|
||||
# Run style checks
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "Checking style with flake8..."
|
||||
flake8 homeassistant
|
||||
|
||||
echo "Checking style with pylint..."
|
||||
pylint homeassistant
|
3
script/server
Executable file
3
script/server
Executable file
@ -0,0 +1,3 @@
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
python3 -m homeassistant -c config
|
4
script/setup
Executable file
4
script/setup
Executable file
@ -0,0 +1,4 @@
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
git submodule init
|
||||
script/bootstrap
|
11
script/test
Executable file
11
script/test
Executable file
@ -0,0 +1,11 @@
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "Running tests..."
|
||||
|
||||
if [ "$1" = "coverage" ]; then
|
||||
coverage run -m unittest discover tests
|
||||
else
|
||||
python3 -m unittest discover tests
|
||||
fi
|
||||
|
||||
script/lint
|
4
script/update
Executable file
4
script/update
Executable file
@ -0,0 +1,4 @@
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
git pull
|
||||
git submodule update
|
Reference in New Issue
Block a user