diff --git a/esphomeyaml-edge/README.md b/esphomeyaml-edge/README.md index 3b7093efa1..1fb5d03ea8 100644 --- a/esphomeyaml-edge/README.md +++ b/esphomeyaml-edge/README.md @@ -58,10 +58,15 @@ Example add-on configuration: { "ssl": false, "certfile": "fullchain.pem", - "keyfile": "privkey.pem" + "keyfile": "privkey.pem", + "port": 6052 } ``` +### Option: `port` + +The port to start the dashboard server on. Default is 6052. + ### Option: `ssl` Enables/Disables encrypted SSL (HTTPS) connections to the web server of this add-on. @@ -87,6 +92,15 @@ The private key file to use for SSL. If this file doesn't exist, the add-on star Adding this option to the add-on configuration allows you to disable authentication by setting it to `true`. +### Option: `esphomeyaml_version` + +Manually override which esphomeyaml version to use in the addon. +For example to install the latest development version, use `"esphomeyaml_version": "dev"`, +or for version 1.10.0: `"esphomeyaml_version": "v1.10.0""`. + +Please note that this does not always work and is only meant for testing, usually the +esphomeyaml add-on and dashboard version must match to guarantee a working system. + [discord-shield]: https://img.shields.io/discord/429907082951524364.svg [dht22]: https://esphomelib.com/esphomeyaml/components/sensor/dht.html [discord]: https://discord.me/KhAMKrd diff --git a/esphomeyaml-edge/config.json b/esphomeyaml-edge/config.json index ab5d8eb052..540e13241f 100644 --- a/esphomeyaml-edge/config.json +++ b/esphomeyaml-edge/config.json @@ -18,9 +18,6 @@ "homeassistant_api": false, "host_network": true, "boot": "auto", - "ports": { - "6052/tcp": 6052 - }, "map": [ "ssl", "config:rw" @@ -28,12 +25,15 @@ "options": { "ssl": false, "certfile": "fullchain.pem", - "keyfile": "privkey.pem" + "keyfile": "privkey.pem", + "port": 6052 }, "schema": { "ssl": "bool", "certfile": "str", "keyfile": "str", - "leave_front_door_open": "bool?" + "port": "int", + "leave_front_door_open": "bool?", + "esphomeyaml_version": "str?" } } diff --git a/esphomeyaml-edge/rootfs/etc/cont-init.d/20-nginx.sh b/esphomeyaml-edge/rootfs/etc/cont-init.d/20-nginx.sh index 768fb71bf1..281463b4dc 100755 --- a/esphomeyaml-edge/rootfs/etc/cont-init.d/20-nginx.sh +++ b/esphomeyaml-edge/rootfs/etc/cont-init.d/20-nginx.sh @@ -8,6 +8,7 @@ source /usr/lib/hassio-addons/base.sh declare certfile declare keyfile +declare port mkdir -p /var/log/nginx @@ -22,3 +23,6 @@ if hass.config.true 'ssl'; then sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf fi + +port=$(hass.config.get 'port') +sed -i "s/%%port%%/${port}/g" /etc/nginx/nginx.conf diff --git a/esphomeyaml-edge/rootfs/etc/cont-init.d/30-esphomeyaml.sh b/esphomeyaml-edge/rootfs/etc/cont-init.d/30-esphomeyaml.sh new file mode 100644 index 0000000000..701f16ba28 --- /dev/null +++ b/esphomeyaml-edge/rootfs/etc/cont-init.d/30-esphomeyaml.sh @@ -0,0 +1,14 @@ +#!/usr/bin/with-contenv bash +# ============================================================================== +# Community Hass.io Add-ons: esphomeyaml +# This files installs the user esphomeyaml version if specified +# ============================================================================== +# shellcheck disable=SC1091 +source /usr/lib/hassio-addons/base.sh + +declare esphomeyaml_version + +if hass.config.has_value 'esphomeyaml_version'; then + esphomeyaml_version=$(hass.config.get 'esphomeyaml_version') + pip2 install --no-cache-dir --no-binary :all: "https://github.com/OttoWinter/esphomeyaml/archive/${esphomeyaml_version}.zip" +end diff --git a/esphomeyaml-edge/rootfs/etc/nginx/nginx-ssl.conf b/esphomeyaml-edge/rootfs/etc/nginx/nginx-ssl.conf index 81484f5b6d..1d761595a9 100755 --- a/esphomeyaml-edge/rootfs/etc/nginx/nginx-ssl.conf +++ b/esphomeyaml-edge/rootfs/etc/nginx/nginx-ssl.conf @@ -15,7 +15,7 @@ http { upstream esphomeyaml { ip_hash; - server 127.0.0.1:80; + server unix:/var/run/esphomeyaml.sock; } map $http_upgrade $connection_upgrade { default upgrade; @@ -24,7 +24,7 @@ http { server { server_name hassio.local; - listen 6052 default_server ssl; + listen %%port%% default_server ssl; root /dev/null; ssl_certificate /ssl/%%certfile%%; diff --git a/esphomeyaml-edge/rootfs/etc/nginx/nginx.conf b/esphomeyaml-edge/rootfs/etc/nginx/nginx.conf index 203e1ac035..596fc3e604 100755 --- a/esphomeyaml-edge/rootfs/etc/nginx/nginx.conf +++ b/esphomeyaml-edge/rootfs/etc/nginx/nginx.conf @@ -15,7 +15,7 @@ http { upstream esphomeyaml { ip_hash; - server 127.0.0.1:80; + server unix:/var/run/esphomeyaml.sock; } map $http_upgrade $connection_upgrade { default upgrade; @@ -24,7 +24,7 @@ http { server { server_name hassio.local; - listen 6052 default_server; + listen %%port%% default_server; root /dev/null; location / { diff --git a/esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/run b/esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/run index 47b600d2f4..8f71cd8095 100755 --- a/esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/run +++ b/esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/run @@ -11,4 +11,4 @@ if hass.config.true 'leave_front_door_open'; then fi hass.log.info "Starting esphomeyaml dashboard..." -exec esphomeyaml /config/esphomeyaml dashboard --port 80 --hassio +exec esphomeyaml /config/esphomeyaml dashboard --socket /var/run/esphomeyaml.sock --hassio diff --git a/esphomeyaml/__main__.py b/esphomeyaml/__main__.py index e5c7b6ddb8..30d7072de0 100644 --- a/esphomeyaml/__main__.py +++ b/esphomeyaml/__main__.py @@ -450,6 +450,8 @@ def parse_args(argv): help="Internal flag used to tell esphomeyaml is started as a Hass.io " "add-on.", action="store_true") + dashboard.add_argument("--socket", + help="Make the dashboard serve under a unix socket", type=str) subparsers.add_parser('hass-config', help="Dump the configuration entries that should be added " diff --git a/esphomeyaml/dashboard/dashboard.py b/esphomeyaml/dashboard/dashboard.py index a5cb1e8163..ae9b1518ae 100644 --- a/esphomeyaml/dashboard/dashboard.py +++ b/esphomeyaml/dashboard/dashboard.py @@ -13,6 +13,8 @@ import threading import tornado import tornado.concurrent +import tornado.httpserver +import tornado.netutil import tornado.gen import tornado.ioloop import tornado.iostream @@ -548,15 +550,22 @@ def start_web_server(args): storage.save(path) COOKIE_SECRET = storage.cookie_secret - _LOGGER.info("Starting dashboard web server on port %s and configuration dir %s...", - args.port, CONFIG_DIR) app = make_app(args.verbose) - app.listen(args.port) + if args.socket is not None: + _LOGGER.info("Starting dashboard web server on unix socket %s and configuration dir %s...", + args.socket, CONFIG_DIR) + server = tornado.httpserver.HTTPServer(app) + socket = tornado.netutil.bind_unix_socket(args.socket, mode=0o666) + server.add_socket(socket) + else: + _LOGGER.info("Starting dashboard web server on port %s and configuration dir %s...", + args.port, CONFIG_DIR) + app.listen(args.port) - if args.open_ui: - import webbrowser + if args.open_ui: + import webbrowser - webbrowser.open('localhost:{}'.format(args.port)) + webbrowser.open('localhost:{}'.format(args.port)) ping_thread = PingThread() ping_thread.start() @@ -567,3 +576,5 @@ def start_web_server(args): STOP_EVENT.set() PING_REQUEST.set() ping_thread.join() + if args.socket is not None: + os.remove(args.socket)