mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 01:48:54 +02:00
[Huge] Util Refactor, Dashboard Improvements, Hass.io Auth API, Better Validation Errors, Conditions, Custom Platforms, Substitutions (#234)
* Implement custom sensor platform
* Update
* Ethernet
* Lint
* Fix
* Login page
* Rename cookie secret
* Update manifest
* Update cookie check logic
* Favicon
* Fix
* Favicon manifest
* Fix
* Fix
* Fix
* Use hostname
* Message
* Temporary commit for screenshot
* Automatic board selection
* Undo temporary commit
* Update esphomeyaml-edge
* In-dashboard editing and hosting files locally
* Update esphomeyaml-edge
* Better ANSI color escaping
* Message
* Lint
* Download Efficiency
* Fix gitlab
* Fix
* Rename extra_libraries to libraries
* Add example
* Update README.md
* Update README.md
* Update README.md
* HassIO -> Hass.io
* Updates
* Add update available notice
* Update
* Fix substitutions
* Better error message
* Re-do dashboard ANSI colors
* Only include FastLED if user says so
* Autoscroll logs
* Remove old checks
* Use safer RedirectText
* Improvements
* Fix
* Use enviornment variable
* Use http://hassio/host/info
* Fix conditions
* Update platformio versions
* Revert "Use enviornment variable"
This reverts commit 7f038eb5d2.
* Fix
* README update
* Temp
* Better invalid config messages
* Platformio debug
* Improve error messages
* Debug
* Remove debug
* Multi Conf
* Update
* Better paths
* Remove unused
* Fixes
* Lint
* lib_ignore
* Try fix platformio colors
* Fix dashboard scrolling
* Revert
* Lint
* Revert
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -105,3 +105,4 @@ venv.bak/
|
||||
|
||||
config/
|
||||
tests/build/
|
||||
tests/.esphomeyaml/
|
||||
|
||||
@@ -11,6 +11,8 @@ stages:
|
||||
|
||||
.lint: &lint
|
||||
stage: lint
|
||||
before_script:
|
||||
- pip install -e .
|
||||
tags:
|
||||
- python2.7
|
||||
- esphomeyaml-lint
|
||||
@@ -24,9 +26,6 @@ stages:
|
||||
- esphomeyaml-test
|
||||
variables:
|
||||
TZ: UTC
|
||||
cache:
|
||||
paths:
|
||||
- tests/build
|
||||
|
||||
.docker-builder: &docker-builder
|
||||
before_script:
|
||||
@@ -62,21 +61,20 @@ test2:
|
||||
stage: build
|
||||
script:
|
||||
- docker run --rm --privileged hassioaddons/qemu-user-static:latest
|
||||
- BUILD_FROM=homeassistant/${ADDON_ARCH}-base-ubuntu:latest
|
||||
- BUILD_FROM=hassioaddons/ubuntu-base-${ADDON_ARCH}:2.2.0
|
||||
- ADDON_VERSION="${CI_COMMIT_TAG#v}"
|
||||
- ADDON_VERSION="${ADDON_VERSION:-${CI_COMMIT_SHA:0:7}}"
|
||||
- ESPHOMELIB_VERSION="${ESPHOMELIB_VERSION:-''}"
|
||||
- echo "Build from ${BUILD_FROM}"
|
||||
- echo "Add-on version ${ADDON_VERSION}"
|
||||
- echo "Esphomelib version ${ESPHOMELIB_VERSION}"
|
||||
- echo "Tag ${CI_REGISTRY}/esphomeyaml-hassio-${ADDON_ARCH}:dev"
|
||||
- echo "Tag ${CI_REGISTRY}/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}"
|
||||
- |
|
||||
docker build \
|
||||
--build-arg "BUILD_FROM=${BUILD_FROM}" \
|
||||
--build-arg "ADDON_ARCH=${ADDON_ARCH}" \
|
||||
--build-arg "ADDON_VERSION=${ADDON_VERSION}" \
|
||||
--build-arg "ESPHOMELIB_VERSION=${ESPHOMELIB_VERSION}" \
|
||||
--build-arg "BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ")" \
|
||||
--build-arg "BUILD_ARCH=${ADDON_ARCH}" \
|
||||
--build-arg "BUILD_REF=${CI_COMMIT_SHA}" \
|
||||
--build-arg "BUILD_VERSION=${ADDON_VERSION}" \
|
||||
--tag "${CI_REGISTRY}/esphomeyaml-hassio-${ADDON_ARCH}:dev" \
|
||||
--tag "${CI_REGISTRY}/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
|
||||
--file "docker/Dockerfile.hassio" \
|
||||
@@ -209,31 +207,28 @@ build:hassio-armhf-edge:
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
DO_PUSH: "false"
|
||||
ESPHOMELIB_VERSION: "${CI_COMMIT_TAG}"
|
||||
|
||||
build:hassio-armhf:
|
||||
<<: *build-hassio-release
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
|
||||
build:hassio-aarch64-edge:
|
||||
<<: *build-hassio-edge
|
||||
variables:
|
||||
ADDON_ARCH: aarch64
|
||||
DO_PUSH: "false"
|
||||
ESPHOMELIB_VERSION: "${CI_COMMIT_TAG}"
|
||||
#build:hassio-aarch64-edge:
|
||||
# <<: *build-hassio-edge
|
||||
# variables:
|
||||
# ADDON_ARCH: aarch64
|
||||
# DO_PUSH: "false"
|
||||
|
||||
build:hassio-aarch64:
|
||||
<<: *build-hassio-release
|
||||
variables:
|
||||
ADDON_ARCH: aarch64
|
||||
#build:hassio-aarch64:
|
||||
# <<: *build-hassio-release
|
||||
# variables:
|
||||
# ADDON_ARCH: aarch64
|
||||
|
||||
build:hassio-i386-edge:
|
||||
<<: *build-hassio-edge
|
||||
variables:
|
||||
ADDON_ARCH: i386
|
||||
DO_PUSH: "false"
|
||||
ESPHOMELIB_VERSION: "${CI_COMMIT_TAG}"
|
||||
|
||||
build:hassio-i386:
|
||||
<<: *build-hassio-release
|
||||
@@ -245,7 +240,6 @@ build:hassio-amd64-edge:
|
||||
variables:
|
||||
ADDON_ARCH: amd64
|
||||
DO_PUSH: "false"
|
||||
ESPHOMELIB_VERSION: "${CI_COMMIT_TAG}"
|
||||
|
||||
build:hassio-amd64:
|
||||
<<: *build-hassio-release
|
||||
@@ -263,15 +257,15 @@ deploy-beta:armhf:
|
||||
variables:
|
||||
ADDON_ARCH: armhf
|
||||
|
||||
deploy-release:aarch64:
|
||||
<<: *deploy-release
|
||||
variables:
|
||||
ADDON_ARCH: aarch64
|
||||
#deploy-release:aarch64:
|
||||
# <<: *deploy-release
|
||||
# variables:
|
||||
# ADDON_ARCH: aarch64
|
||||
|
||||
deploy-beta:aarch64:
|
||||
<<: *deploy-beta
|
||||
variables:
|
||||
ADDON_ARCH: aarch64
|
||||
#deploy-beta:aarch64:
|
||||
# <<: *deploy-beta
|
||||
# variables:
|
||||
# ADDON_ARCH: aarch64
|
||||
|
||||
deploy-release:i386:
|
||||
<<: *deploy-release
|
||||
|
||||
12
MANIFEST.in
12
MANIFEST.in
@@ -1,4 +1,16 @@
|
||||
include README.md
|
||||
include esphomeyaml/dashboard/templates/index.html
|
||||
include esphomeyaml/dashboard/templates/login.html
|
||||
include esphomeyaml/dashboard/static/ace.js
|
||||
include esphomeyaml/dashboard/static/esphomeyaml.css
|
||||
include esphomeyaml/dashboard/static/esphomeyaml.js
|
||||
include esphomeyaml/dashboard/static/favicon.ico
|
||||
include esphomeyaml/dashboard/static/jquery.min.js
|
||||
include esphomeyaml/dashboard/static/jquery.validate.min.js
|
||||
include esphomeyaml/dashboard/static/jquery-ui.min.js
|
||||
include esphomeyaml/dashboard/static/materialize.min.css
|
||||
include esphomeyaml/dashboard/static/materialize.min.js
|
||||
include esphomeyaml/dashboard/static/materialize-stepper.min.css
|
||||
include esphomeyaml/dashboard/static/materialize-stepper.min.js
|
||||
include esphomeyaml/dashboard/static/mode-yaml.js
|
||||
include esphomeyaml/dashboard/static/theme-dreamweaver.js
|
||||
|
||||
@@ -1,40 +1,78 @@
|
||||
# Dockerfile for HassIO add-on
|
||||
ARG BUILD_FROM=homeassistant/amd64-base-ubuntu:latest
|
||||
ARG BUILD_FROM=hassioaddons/ubuntu-base:2.2.0
|
||||
# hadolint ignore=DL3006
|
||||
FROM ${BUILD_FROM}
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
# Set shell
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
# Copy root filesystem
|
||||
COPY esphomeyaml-edge/rootfs /
|
||||
COPY setup.py setup.cfg MANIFEST.in /opt/esphomeyaml/
|
||||
COPY esphomeyaml /opt/esphomeyaml/esphomeyaml
|
||||
|
||||
RUN \
|
||||
# Temporarily move nginx.conf (otherwise dpkg fails)
|
||||
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bkp \
|
||||
# Install add-on dependencies
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
# Python for esphomeyaml
|
||||
python \
|
||||
python-pip \
|
||||
python-setuptools \
|
||||
# Python Pillow for display component
|
||||
python-pil \
|
||||
# Git for esphomelib downloads
|
||||
git \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* && \
|
||||
pip install --no-cache-dir --no-binary :all: platformio && \
|
||||
platformio settings set enable_telemetry No && \
|
||||
platformio settings set check_libraries_interval 1000000 && \
|
||||
platformio settings set check_platformio_interval 1000000 && \
|
||||
platformio settings set check_platforms_interval 1000000
|
||||
|
||||
COPY docker/platformio.ini /pio/platformio.ini
|
||||
RUN platformio run -d /pio; rm -rf /pio
|
||||
|
||||
|
||||
COPY . .
|
||||
RUN pip install --no-cache-dir --no-binary :all: -e . && \
|
||||
pip install --no-cache-dir --no-binary :all: tzlocal
|
||||
|
||||
CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"]
|
||||
# Ping for dashboard online/offline status
|
||||
iputils-ping \
|
||||
# NGINX proxy
|
||||
nginx \
|
||||
\
|
||||
&& mv /etc/nginx/nginx.conf.bkp /etc/nginx/nginx.conf \
|
||||
\
|
||||
&& pip2 install --no-cache-dir --no-binary :all: -e /opt/esphomeyaml \
|
||||
\
|
||||
# tzlocal for automatic timezone detection
|
||||
&& pip2 install --no-cache-dir --no-binary :all: tzlocal \
|
||||
\
|
||||
# Change some platformio settings
|
||||
&& platformio settings set enable_telemetry No \
|
||||
&& platformio settings set check_libraries_interval 1000000 \
|
||||
&& platformio settings set check_platformio_interval 1000000 \
|
||||
&& platformio settings set check_platforms_interval 1000000 \
|
||||
\
|
||||
# Build an empty platformio project to force platformio to install all fw build dependencies
|
||||
# The return-code will be non-zero since there's nothing to build.
|
||||
&& (platformio run -d /opt/pio; echo "Done") \
|
||||
\
|
||||
# Cleanup
|
||||
&& rm -fr \
|
||||
/tmp/* \
|
||||
/var/{cache,log}/* \
|
||||
/var/lib/apt/lists/* \
|
||||
/opt/pio/
|
||||
|
||||
# Build arugments
|
||||
ARG ADDON_ARCH
|
||||
ARG ADDON_VERSION
|
||||
ARG BUILD_ARCH=amd64
|
||||
ARG BUILD_DATE
|
||||
ARG BUILD_REF
|
||||
ARG BUILD_VERSION
|
||||
|
||||
# Labels
|
||||
LABEL \
|
||||
io.hass.name="esphomeyaml" \
|
||||
io.hass.description="esphomeyaml HassIO add-on for intelligently managing all your ESP8266/ESP32 devices." \
|
||||
io.hass.arch="${ADDON_ARCH}" \
|
||||
io.hass.description="Manage and program ESP8266/ESP32 microcontrollers through YAML configuration files" \
|
||||
io.hass.arch="${BUILD_ARCH}" \
|
||||
io.hass.type="addon" \
|
||||
io.hass.version="${ADDON_VERSION}" \
|
||||
io.hass.url="https://esphomelib.com/esphomeyaml/index.html" \
|
||||
maintainer="Otto Winter <contact@otto-winter.com>"
|
||||
io.hass.version=${BUILD_VERSION} \
|
||||
maintainer="Otto Winter <contact@otto-winter.com>" \
|
||||
org.label-schema.description="Manage and program ESP8266/ESP32 microcontrollers through YAML configuration files" \
|
||||
org.label-schema.build-date=${BUILD_DATE} \
|
||||
org.label-schema.name="esphomeyaml" \
|
||||
org.label-schema.schema-version="1.0" \
|
||||
org.label-schema.url="https://esphomelib.com" \
|
||||
org.label-schema.usage="https://github.com/OttoWinter/esphomeyaml/tree/dev/esphomeyaml/README.md" \
|
||||
org.label-schema.vcs-ref=${BUILD_REF} \
|
||||
org.label-schema.vcs-url="https://github.com/OttoWinter/esphomeyaml" \
|
||||
org.label-schema.vendor="esphomelib"
|
||||
|
||||
@@ -8,7 +8,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \
|
||||
pip install --no-cache-dir --no-binary :all: platformio && \
|
||||
platformio settings set enable_telemetry No
|
||||
platformio settings set enable_telemetry No && \
|
||||
platformio settings set check_libraries_interval 1000000 && \
|
||||
platformio settings set check_platformio_interval 1000000 && \
|
||||
platformio settings set check_platforms_interval 1000000
|
||||
|
||||
COPY docker/platformio.ini /pio/platformio.ini
|
||||
RUN platformio run -d /pio; rm -rf /pio
|
||||
@@ -16,4 +19,4 @@ RUN platformio run -d /pio; rm -rf /pio
|
||||
COPY requirements.txt /requirements.txt
|
||||
|
||||
RUN pip install --no-cache-dir -r /requirements.txt && \
|
||||
pip install --no-cache-dir tzlocal pillow
|
||||
pip install --no-cache-dir tzlocal
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "esphomeyaml-beta",
|
||||
"version": "1.9.3",
|
||||
"slug": "esphomeyaml-beta",
|
||||
"description": "Beta version of esphomeyaml HassIO add-on.",
|
||||
"description": "Beta version of esphomeyaml Hass.io add-on.",
|
||||
"url": "https://beta.esphomelib.com/esphomeyaml/index.html",
|
||||
"startup": "application",
|
||||
"webui": "http://[HOST]:[PORT:6052]",
|
||||
|
||||
@@ -1,24 +1,76 @@
|
||||
# Dockerfile for HassIO edge add-on
|
||||
ARG BUILD_FROM=homeassistant/amd64-base-ubuntu:latest
|
||||
ARG BUILD_FROM=hassioaddons/ubuntu-base:2.2.0
|
||||
# hadolint ignore=DL3006
|
||||
FROM ${BUILD_FROM}
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
# Set shell
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
# Copy root filesystem
|
||||
COPY rootfs /
|
||||
|
||||
RUN \
|
||||
# Temporarily move nginx.conf (otherwise dpkg fails)
|
||||
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bkp \
|
||||
# Install add-on dependencies
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
# Python for esphomeyaml
|
||||
python \
|
||||
python-pip \
|
||||
python-setuptools \
|
||||
# Python Pillow for display component
|
||||
python-pil \
|
||||
# Git for esphomelib downloads
|
||||
git \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* && \
|
||||
pip install --no-cache-dir --no-binary :all: platformio && \
|
||||
platformio settings set enable_telemetry No && \
|
||||
platformio settings set check_libraries_interval 1000000 && \
|
||||
platformio settings set check_platformio_interval 1000000 && \
|
||||
platformio settings set check_platforms_interval 1000000
|
||||
# Ping for dashboard online/offline status
|
||||
iputils-ping \
|
||||
# NGINX proxy
|
||||
nginx \
|
||||
\
|
||||
&& mv /etc/nginx/nginx.conf.bkp /etc/nginx/nginx.conf \
|
||||
\
|
||||
&& pip2 install --no-cache-dir --no-binary :all: https://github.com/OttoWinter/esphomeyaml/archive/dev.zip \
|
||||
\
|
||||
# tzlocal for automatic timezone detection
|
||||
&& pip2 install --no-cache-dir --no-binary :all: tzlocal \
|
||||
\
|
||||
# Change some platformio settings
|
||||
&& platformio settings set enable_telemetry No \
|
||||
&& platformio settings set check_libraries_interval 1000000 \
|
||||
&& platformio settings set check_platformio_interval 1000000 \
|
||||
&& platformio settings set check_platforms_interval 1000000 \
|
||||
\
|
||||
# Build an empty platformio project to force platformio to install all fw build dependencies
|
||||
# The return-code will be non-zero since there's nothing to build.
|
||||
&& (platformio run -d /opt/pio; echo "Done") \
|
||||
\
|
||||
# Cleanup
|
||||
&& rm -fr \
|
||||
/tmp/* \
|
||||
/var/{cache,log}/* \
|
||||
/var/lib/apt/lists/* \
|
||||
/opt/pio/
|
||||
|
||||
COPY platformio.ini /pio/platformio.ini
|
||||
RUN platformio run -d /pio; rm -rf /pio
|
||||
# Build arugments
|
||||
ARG BUILD_ARCH=amd64
|
||||
ARG BUILD_DATE
|
||||
ARG BUILD_REF
|
||||
ARG BUILD_VERSION
|
||||
|
||||
RUN pip install --no-cache-dir git+https://github.com/OttoWinter/esphomeyaml.git@dev#egg=esphomeyaml && \
|
||||
pip install --no-cache-dir pillow tzlocal
|
||||
|
||||
CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"]
|
||||
# Labels
|
||||
LABEL \
|
||||
io.hass.name="esphomeyaml-edge" \
|
||||
io.hass.description="Manage and program ESP8266/ESP32 microcontrollers through YAML configuration files" \
|
||||
io.hass.arch="${BUILD_ARCH}" \
|
||||
io.hass.type="addon" \
|
||||
io.hass.version=${BUILD_VERSION} \
|
||||
maintainer="Otto Winter <contact@otto-winter.com>" \
|
||||
org.label-schema.description="Manage and program ESP8266/ESP32 microcontrollers through YAML configuration files" \
|
||||
org.label-schema.build-date=${BUILD_DATE} \
|
||||
org.label-schema.name="esphomeyaml-edge" \
|
||||
org.label-schema.schema-version="1.0" \
|
||||
org.label-schema.url="https://esphomelib.com" \
|
||||
org.label-schema.usage="https://github.com/OttoWinter/esphomeyaml/tree/dev/esphomeyaml-edge/README.md" \
|
||||
org.label-schema.vcs-ref=${BUILD_REF} \
|
||||
org.label-schema.vcs-url="https://github.com/OttoWinter/esphomeyaml" \
|
||||
org.label-schema.vendor="esphomelib"
|
||||
|
||||
123
esphomeyaml-edge/README.md
Normal file
123
esphomeyaml-edge/README.md
Normal file
@@ -0,0 +1,123 @@
|
||||
# Esphomeyaml Hass.io Add-On
|
||||
|
||||
[![GitHub Release][releases-shield]][releases]
|
||||
![Project Stage][project-stage-shield]
|
||||
[![License][license-shield]](LICENSE.md)
|
||||
|
||||
[![GitLab CI][gitlabci-shield]][gitlabci]
|
||||
![Project Maintenance][maintenance-shield]
|
||||
[![GitHub Activity][commits-shield]][commits]
|
||||
|
||||
[![Discord][discord-shield]][discord]
|
||||
[![Community Forum][forum-shield]][forum]
|
||||
|
||||
[](https://esphomelib.com/esphomeyaml/index.html)
|
||||
|
||||
## About
|
||||
|
||||
This add-on allows you to manage and program your ESP8266 and ESP32 based microcontrollers
|
||||
directly through Hass.io **with no programming experience required**. All you need to do
|
||||
is write YAML configuration files; the rest (over-the-air updates, compiling) is all
|
||||
handled by esphomeyaml.
|
||||
|
||||
<p align="center">
|
||||
<img title="esphomeyaml dashboard screenshot" src="images/screenshot.png" width="700px"></img>
|
||||
</p>
|
||||
|
||||
[_View the esphomeyaml documentation here_](https://esphomelib.com/esphomeyaml/index.html)
|
||||
|
||||
## Example
|
||||
|
||||
With esphomeyaml, you can go from a few lines of YAML straight to a custom-made
|
||||
firmware. For example, to include a [DHT22][dht22].
|
||||
temperature and humidity sensor, you just need to include 8 lines of YAML
|
||||
in your configuration file:
|
||||
|
||||
<img title="esphomeyaml DHT configuration example" src="images/dht-example.png" width="500px"></img>
|
||||
|
||||
Then just click UPLOAD and the sensor will magically appear in Home Assistant:
|
||||
|
||||
<img title="esphomelib Home Assistant MQTT discovery" src="images/temperature-humidity.png" width="600px"></img>
|
||||
|
||||
## Installation
|
||||
|
||||
To install this Hass.io add-on you need to add the esphomeyaml add-on repository
|
||||
first:
|
||||
|
||||
1. Add our Hass.io add-ons repository to your Hass.io instance. You can do this by navigating to the "Add-on Store" tab in the Hass.io panel and then entering https://github.com/hassio-addons/repository in the "Add new repository by URL" field.
|
||||
2. Now scroll down and select the "esphomeyaml" add-on.
|
||||
3. Press install to download the add-on and unpack it on your machine. This can take some time.
|
||||
4. Optional: If you're using SSL certificates and want to encrypt your communication to this add-on, please enter `true` into the `ssl` field and set the `fullchain` and `certfile` options accordingly.
|
||||
5. Start the add-on, check the logs of the add-on to see if everything went well.
|
||||
6. Click "OPEN WEB UI" to open the esphomeyaml dashboard. You will be asked for your Home Assistant credentials - esphomeyaml uses Hass.io's authentication system to log you in.
|
||||
|
||||
**NOTE**: Installation on RPis running in 64-bit mode is currently not possible. Please use the 32-bit variant of HassOS instead.
|
||||
|
||||
You can view the esphomeyaml docs here: https://esphomelib.com/esphomeyaml/index.html
|
||||
|
||||
## Configuration
|
||||
|
||||
**Note**: _Remember to restart the add-on when the configuration is changed._
|
||||
|
||||
Example add-on configuration:
|
||||
|
||||
```json
|
||||
{
|
||||
"ssl": true,
|
||||
"certfile": "fullchain.pem",
|
||||
"keyfile": "privkey.pem"
|
||||
}
|
||||
```
|
||||
|
||||
### Option: `ssl`
|
||||
|
||||
Enables/Disables encrypted SSL (HTTPS) connections to the web server of this add-on. Set it to `true` to encrypt communications, `false` otherwise. Please note that if you set this to `true` you must also specify a `certfile` and `keyfile`.
|
||||
|
||||
### Option: `certfile`
|
||||
|
||||
The certificate file to use for SSL.
|
||||
|
||||
**Note**: _The file MUST be stored in `/ssl/`, which is the default for Hass.io_
|
||||
|
||||
### Option: `keyfile`
|
||||
|
||||
The private key file to use for SSL.
|
||||
|
||||
**Note**: _The file MUST be stored in `/ssl/`, which is the default for Hass.io_
|
||||
|
||||
### Option: `leave_front_door_open`
|
||||
|
||||
Adding this option to the add-on configuration allows you to disable
|
||||
authentication by setting it to `true`.
|
||||
|
||||
## Embedding into Home Assistant
|
||||
|
||||
It is possible to embed the esphomeyaml dashboard directly into
|
||||
Home Assistant, allowing you to access your ESP nodes through
|
||||
the Home Assistant frontend using the `panel_iframe` component.
|
||||
|
||||
Example configuration:
|
||||
|
||||
```yaml
|
||||
panel_iframe:
|
||||
esphomeyaml:
|
||||
title: esphomeyaml Dashboard
|
||||
icon: mdi:code-brackets
|
||||
url: https://addres.to.your.hass.io:6052
|
||||
```
|
||||
|
||||
[commits-shield]: https://img.shields.io/github/commit-activity/y/hassio-addons/addon-esphomeyaml.svg
|
||||
[commits]: https://github.com/hassio-addons/addon-esphomeyaml/commits/master
|
||||
[discord-shield]: https://img.shields.io/discord/429907082951524364.svg
|
||||
[dht22]: https://esphomelib.com/esphomeyaml/components/sensor/dht.html
|
||||
[discord]: https://discord.me/KhAMKrd
|
||||
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
|
||||
[forum]: https://community.home-assistant.io/c/third-party/esphomelib
|
||||
[gitlabci-shield]: https://gitlab.com/hassio-addons/addon-esphomeyaml/badges/master/pipeline.svg
|
||||
[gitlabci]: https://gitlab.com/hassio-addons/addon-esphomeyaml/pipelines
|
||||
[license-shield]: https://img.shields.io/github/license/hassio-addons/addon-esphomeyaml.svg
|
||||
[maintenance-shield]: https://img.shields.io/maintenance/yes/2018.svg
|
||||
[project-stage-shield]: https://img.shields.io/badge/project%20stage-stable-green.svg
|
||||
[releases-shield]: https://img.shields.io/github/release/hassio-addons/addon-esphomeyaml.svg
|
||||
[releases]: https://github.com/hassio-addons/addon-esphomeyaml/releases
|
||||
[repository]: https://github.com/hassio-addons/repository
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"squash": false,
|
||||
"build_from": {
|
||||
"aarch64": "homeassistant/aarch64-base-ubuntu:latest",
|
||||
"amd64": "homeassistant/amd64-base-ubuntu:latest",
|
||||
"armhf": "homeassistant/armhf-base-ubuntu:latest",
|
||||
"i386": "homeassistant/i386-base-ubuntu:latest"
|
||||
},
|
||||
"args": {}
|
||||
"squash": false,
|
||||
"build_from": {
|
||||
"aarch64": "hassioaddons/ubuntu-base-aarch64:2.2.0",
|
||||
"amd64": "hassioaddons/ubuntu-base-amd64:2.2.0",
|
||||
"armhf": "hassioaddons/ubuntu-base-armhf:2.2.0",
|
||||
"i386": "hassioaddons/ubuntu-base-i386:2.2.0"
|
||||
},
|
||||
"args": {}
|
||||
}
|
||||
|
||||
@@ -2,32 +2,41 @@
|
||||
"name": "esphomeyaml-edge",
|
||||
"version": "dev",
|
||||
"slug": "esphomeyaml-edge",
|
||||
"description": "Development build of the esphomeyaml HassIO add-on.",
|
||||
"url": "https://esphomelib.com/esphomeyaml/index.html",
|
||||
"startup": "application",
|
||||
"description": "Development Version! Manage and program ESP8266/ESP32 microcontrollers through YAML configuration files",
|
||||
"url": "https://github.com/OttoWinter/esphomeyaml/tree/dev/esphomeyaml-edge/README.md",
|
||||
"webui": "http://[HOST]:[PORT:6052]",
|
||||
"boot": "auto",
|
||||
"ports": {
|
||||
"6052/tcp": 6052,
|
||||
"6053/tcp": 6053
|
||||
},
|
||||
"startup": "application",
|
||||
"arch": [
|
||||
"aarch64",
|
||||
"amd64",
|
||||
"armhf",
|
||||
"i386"
|
||||
],
|
||||
"auto_uart": true,
|
||||
"hassio_api": true,
|
||||
"auth_api": true,
|
||||
"services": [
|
||||
"mqtt:want"
|
||||
],
|
||||
"hassio_role": "default",
|
||||
"homeassistant_api": false,
|
||||
"host_network": false,
|
||||
"boot": "auto",
|
||||
"ports": {
|
||||
"6052/tcp": 6052
|
||||
},
|
||||
"map": [
|
||||
"ssl",
|
||||
"config:rw"
|
||||
],
|
||||
"options": {
|
||||
"password": ""
|
||||
"ssl": false,
|
||||
"certfile": "fullchain.pem",
|
||||
"keyfile": "privkey.pem"
|
||||
},
|
||||
"schema": {
|
||||
"password": "str?"
|
||||
},
|
||||
"environment": {
|
||||
"ESPHOMEYAML_OTA_HOST_PORT": "6053"
|
||||
"ssl": "bool",
|
||||
"certfile": "str",
|
||||
"keyfile": "str",
|
||||
"leave_front_door_open": "bool?"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
esphomeyaml-edge/images/dht-example.png
Normal file
BIN
esphomeyaml-edge/images/dht-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
esphomeyaml-edge/images/screenshot.png
Normal file
BIN
esphomeyaml-edge/images/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
BIN
esphomeyaml-edge/images/temperature-humidity.png
Normal file
BIN
esphomeyaml-edge/images/temperature-humidity.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 8.6 KiB |
35
esphomeyaml-edge/rootfs/etc/cont-init.d/10-requirements.sh
Executable file
35
esphomeyaml-edge/rootfs/etc/cont-init.d/10-requirements.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: esphomeyaml
|
||||
# This files check if all user configuration requirements are met
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
|
||||
# Check SSL requirements, if enabled
|
||||
if hass.config.true 'ssl'; then
|
||||
if ! hass.config.has_value 'certfile'; then
|
||||
hass.die 'SSL is enabled, but no certfile was specified.'
|
||||
fi
|
||||
|
||||
if ! hass.config.has_value 'keyfile'; then
|
||||
hass.die 'SSL is enabled, but no keyfile was specified'
|
||||
fi
|
||||
|
||||
if ! hass.file_exists "/ssl/$(hass.config.get 'certfile')"; then
|
||||
if ! hass.file_exists "/ssl/$(hass.config.get 'keyfile')"; then
|
||||
# Both files are missing, let's print a friendlier error message
|
||||
text = "You enabled encrypted connections using the \"ssl\": true option.
|
||||
However, the SSL files \"$(hass.config.get 'certfile')\" and \"$(hass.config.get 'keyfile')\"
|
||||
were not found. If you're using Hass.io on your local network and don't want
|
||||
to encrypt connections to the esphomeyaml dashboard, you can manually disable
|
||||
SSL by setting \"ssl\" to false."
|
||||
hass.die "${text}"
|
||||
fi
|
||||
hass.die 'The configured certfile is not found'
|
||||
fi
|
||||
|
||||
if ! hass.file_exists "/ssl/$(hass.config.get 'keyfile')"; then
|
||||
hass.die 'The configured keyfile is not found'
|
||||
fi
|
||||
fi
|
||||
24
esphomeyaml-edge/rootfs/etc/cont-init.d/20-nginx.sh
Executable file
24
esphomeyaml-edge/rootfs/etc/cont-init.d/20-nginx.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: esphomeyaml
|
||||
# Configures NGINX for use with esphomeyaml
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
|
||||
declare certfile
|
||||
declare keyfile
|
||||
|
||||
mkdir -p /var/log/nginx
|
||||
|
||||
# Enable SSL
|
||||
if hass.config.true 'ssl'; then
|
||||
rm /etc/nginx/nginx.conf
|
||||
mv /etc/nginx/nginx-ssl.conf /etc/nginx/nginx.conf
|
||||
|
||||
certfile=$(hass.config.get 'certfile')
|
||||
keyfile=$(hass.config.get 'keyfile')
|
||||
|
||||
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf
|
||||
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf
|
||||
fi
|
||||
62
esphomeyaml-edge/rootfs/etc/nginx/nginx-ssl.conf
Executable file
62
esphomeyaml-edge/rootfs/etc/nginx/nginx-ssl.conf
Executable file
@@ -0,0 +1,62 @@
|
||||
worker_processes 1;
|
||||
pid /var/run/nginx.pid;
|
||||
error_log stderr;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
access_log stdout;
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
upstream esphomeyaml {
|
||||
ip_hash;
|
||||
server 127.0.0.1:80;
|
||||
}
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
server {
|
||||
server_name hassio.local;
|
||||
listen 6052 default_server ssl;
|
||||
root /dev/null;
|
||||
|
||||
ssl_certificate /ssl/%%certfile%%;
|
||||
ssl_certificate_key /ssl/%%keyfile%%;
|
||||
ssl_protocols TLSv1.2;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA;
|
||||
ssl_ecdh_curve secp384r1;
|
||||
ssl_session_timeout 10m;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_tickets off;
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
|
||||
# Redirect http requests to https on the same port.
|
||||
# https://rageagainstshell.com/2016/11/redirect-http-to-https-on-the-same-port-in-nginx/
|
||||
error_page 497 https://$http_host$request_uri;
|
||||
|
||||
location / {
|
||||
proxy_redirect off;
|
||||
proxy_pass http://esphomeyaml;
|
||||
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Authorization "";
|
||||
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-NginX-Proxy true;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
esphomeyaml-edge/rootfs/etc/nginx/nginx.conf
Executable file
46
esphomeyaml-edge/rootfs/etc/nginx/nginx.conf
Executable file
@@ -0,0 +1,46 @@
|
||||
worker_processes 1;
|
||||
pid /var/run/nginx.pid;
|
||||
error_log stderr;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
access_log stdout;
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
upstream esphomeyaml {
|
||||
ip_hash;
|
||||
server 127.0.0.1:80;
|
||||
}
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
server {
|
||||
server_name hassio.local;
|
||||
listen 6052 default_server;
|
||||
root /dev/null;
|
||||
|
||||
location / {
|
||||
proxy_redirect off;
|
||||
proxy_pass http://esphomeyaml;
|
||||
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Authorization "";
|
||||
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-NginX-Proxy true;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/finish
Executable file
9
esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/finish
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/execlineb -S0
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: esphomeyaml
|
||||
# Take down the S6 supervision tree when esphomeyaml fails
|
||||
# ==============================================================================
|
||||
if -n { s6-test $# -ne 0 }
|
||||
if -n { s6-test ${1} -eq 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
14
esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/run
Executable file
14
esphomeyaml-edge/rootfs/etc/services.d/esphomeyaml/run
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: esphomeyaml
|
||||
# Runs the esphomeyaml dashboard
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
|
||||
if hass.config.true 'leave_front_door_open'; then
|
||||
export DISABLE_HA_AUTHENTICATION=true
|
||||
fi
|
||||
|
||||
hass.log.info "Starting esphomeyaml dashboard..."
|
||||
exec esphomeyaml /config/esphomeyaml dashboard --port 80 --hassio
|
||||
9
esphomeyaml-edge/rootfs/etc/services.d/nginx/finish
Executable file
9
esphomeyaml-edge/rootfs/etc/services.d/nginx/finish
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/execlineb -S0
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: esphomeyaml
|
||||
# Take down the S6 supervision tree when NGINX fails
|
||||
# ==============================================================================
|
||||
if -n { s6-test $# -ne 0 }
|
||||
if -n { s6-test ${1} -eq 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
10
esphomeyaml-edge/rootfs/etc/services.d/nginx/run
Executable file
10
esphomeyaml-edge/rootfs/etc/services.d/nginx/run
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: esphomeyaml
|
||||
# Runs the NGINX proxy
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/hassio-addons/base.sh
|
||||
|
||||
hass.log.info "Starting NGINX..."
|
||||
exec nginx -g "daemon off;"
|
||||
12
esphomeyaml-edge/rootfs/opt/pio/platformio.ini
Normal file
12
esphomeyaml-edge/rootfs/opt/pio/platformio.ini
Normal file
@@ -0,0 +1,12 @@
|
||||
; This file allows the docker build file to install the required platformio
|
||||
; platforms
|
||||
|
||||
[env:espressif8266]
|
||||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
|
||||
[env:espressif32]
|
||||
platform = espressif32
|
||||
board = nodemcu-32s
|
||||
framework = arduino
|
||||
@@ -2,21 +2,23 @@ from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
from esphomeyaml import const, core, core_config, mqtt, wizard, writer, yaml_util, platformio_api
|
||||
from esphomeyaml.config import get_component, iter_components, read_config
|
||||
from esphomeyaml.const import CONF_BAUD_RATE, CONF_BUILD_PATH, CONF_DOMAIN, CONF_ESPHOMEYAML, \
|
||||
from esphomeyaml import const, core_config, mqtt, platformio_api, wizard, writer, yaml_util
|
||||
from esphomeyaml.config import get_component, iter_components, read_config, strip_default_ids
|
||||
from esphomeyaml.const import CONF_BAUD_RATE, CONF_DOMAIN, CONF_ESPHOMEYAML, \
|
||||
CONF_HOSTNAME, CONF_LOGGER, CONF_MANUAL_IP, CONF_NAME, CONF_STATIC_IP, CONF_USE_CUSTOM_CODE, \
|
||||
CONF_WIFI, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import AssignmentExpression, Expression, RawStatement, \
|
||||
_EXPRESSIONS, add, add_job, color, flush_tasks, indent, statement, relative_path
|
||||
from esphomeyaml.util import safe_print, run_external_command
|
||||
CONF_WIFI
|
||||
from esphomeyaml.core import CORE, EsphomeyamlError
|
||||
from esphomeyaml.cpp_generator import Expression, RawStatement, add, statement
|
||||
from esphomeyaml.helpers import color, indent
|
||||
from esphomeyaml.storage_json import StorageJSON, storage_path, start_update_check_thread, \
|
||||
esphomeyaml_storage_path
|
||||
from esphomeyaml.util import run_external_command, safe_print
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -32,6 +34,7 @@ def get_serial_ports():
|
||||
continue
|
||||
if "VID:PID" in info:
|
||||
result.append((port, desc))
|
||||
result.sort(key=lambda x: x[0])
|
||||
return result
|
||||
|
||||
|
||||
@@ -62,7 +65,7 @@ def choose_serial_port(config):
|
||||
return result[opt][0]
|
||||
|
||||
|
||||
def run_miniterm(config, port, escape=False):
|
||||
def run_miniterm(config, port):
|
||||
import serial
|
||||
if CONF_LOGGER not in config:
|
||||
_LOGGER.info("Logger is not enabled. Not starting UART logs.")
|
||||
@@ -83,8 +86,6 @@ def run_miniterm(config, port, escape=False):
|
||||
line = raw.replace('\r', '').replace('\n', '')
|
||||
time = datetime.now().time().strftime('[%H:%M:%S]')
|
||||
message = time + line
|
||||
if escape:
|
||||
message = message.replace('\033', '\\033')
|
||||
safe_print(message)
|
||||
|
||||
backtrace_state = platformio_api.process_stacktrace(
|
||||
@@ -94,43 +95,40 @@ def run_miniterm(config, port, escape=False):
|
||||
def write_cpp(config):
|
||||
_LOGGER.info("Generating C++ source...")
|
||||
|
||||
add_job(core_config.to_code, config[CONF_ESPHOMEYAML], domain='esphomeyaml')
|
||||
CORE.add_job(core_config.to_code, config[CONF_ESPHOMEYAML], domain='esphomeyaml')
|
||||
for domain in PRE_INITIALIZE:
|
||||
if domain == CONF_ESPHOMEYAML or domain not in config:
|
||||
continue
|
||||
add_job(get_component(domain).to_code, config[domain], domain=domain)
|
||||
CORE.add_job(get_component(domain).to_code, config[domain], domain=domain)
|
||||
|
||||
for domain, component, conf in iter_components(config):
|
||||
if domain in PRE_INITIALIZE or not hasattr(component, 'to_code'):
|
||||
continue
|
||||
add_job(component.to_code, conf, domain=domain)
|
||||
CORE.add_job(component.to_code, conf, domain=domain)
|
||||
|
||||
flush_tasks()
|
||||
CORE.flush_tasks()
|
||||
add(RawStatement(''))
|
||||
add(RawStatement(''))
|
||||
all_code = []
|
||||
for exp in _EXPRESSIONS:
|
||||
for exp in CORE.expressions:
|
||||
if not config[CONF_ESPHOMEYAML][CONF_USE_CUSTOM_CODE]:
|
||||
if isinstance(exp, Expression) and not exp.required:
|
||||
continue
|
||||
if isinstance(exp, AssignmentExpression) and not exp.obj.required:
|
||||
if not exp.has_side_effects():
|
||||
continue
|
||||
exp = exp.rhs
|
||||
all_code.append(unicode(statement(exp)))
|
||||
|
||||
build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])
|
||||
writer.write_platformio_project(config, build_path)
|
||||
writer.write_platformio_project()
|
||||
|
||||
code_s = indent('\n'.join(line.rstrip() for line in all_code))
|
||||
cpp_path = os.path.join(build_path, 'src', 'main.cpp')
|
||||
writer.write_cpp(code_s, cpp_path)
|
||||
writer.write_cpp(code_s)
|
||||
return 0
|
||||
|
||||
|
||||
def compile_program(args, config):
|
||||
_LOGGER.info("Compiling app...")
|
||||
return platformio_api.run_compile(config, args.verbose)
|
||||
thread = start_update_check_thread(esphomeyaml_storage_path(CORE.config_dir))
|
||||
rc = platformio_api.run_compile(config, args.verbose)
|
||||
thread.join()
|
||||
return rc
|
||||
|
||||
|
||||
def get_upload_host(config):
|
||||
@@ -146,8 +144,7 @@ def get_upload_host(config):
|
||||
def upload_using_esptool(config, port):
|
||||
import esptool
|
||||
|
||||
build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])
|
||||
path = os.path.join(build_path, '.pioenvs', core.NAME, 'firmware.bin')
|
||||
path = os.path.join(CORE.build_path, '.pioenvs', CORE.name, 'firmware.bin')
|
||||
cmd = ['esptool.py', '--before', 'default_reset', '--after', 'hard_reset',
|
||||
'--chip', 'esp8266', '--port', port, 'write_flash', '0x0', path]
|
||||
# pylint: disable=protected-access
|
||||
@@ -155,12 +152,10 @@ def upload_using_esptool(config, port):
|
||||
|
||||
|
||||
def upload_program(config, args, port):
|
||||
build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])
|
||||
|
||||
# if upload is to a serial port use platformio, otherwise assume ota
|
||||
serial_port = port.startswith('/') or port.startswith('COM')
|
||||
if port != 'OTA' and serial_port:
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266 and args.use_esptoolpy:
|
||||
if CORE.is_esp8266:
|
||||
return upload_using_esptool(config, port)
|
||||
return platformio_api.run_upload(config, args.verbose, port)
|
||||
|
||||
@@ -178,7 +173,6 @@ def upload_program(config, args, port):
|
||||
from esphomeyaml.components import ota
|
||||
from esphomeyaml import espota2
|
||||
|
||||
bin_file = os.path.join(build_path, '.pioenvs', core.NAME, 'firmware.bin')
|
||||
if args.host_port is not None:
|
||||
host_port = args.host_port
|
||||
else:
|
||||
@@ -188,20 +182,27 @@ def upload_program(config, args, port):
|
||||
remote_port = ota.get_port(config)
|
||||
password = ota.get_auth(config)
|
||||
|
||||
res = espota2.run_ota(host, remote_port, password, bin_file)
|
||||
storage = StorageJSON.load(storage_path())
|
||||
res = espota2.run_ota(host, remote_port, password, CORE.firmware_bin)
|
||||
if res == 0:
|
||||
if storage is not None and storage.use_legacy_ota:
|
||||
storage.use_legacy_ota = False
|
||||
storage.save(storage_path())
|
||||
return res
|
||||
if storage is not None and not storage.use_legacy_ota:
|
||||
return res
|
||||
|
||||
_LOGGER.warn("OTA v2 method failed. Trying with legacy OTA...")
|
||||
return espota2.run_legacy_ota(verbose, host_port, host, remote_port, password, bin_file)
|
||||
return espota2.run_legacy_ota(verbose, host_port, host, remote_port, password,
|
||||
CORE.firmware_bin)
|
||||
|
||||
|
||||
def show_logs(config, args, port, escape=False):
|
||||
def show_logs(config, args, port):
|
||||
serial_port = port.startswith('/') or port.startswith('COM')
|
||||
if port != 'OTA' and serial_port:
|
||||
run_miniterm(config, port, escape=escape)
|
||||
run_miniterm(config, port)
|
||||
return 0
|
||||
return mqtt.show_logs(config, args.topic, args.username, args.password, args.client_id,
|
||||
escape=escape)
|
||||
return mqtt.show_logs(config, args.topic, args.username, args.password, args.client_id)
|
||||
|
||||
|
||||
def clean_mqtt(config, args):
|
||||
@@ -239,26 +240,8 @@ def command_wizard(args):
|
||||
return wizard.wizard(args.configuration)
|
||||
|
||||
|
||||
def strip_default_ids(config):
|
||||
value = config
|
||||
if isinstance(config, list):
|
||||
value = type(config)()
|
||||
for x in config:
|
||||
if isinstance(x, core.ID) and not x.is_manual:
|
||||
continue
|
||||
value.append(strip_default_ids(x))
|
||||
return value
|
||||
elif isinstance(config, dict):
|
||||
value = type(config)()
|
||||
for k, v in config.iteritems():
|
||||
if isinstance(v, core.ID) and not v.is_manual:
|
||||
continue
|
||||
value[k] = strip_default_ids(v)
|
||||
return value
|
||||
return value
|
||||
|
||||
|
||||
def command_config(args, config):
|
||||
_LOGGER.info("Configuration is valid!")
|
||||
if not args.verbose:
|
||||
config = strip_default_ids(config)
|
||||
safe_print(yaml_util.dump(config))
|
||||
@@ -290,7 +273,7 @@ def command_upload(args, config):
|
||||
|
||||
def command_logs(args, config):
|
||||
port = args.serial_port or choose_serial_port(config)
|
||||
return show_logs(config, args, port, escape=args.escape)
|
||||
return show_logs(config, args, port)
|
||||
|
||||
|
||||
def command_run(args, config):
|
||||
@@ -308,7 +291,7 @@ def command_run(args, config):
|
||||
_LOGGER.info(u"Successfully uploaded program.")
|
||||
if args.no_logs:
|
||||
return 0
|
||||
return show_logs(config, args, port, escape=args.escape)
|
||||
return show_logs(config, args, port)
|
||||
|
||||
|
||||
def command_clean_mqtt(args, config):
|
||||
@@ -325,9 +308,8 @@ def command_version(args):
|
||||
|
||||
|
||||
def command_clean(args, config):
|
||||
build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])
|
||||
try:
|
||||
writer.clean_build(build_path)
|
||||
writer.clean_build()
|
||||
except OSError as err:
|
||||
_LOGGER.error("Error deleting build files: %s", err)
|
||||
return 1
|
||||
@@ -403,9 +385,6 @@ def parse_args(argv):
|
||||
parser_upload.add_argument('--upload-port', help="Manually specify the upload port to use. "
|
||||
"For example /dev/cu.SLAB_USBtoUART.")
|
||||
parser_upload.add_argument('--host-port', help="Specify the host port.", type=int)
|
||||
parser_upload.add_argument('--use-esptoolpy',
|
||||
help="Use esptool.py for the uploading (only for ESP8266)",
|
||||
action='store_true')
|
||||
|
||||
parser_logs = subparsers.add_parser('logs', help='Validate the configuration '
|
||||
'and show all MQTT logs.')
|
||||
@@ -415,8 +394,6 @@ def parse_args(argv):
|
||||
parser_logs.add_argument('--client-id', help='Manually set the client id.')
|
||||
parser_logs.add_argument('--serial-port', help="Manually specify a serial port to use"
|
||||
"For example /dev/cu.SLAB_USBtoUART.")
|
||||
parser_logs.add_argument('--escape', help="Escape ANSI color codes for running in dashboard",
|
||||
action='store_true')
|
||||
|
||||
parser_run = subparsers.add_parser('run', help='Validate the configuration, create a binary, '
|
||||
'upload it, and start MQTT logs.')
|
||||
@@ -429,11 +406,6 @@ def parse_args(argv):
|
||||
parser_run.add_argument('--username', help='Manually set the MQTT username for logs.')
|
||||
parser_run.add_argument('--password', help='Manually set the MQTT password for logs.')
|
||||
parser_run.add_argument('--client-id', help='Manually set the client id for logs.')
|
||||
parser_run.add_argument('--escape', help="Escape ANSI color codes for running in dashboard",
|
||||
action='store_true')
|
||||
parser_run.add_argument('--use-esptoolpy',
|
||||
help="Use esptool.py for the uploading (only for ESP8266)",
|
||||
action='store_true')
|
||||
|
||||
parser_clean = subparsers.add_parser('clean-mqtt', help="Helper to clear an MQTT topic from "
|
||||
"retain messages.")
|
||||
@@ -453,39 +425,46 @@ def parse_args(argv):
|
||||
|
||||
dashboard = subparsers.add_parser('dashboard',
|
||||
help="Create a simple web server for a dashboard.")
|
||||
dashboard.add_argument("--port", help="The HTTP port to open connections on.", type=int,
|
||||
default=6052)
|
||||
dashboard.add_argument("--port", help="The HTTP port to open connections on. Defaults to 6052.",
|
||||
type=int, default=6052)
|
||||
dashboard.add_argument("--password", help="The optional password to require for all requests.",
|
||||
type=str, default='')
|
||||
dashboard.add_argument("--open-ui", help="Open the dashboard UI in a browser.",
|
||||
action='store_true')
|
||||
dashboard.add_argument("--hassio",
|
||||
help="Internal flag used to tell esphomeyaml is started as a Hass.io "
|
||||
"add-on.",
|
||||
action="store_true")
|
||||
|
||||
subparsers.add_parser('hass-config', help="Dump the configuration entries that should be added"
|
||||
"to Home Assistant when not using MQTT discovery.")
|
||||
subparsers.add_parser('hass-config',
|
||||
help="Dump the configuration entries that should be added "
|
||||
"to Home Assistant when not using MQTT discovery.")
|
||||
|
||||
return parser.parse_args(argv[1:])
|
||||
|
||||
|
||||
def run_esphomeyaml(argv):
|
||||
args = parse_args(argv)
|
||||
|
||||
setup_log(args.verbose)
|
||||
if args.command in PRE_CONFIG_ACTIONS:
|
||||
try:
|
||||
return PRE_CONFIG_ACTIONS[args.command](args)
|
||||
except ESPHomeYAMLError as e:
|
||||
except EsphomeyamlError as e:
|
||||
_LOGGER.error(e)
|
||||
return 1
|
||||
|
||||
core.CONFIG_PATH = args.configuration
|
||||
CORE.config_path = args.configuration
|
||||
|
||||
config = read_config(core.CONFIG_PATH)
|
||||
config = read_config(args.verbose)
|
||||
if config is None:
|
||||
return 1
|
||||
CORE.config = config
|
||||
|
||||
if args.command in POST_CONFIG_ACTIONS:
|
||||
try:
|
||||
return POST_CONFIG_ACTIONS[args.command](args, config)
|
||||
except ESPHomeYAMLError as e:
|
||||
except EsphomeyamlError as e:
|
||||
_LOGGER.error(e)
|
||||
return 1
|
||||
safe_print(u"Unknown command {}".format(args.command))
|
||||
@@ -495,7 +474,7 @@ def run_esphomeyaml(argv):
|
||||
def main():
|
||||
try:
|
||||
return run_esphomeyaml(sys.argv)
|
||||
except ESPHomeYAMLError as e:
|
||||
except EsphomeyamlError as e:
|
||||
_LOGGER.error(e)
|
||||
return 1
|
||||
except KeyboardInterrupt:
|
||||
|
||||
@@ -2,16 +2,15 @@ import copy
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ABOVE, CONF_ACTION_ID, CONF_AND, CONF_AUTOMATION_ID, \
|
||||
CONF_BELOW, CONF_CONDITION, CONF_CONDITION_ID, CONF_DELAY, \
|
||||
CONF_ELSE, CONF_ID, CONF_IF, CONF_LAMBDA, \
|
||||
CONF_OR, CONF_RANGE, CONF_THEN, CONF_TRIGGER_ID
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, TemplateArguments, add, add_job, \
|
||||
esphomelib_ns, float_, process_lambda, templatable, uint32, get_variable, PollingComponent, \
|
||||
Action, Component, Trigger
|
||||
CONF_BELOW, CONF_CONDITION, CONF_CONDITION_ID, CONF_DELAY, CONF_ELSE, CONF_ID, CONF_IF, \
|
||||
CONF_LAMBDA, CONF_OR, CONF_RANGE, CONF_THEN, CONF_TRIGGER_ID, CONF_WHILE
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, TemplateArguments, add, \
|
||||
get_variable, process_lambda, templatable
|
||||
from esphomeyaml.cpp_types import Action, App, Component, PollingComponent, Trigger, \
|
||||
esphomelib_ns, float_, uint32
|
||||
from esphomeyaml.util import ServiceRegistry
|
||||
|
||||
|
||||
@@ -27,41 +26,81 @@ def maybe_simple_id(*validators):
|
||||
|
||||
|
||||
def validate_recursive_condition(value):
|
||||
return CONDITIONS_SCHEMA(value)
|
||||
is_list = isinstance(value, list)
|
||||
value = cv.ensure_list(value)[:]
|
||||
for i, item in enumerate(value):
|
||||
path = [i] if is_list else []
|
||||
item = copy.deepcopy(item)
|
||||
if not isinstance(item, dict):
|
||||
raise vol.Invalid(u"Condition must consist of key-value mapping! Got {}".format(item),
|
||||
path)
|
||||
key = next((x for x in item if x != CONF_CONDITION_ID), None)
|
||||
if key is None:
|
||||
raise vol.Invalid(u"Key missing from action! Got {}".format(item), path)
|
||||
if key not in CONDITION_REGISTRY:
|
||||
raise vol.Invalid(u"Unable to find condition with the name '{}', is the "
|
||||
u"component loaded?".format(key), path + [key])
|
||||
item.setdefault(CONF_CONDITION_ID, None)
|
||||
key2 = next((x for x in item if x != CONF_CONDITION_ID and x != key), None)
|
||||
if key2 is not None:
|
||||
raise vol.Invalid(u"Cannot have two conditions in one item. Key '{}' overrides '{}'! "
|
||||
u"Did you forget to indent the block inside the condition?"
|
||||
u"".format(key, key2), path)
|
||||
validator = CONDITION_REGISTRY[key][0]
|
||||
try:
|
||||
condition = validator(item[key])
|
||||
except vol.Invalid as err:
|
||||
err.prepend(path)
|
||||
raise err
|
||||
value[i] = {
|
||||
CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]),
|
||||
key: condition,
|
||||
}
|
||||
return value
|
||||
|
||||
|
||||
def validate_recursive_action(value):
|
||||
is_list = isinstance(value, list)
|
||||
value = cv.ensure_list(value)[:]
|
||||
for i, item in enumerate(value):
|
||||
path = [i] if is_list else []
|
||||
item = copy.deepcopy(item)
|
||||
if not isinstance(item, dict):
|
||||
raise vol.Invalid(u"Action must consist of key-value mapping! Got {}".format(item))
|
||||
raise vol.Invalid(u"Action must consist of key-value mapping! Got {}".format(item),
|
||||
path)
|
||||
key = next((x for x in item if x != CONF_ACTION_ID), None)
|
||||
if key is None:
|
||||
raise vol.Invalid(u"Key missing from action! Got {}".format(item))
|
||||
raise vol.Invalid(u"Key missing from action! Got {}".format(item), path)
|
||||
if key not in ACTION_REGISTRY:
|
||||
raise vol.Invalid(u"Unable to find action with the name '{}', is the component loaded?"
|
||||
u"".format(key))
|
||||
u"".format(key), path + [key])
|
||||
item.setdefault(CONF_ACTION_ID, None)
|
||||
key2 = next((x for x in item if x != CONF_ACTION_ID and x != key), None)
|
||||
if key2 is not None:
|
||||
raise vol.Invalid(u"Cannot have two actions in one item. Key '{}' overrides '{}'! "
|
||||
u"Did you forget to indent the action?"
|
||||
u"".format(key, key2))
|
||||
u"Did you forget to indent the block inside the action?"
|
||||
u"".format(key, key2), path)
|
||||
validator = ACTION_REGISTRY[key][0]
|
||||
try:
|
||||
action = validator(item[key])
|
||||
except vol.Invalid as err:
|
||||
err.prepend(path)
|
||||
raise err
|
||||
value[i] = {
|
||||
CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
|
||||
key: validator(item[key])
|
||||
key: action,
|
||||
}
|
||||
return value
|
||||
|
||||
|
||||
ACTION_REGISTRY = ServiceRegistry()
|
||||
CONDITION_REGISTRY = ServiceRegistry()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
DelayAction = esphomelib_ns.class_('DelayAction', Action, Component)
|
||||
LambdaAction = esphomelib_ns.class_('LambdaAction', Action)
|
||||
IfAction = esphomelib_ns.class_('IfAction', Action)
|
||||
WhileAction = esphomelib_ns.class_('WhileAction', Action)
|
||||
UpdateComponentAction = esphomelib_ns.class_('UpdateComponentAction', Action)
|
||||
Automation = esphomelib_ns.class_('Automation')
|
||||
|
||||
@@ -71,17 +110,6 @@ OrCondition = esphomelib_ns.class_('OrCondition', Condition)
|
||||
RangeCondition = esphomelib_ns.class_('RangeCondition', Condition)
|
||||
LambdaCondition = esphomelib_ns.class_('LambdaCondition', Condition)
|
||||
|
||||
CONDITIONS_SCHEMA = vol.All(cv.ensure_list, [cv.templatable({
|
||||
cv.GenerateID(CONF_CONDITION_ID): cv.declare_variable_id(Condition),
|
||||
vol.Optional(CONF_AND): validate_recursive_condition,
|
||||
vol.Optional(CONF_OR): validate_recursive_condition,
|
||||
vol.Optional(CONF_RANGE): vol.All(vol.Schema({
|
||||
vol.Optional(CONF_ABOVE): vol.Coerce(float),
|
||||
vol.Optional(CONF_BELOW): vol.Coerce(float),
|
||||
}), cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW)),
|
||||
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
||||
})])
|
||||
|
||||
|
||||
def validate_automation(extra_schema=None, extra_validators=None, single=False):
|
||||
schema = AUTOMATION_SCHEMA.extend(extra_schema or {})
|
||||
@@ -122,63 +150,63 @@ def validate_automation(extra_schema=None, extra_validators=None, single=False):
|
||||
AUTOMATION_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(Trigger),
|
||||
cv.GenerateID(CONF_AUTOMATION_ID): cv.declare_variable_id(Automation),
|
||||
vol.Optional(CONF_IF): CONDITIONS_SCHEMA,
|
||||
vol.Optional(CONF_IF): validate_recursive_condition,
|
||||
vol.Required(CONF_THEN): validate_recursive_action,
|
||||
})
|
||||
|
||||
AND_CONDITION_SCHEMA = validate_recursive_condition
|
||||
|
||||
def build_condition(config, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
if isinstance(config, core.Lambda):
|
||||
lambda_ = None
|
||||
for lambda_ in process_lambda(config, [(arg_type, 'x')]):
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_AND, AND_CONDITION_SCHEMA)
|
||||
def and_condition_to_code(config, condition_id, arg_type, template_arg):
|
||||
for conditions in build_conditions(config, arg_type):
|
||||
yield
|
||||
rhs = AndCondition.new(template_arg, conditions)
|
||||
type = AndCondition.template(template_arg)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
OR_CONDITION_SCHEMA = validate_recursive_condition
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_OR, OR_CONDITION_SCHEMA)
|
||||
def or_condition_to_code(config, condition_id, arg_type, template_arg):
|
||||
for conditions in build_conditions(config, arg_type):
|
||||
yield
|
||||
rhs = OrCondition.new(template_arg, conditions)
|
||||
type = OrCondition.template(template_arg)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
RANGE_CONDITION_SCHEMA = vol.All(vol.Schema({
|
||||
vol.Optional(CONF_ABOVE): cv.templatable(cv.float_),
|
||||
vol.Optional(CONF_BELOW): cv.templatable(cv.float_),
|
||||
}), cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW))
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_RANGE, RANGE_CONDITION_SCHEMA)
|
||||
def range_condition_to_code(config, condition_id, arg_type, template_arg):
|
||||
for conditions in build_conditions(config, arg_type):
|
||||
yield
|
||||
rhs = RangeCondition.new(template_arg, conditions)
|
||||
type = RangeCondition.template(template_arg)
|
||||
condition = Pvariable(condition_id, rhs, type=type)
|
||||
if CONF_ABOVE in config:
|
||||
for template_ in templatable(config[CONF_ABOVE], arg_type, float_):
|
||||
yield
|
||||
yield LambdaCondition.new(template_arg, lambda_)
|
||||
elif CONF_AND in config:
|
||||
yield AndCondition.new(template_arg, build_conditions(config[CONF_AND], template_arg))
|
||||
elif CONF_OR in config:
|
||||
yield OrCondition.new(template_arg, build_conditions(config[CONF_OR], template_arg))
|
||||
elif CONF_LAMBDA in config:
|
||||
lambda_ = None
|
||||
for lambda_ in process_lambda(config[CONF_LAMBDA], [(arg_type, 'x')]):
|
||||
condition.set_min(template_)
|
||||
if CONF_BELOW in config:
|
||||
for template_ in templatable(config[CONF_BELOW], arg_type, float_):
|
||||
yield
|
||||
yield LambdaCondition.new(template_arg, lambda_)
|
||||
elif CONF_RANGE in config:
|
||||
conf = config[CONF_RANGE]
|
||||
rhs = RangeCondition.new(template_arg)
|
||||
type = RangeCondition.template(template_arg)
|
||||
condition = Pvariable(config[CONF_CONDITION_ID], rhs, type=type)
|
||||
if CONF_ABOVE in conf:
|
||||
template_ = None
|
||||
for template_ in templatable(conf[CONF_ABOVE], arg_type, float_):
|
||||
yield
|
||||
condition.set_min(template_)
|
||||
if CONF_BELOW in conf:
|
||||
template_ = None
|
||||
for template_ in templatable(conf[CONF_BELOW], arg_type, float_):
|
||||
yield
|
||||
condition.set_max(template_)
|
||||
yield condition
|
||||
else:
|
||||
raise ESPHomeYAMLError(u"Unsupported condition {}".format(config))
|
||||
|
||||
|
||||
def build_conditions(config, arg_type):
|
||||
conditions = []
|
||||
for conf in config:
|
||||
condition = None
|
||||
for condition in build_condition(conf, arg_type):
|
||||
yield None
|
||||
conditions.append(condition)
|
||||
yield ArrayInitializer(*conditions)
|
||||
condition.set_max(template_)
|
||||
yield condition
|
||||
|
||||
|
||||
DELAY_ACTION_SCHEMA = cv.templatable(cv.positive_time_period_milliseconds)
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_DELAY, DELAY_ACTION_SCHEMA)
|
||||
def delay_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def delay_action_to_code(config, action_id, arg_type, template_arg):
|
||||
rhs = App.register_component(DelayAction.new(template_arg))
|
||||
type = DelayAction.template(template_arg)
|
||||
action = Pvariable(action_id, rhs, type=type)
|
||||
@@ -196,8 +224,7 @@ IF_ACTION_SCHEMA = vol.All({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_IF, IF_ACTION_SCHEMA)
|
||||
def if_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def if_action_to_code(config, action_id, arg_type, template_arg):
|
||||
for conditions in build_conditions(config[CONF_CONDITION], arg_type):
|
||||
yield None
|
||||
rhs = IfAction.new(template_arg, conditions)
|
||||
@@ -214,12 +241,30 @@ def if_action_to_code(config, action_id, arg_type):
|
||||
yield action
|
||||
|
||||
|
||||
WHILE_ACTION_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_CONDITION): validate_recursive_condition,
|
||||
vol.Required(CONF_THEN): validate_recursive_action,
|
||||
})
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_WHILE, WHILE_ACTION_SCHEMA)
|
||||
def while_action_to_code(config, action_id, arg_type, template_arg):
|
||||
for conditions in build_conditions(config[CONF_CONDITION], arg_type):
|
||||
yield None
|
||||
rhs = WhileAction.new(template_arg, conditions)
|
||||
type = WhileAction.template(template_arg)
|
||||
action = Pvariable(action_id, rhs, type=type)
|
||||
for actions in build_actions(config[CONF_THEN], arg_type):
|
||||
yield None
|
||||
add(action.add_then(actions))
|
||||
yield action
|
||||
|
||||
|
||||
LAMBDA_ACTION_SCHEMA = cv.lambda_
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_LAMBDA, LAMBDA_ACTION_SCHEMA)
|
||||
def lambda_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def lambda_action_to_code(config, action_id, arg_type, template_arg):
|
||||
for lambda_ in process_lambda(config, [(arg_type, 'x')]):
|
||||
yield None
|
||||
rhs = LambdaAction.new(template_arg, lambda_)
|
||||
@@ -227,6 +272,18 @@ def lambda_action_to_code(config, action_id, arg_type):
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
|
||||
LAMBDA_CONDITION_SCHEMA = cv.lambda_
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_LAMBDA, LAMBDA_CONDITION_SCHEMA)
|
||||
def lambda_condition_to_code(config, condition_id, arg_type, template_arg):
|
||||
for lambda_ in process_lambda(config, [(arg_type, 'x')]):
|
||||
yield
|
||||
rhs = LambdaCondition.new(template_arg, lambda_)
|
||||
type = LambdaCondition.template(template_arg)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_COMPONENT_UPDATE = 'component.update'
|
||||
COMPONENT_UPDATE_ACTION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(PollingComponent),
|
||||
@@ -234,8 +291,7 @@ COMPONENT_UPDATE_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_COMPONENT_UPDATE, COMPONENT_UPDATE_ACTION_SCHEMA)
|
||||
def component_update_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def component_update_action_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = UpdateComponentAction.new(var)
|
||||
@@ -248,7 +304,8 @@ def build_action(full_config, arg_type):
|
||||
key, config = next((k, v) for k, v in full_config.items() if k in ACTION_REGISTRY)
|
||||
|
||||
builder = ACTION_REGISTRY[key][1]
|
||||
for result in builder(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
for result in builder(config, action_id, arg_type, template_arg):
|
||||
yield None
|
||||
yield result
|
||||
|
||||
@@ -263,6 +320,26 @@ def build_actions(config, arg_type):
|
||||
yield ArrayInitializer(*actions, multiline=False)
|
||||
|
||||
|
||||
def build_condition(full_config, arg_type):
|
||||
action_id = full_config[CONF_CONDITION_ID]
|
||||
key, config = next((k, v) for k, v in full_config.items() if k in CONDITION_REGISTRY)
|
||||
|
||||
builder = CONDITION_REGISTRY[key][1]
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
for result in builder(config, action_id, arg_type, template_arg):
|
||||
yield None
|
||||
yield result
|
||||
|
||||
|
||||
def build_conditions(config, arg_type):
|
||||
conditions = []
|
||||
for conf in config:
|
||||
for condition in build_condition(conf, arg_type):
|
||||
yield None
|
||||
conditions.append(condition)
|
||||
yield ArrayInitializer(*conditions, multiline=False)
|
||||
|
||||
|
||||
def build_automation_(trigger, arg_type, config):
|
||||
rhs = App.make_automation(TemplateArguments(arg_type), trigger)
|
||||
type = Automation.template(arg_type)
|
||||
@@ -280,4 +357,4 @@ def build_automation_(trigger, arg_type, config):
|
||||
|
||||
|
||||
def build_automation(trigger, arg_type, config):
|
||||
add_job(build_automation_, trigger, arg_type, config)
|
||||
CORE.add_job(build_automation_, trigger, arg_type, config)
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import sensor, i2c
|
||||
from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
MULTI_CONF = True
|
||||
|
||||
ADS1115Component = sensor.sensor_ns.class_('ADS1115Component', Component, i2c.I2CDevice)
|
||||
|
||||
ADS1115_SCHEMA = vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(ADS1115Component),
|
||||
vol.Required(CONF_ADDRESS): cv.i2c_address,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [ADS1115_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
rhs = App.make_ads1115_component(conf[CONF_ADDRESS])
|
||||
var = Pvariable(conf[CONF_ID], rhs)
|
||||
setup_component(var, conf)
|
||||
rhs = App.make_ads1115_component(config[CONF_ADDRESS])
|
||||
var = Pvariable(config[CONF_ID], rhs)
|
||||
setup_component(var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_ADS1115_SENSOR'
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import automation, core
|
||||
from esphomeyaml.automation import maybe_simple_id, CONDITION_REGISTRY, Condition
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_DELAYED_OFF, CONF_DELAYED_ON, CONF_DEVICE_CLASS, CONF_FILTERS, \
|
||||
CONF_HEARTBEAT, CONF_ID, CONF_INTERNAL, CONF_INVALID_COOLDOWN, CONF_INVERT, CONF_INVERTED, \
|
||||
CONF_LAMBDA, CONF_MAX_LENGTH, CONF_MIN_LENGTH, CONF_MQTT_ID, CONF_ON_CLICK, \
|
||||
CONF_ON_DOUBLE_CLICK, CONF_ON_MULTI_CLICK, CONF_ON_PRESS, CONF_ON_RELEASE, CONF_STATE, \
|
||||
CONF_TIMING, CONF_TRIGGER_ID
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, NoArg, Pvariable, StructInitializer, add, \
|
||||
add_job, bool_, esphomelib_ns, process_lambda, setup_mqtt_component, Nameable, Trigger, \
|
||||
Component
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import process_lambda, ArrayInitializer, add, Pvariable, \
|
||||
StructInitializer, get_variable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Trigger, NoArg, Component, App, bool_
|
||||
|
||||
DEVICE_CLASSES = [
|
||||
'', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas',
|
||||
@@ -25,6 +28,7 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
binary_sensor_ns = esphomelib_ns.namespace('binary_sensor')
|
||||
BinarySensor = binary_sensor_ns.class_('BinarySensor', Nameable)
|
||||
BinarySensorPtr = BinarySensor.operator('ptr')
|
||||
MQTTBinarySensorComponent = binary_sensor_ns.class_('MQTTBinarySensorComponent', mqtt.MQTTComponent)
|
||||
|
||||
# Triggers
|
||||
@@ -35,6 +39,9 @@ DoubleClickTrigger = binary_sensor_ns.class_('DoubleClickTrigger', Trigger.templ
|
||||
MultiClickTrigger = binary_sensor_ns.class_('MultiClickTrigger', Trigger.template(NoArg), Component)
|
||||
MultiClickTriggerEvent = binary_sensor_ns.struct('MultiClickTriggerEvent')
|
||||
|
||||
# Condition
|
||||
BinarySensorCondition = binary_sensor_ns.class_('BinarySensorCondition', Condition)
|
||||
|
||||
# Filters
|
||||
Filter = binary_sensor_ns.class_('Filter')
|
||||
DelayedOnFilter = binary_sensor_ns.class_('DelayedOnFilter', Filter, Component)
|
||||
@@ -269,14 +276,14 @@ def setup_binary_sensor(binary_sensor_obj, mqtt_obj, config):
|
||||
has_side_effects=False)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj,
|
||||
has_side_effects=False)
|
||||
add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
|
||||
CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
|
||||
|
||||
|
||||
def register_binary_sensor(var, config):
|
||||
binary_sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||
rhs = App.register_binary_sensor(binary_sensor_var)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
||||
add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
|
||||
CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
|
||||
|
||||
|
||||
def core_to_hass_config(data, config):
|
||||
@@ -290,3 +297,33 @@ def core_to_hass_config(data, config):
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_BINARY_SENSOR'
|
||||
|
||||
|
||||
CONF_BINARY_SENSOR_IS_ON = 'binary_sensor.is_on'
|
||||
BINARY_SENSOR_IS_ON_CONDITION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(BinarySensor),
|
||||
})
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_BINARY_SENSOR_IS_ON, BINARY_SENSOR_IS_ON_CONDITION_SCHEMA)
|
||||
def binary_sensor_is_on_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_binary_sensor_is_on_condition(template_arg)
|
||||
type = BinarySensorCondition.template(arg_type)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_BINARY_SENSOR_IS_OFF = 'binary_sensor.is_off'
|
||||
BINARY_SENSOR_IS_OFF_CONDITION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(BinarySensor),
|
||||
})
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_BINARY_SENSOR_IS_OFF, BINARY_SENSOR_IS_OFF_CONDITION_SCHEMA)
|
||||
def binary_sensor_is_off_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_binary_sensor_is_off_condition(template_arg)
|
||||
type = BinarySensorCondition.template(arg_type)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
37
esphomeyaml/components/binary_sensor/custom.py
Normal file
37
esphomeyaml/components/binary_sensor/custom.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import binary_sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BINARY_SENSORS, CONF_ID, CONF_LAMBDA
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable
|
||||
from esphomeyaml.cpp_types import std_vector
|
||||
|
||||
CustomBinarySensorConstructor = binary_sensor.binary_sensor_ns.class_(
|
||||
'CustomBinarySensorConstructor')
|
||||
|
||||
PLATFORM_SCHEMA = binary_sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomBinarySensorConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_BINARY_SENSORS):
|
||||
vol.All(cv.ensure_list, [binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(binary_sensor.BinarySensor),
|
||||
})]),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(binary_sensor.BinarySensorPtr)):
|
||||
yield
|
||||
|
||||
rhs = CustomBinarySensorConstructor(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, sens in enumerate(config[CONF_BINARY_SENSORS]):
|
||||
binary_sensor.register_binary_sensor(custom.get_binary_sensor(i), sens)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_BINARY_SENSOR'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return [binary_sensor.core_to_hass_config(data, sens) for sens in config[CONF_BINARY_SENSORS]]
|
||||
@@ -5,7 +5,8 @@ from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLE
|
||||
make_address_array
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAC_ADDRESS, CONF_NAME
|
||||
from esphomeyaml.helpers import esphomelib_ns, get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns
|
||||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
ESP32BLEPresenceDevice = esphomelib_ns.class_('ESP32BLEPresenceDevice', binary_sensor.BinarySensor)
|
||||
|
||||
@@ -4,7 +4,8 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import binary_sensor
|
||||
from esphomeyaml.components.esp32_touch import ESP32TouchComponent
|
||||
from esphomeyaml.const import CONF_NAME, CONF_PIN, CONF_THRESHOLD, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.helpers import get_variable, global_ns
|
||||
from esphomeyaml.cpp_generator import get_variable
|
||||
from esphomeyaml.cpp_types import global_ns
|
||||
from esphomeyaml.pins import validate_gpio_pin
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
@@ -4,8 +4,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import binary_sensor
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN
|
||||
from esphomeyaml.helpers import App, gpio_input_pin_expression, variable, Application, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import Application, Component, App
|
||||
|
||||
MakeGPIOBinarySensor = Application.struct('MakeGPIOBinarySensor')
|
||||
GPIOBinarySensorComponent = binary_sensor.binary_sensor_ns.class_('GPIOBinarySensorComponent',
|
||||
|
||||
@@ -4,7 +4,7 @@ from esphomeyaml.components import binary_sensor, display
|
||||
from esphomeyaml.components.display.nextion import Nextion
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_COMPONENT_ID, CONF_NAME, CONF_PAGE_ID
|
||||
from esphomeyaml.helpers import get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable
|
||||
|
||||
DEPENDENCIES = ['display']
|
||||
|
||||
@@ -22,7 +22,6 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
|
||||
|
||||
|
||||
def to_code(config):
|
||||
hub = None
|
||||
for hub in get_variable(config[CONF_NEXTION_ID]):
|
||||
yield
|
||||
rhs = hub.make_touch_component(config[CONF_NAME], config[CONF_PAGE_ID],
|
||||
|
||||
@@ -5,7 +5,7 @@ from esphomeyaml.components import binary_sensor
|
||||
from esphomeyaml.components.pn532 import PN532Component
|
||||
from esphomeyaml.const import CONF_NAME, CONF_UID
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.helpers import ArrayInitializer, get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable, ArrayInitializer
|
||||
|
||||
DEPENDENCIES = ['pn532']
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import voluptuous as vol
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import binary_sensor, rdm6300
|
||||
from esphomeyaml.const import CONF_NAME, CONF_UID
|
||||
from esphomeyaml.helpers import get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable
|
||||
|
||||
DEPENDENCIES = ['rdm6300']
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from esphomeyaml.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAN
|
||||
CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, \
|
||||
CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_SAMSUNG, CONF_SONY, \
|
||||
CONF_STATE
|
||||
from esphomeyaml.helpers import ArrayInitializer, Pvariable, get_variable
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, get_variable, Pvariable
|
||||
|
||||
DEPENDENCIES = ['remote_receiver']
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import binary_sensor
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, Component, App
|
||||
|
||||
DEPENDENCIES = ['mqtt']
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import binary_sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME
|
||||
from esphomeyaml.helpers import App, Application, add, bool_, optional, process_lambda, variable, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import variable, process_lambda, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, Component, App, optional, bool_
|
||||
|
||||
MakeTemplateBinarySensor = Application.struct('MakeTemplateBinarySensor')
|
||||
TemplateBinarySensor = binary_sensor.binary_sensor_ns.class_('TemplateBinarySensor',
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY
|
||||
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_MQTT_ID, CONF_INTERNAL
|
||||
from esphomeyaml.helpers import Pvariable, esphomelib_ns, setup_mqtt_component, add, \
|
||||
TemplateArguments, get_variable, Action, Nameable
|
||||
from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable
|
||||
from esphomeyaml.cpp_types import Action, Nameable, esphomelib_ns
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -54,8 +55,7 @@ COVER_OPEN_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_COVER_OPEN, COVER_OPEN_ACTION_SCHEMA)
|
||||
def cover_open_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def cover_open_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_open_action(template_arg)
|
||||
@@ -70,8 +70,7 @@ COVER_CLOSE_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_COVER_CLOSE, COVER_CLOSE_ACTION_SCHEMA)
|
||||
def cover_close_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def cover_close_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_close_action(template_arg)
|
||||
@@ -86,8 +85,7 @@ COVER_STOP_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_COVER_STOP, COVER_STOP_ACTION_SCHEMA)
|
||||
def cover_stop_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def cover_stop_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_stop_action(template_arg)
|
||||
|
||||
@@ -5,8 +5,9 @@ from esphomeyaml import automation
|
||||
from esphomeyaml.components import cover
|
||||
from esphomeyaml.const import CONF_CLOSE_ACTION, CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, \
|
||||
CONF_OPEN_ACTION, CONF_STOP_ACTION, CONF_OPTIMISTIC
|
||||
from esphomeyaml.helpers import App, Application, NoArg, add, process_lambda, variable, optional, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_generator import variable, process_lambda, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, App, optional, NoArg
|
||||
|
||||
MakeTemplateCover = Application.struct('MakeTemplateCover')
|
||||
TemplateCover = cover.cover_ns.class_('TemplateCover', cover.Cover)
|
||||
|
||||
32
esphomeyaml/components/custom_component.py
Normal file
32
esphomeyaml/components/custom_component.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_COMPONENTS
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Component, ComponentPtr, esphomelib_ns, std_vector
|
||||
|
||||
CustomComponentConstructor = esphomelib_ns.class_('CustomComponentConstructor')
|
||||
MULTI_CONF = True
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomComponentConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Optional(CONF_COMPONENTS): vol.All(cv.ensure_list, [vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(Component)
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)]),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(ComponentPtr)):
|
||||
yield
|
||||
|
||||
rhs = CustomComponentConstructor(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, comp in enumerate(config.get(CONF_COMPONENTS, [])):
|
||||
setup_component(custom.get_component(i), comp)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_COMPONENT'
|
||||
@@ -1,25 +1,27 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_PIN, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Pvariable, setup_component, PollingComponent
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DallasComponent = sensor.sensor_ns.class_('DallasComponent', PollingComponent)
|
||||
MULTI_CONF = True
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(DallasComponent),
|
||||
vol.Required(CONF_PIN): pins.input_output_pin,
|
||||
vol.Required(CONF_PIN): pins.input_pullup_pin,
|
||||
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
rhs = App.make_dallas_component(conf[CONF_PIN], conf.get(CONF_UPDATE_INTERVAL))
|
||||
var = Pvariable(conf[CONF_ID], rhs)
|
||||
setup_component(var, conf)
|
||||
rhs = App.make_dallas_component(config[CONF_PIN], config.get(CONF_UPDATE_INTERVAL))
|
||||
var = Pvariable(config[CONF_ID], rhs)
|
||||
setup_component(var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_DALLAS_SENSOR'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.helpers import App, add
|
||||
from esphomeyaml.cpp_generator import add
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
DEPENDENCIES = ['logger']
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml import config_validation as cv, pins
|
||||
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
|
||||
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_RUN_CYCLES, CONF_RUN_DURATION, \
|
||||
CONF_SLEEP_DURATION, CONF_WAKEUP_PIN, CONF_MODE, CONF_PINS
|
||||
from esphomeyaml.helpers import Action, App, Component, Pvariable, TemplateArguments, add, \
|
||||
esphomelib_ns, get_variable, gpio_input_pin_expression, setup_component, global_ns, \
|
||||
StructInitializer
|
||||
from esphomeyaml.const import CONF_ID, CONF_MODE, CONF_NUMBER, CONF_PINS, CONF_RUN_CYCLES, \
|
||||
CONF_RUN_DURATION, CONF_SLEEP_DURATION, CONF_WAKEUP_PIN
|
||||
from esphomeyaml.cpp_generator import Pvariable, StructInitializer, add, get_variable
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import Action, App, Component, esphomelib_ns, global_ns
|
||||
|
||||
|
||||
def validate_pin_number(value):
|
||||
@@ -95,8 +95,7 @@ DEEP_SLEEP_ENTER_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_DEEP_SLEEP_ENTER, DEEP_SLEEP_ENTER_ACTION_SCHEMA)
|
||||
def deep_sleep_enter_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def deep_sleep_enter_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_enter_deep_sleep_action(template_arg)
|
||||
@@ -111,8 +110,7 @@ DEEP_SLEEP_PREVENT_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_DEEP_SLEEP_PREVENT, DEEP_SLEEP_PREVENT_ACTION_SCHEMA)
|
||||
def deep_sleep_prevent_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def deep_sleep_prevent_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_prevent_deep_sleep_action(template_arg)
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_LAMBDA, CONF_ROTATION, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import add, add_job, esphomelib_ns
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import add
|
||||
from esphomeyaml.cpp_types import esphomelib_ns
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -50,7 +52,7 @@ def setup_display_core_(display_var, config):
|
||||
|
||||
|
||||
def setup_display(display_var, config):
|
||||
add_job(setup_display_core_, display_var, config)
|
||||
CORE.add_job(setup_display_core_, display_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_DISPLAY'
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import display
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_DATA_PINS, CONF_DIMENSIONS, CONF_ENABLE_PIN, CONF_ID, \
|
||||
CONF_LAMBDA, CONF_RS_PIN, CONF_RW_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, add, gpio_output_pin_expression, process_lambda, \
|
||||
setup_component, PollingComponent
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, process_lambda
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
LCDDisplay = display.display_ns.class_('LCDDisplay', PollingComponent)
|
||||
LCDDisplayRef = LCDDisplay.operator('ref')
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import display, i2c
|
||||
from esphomeyaml.components.display.lcd_gpio import LCDDisplayRef, validate_lcd_dimensions, \
|
||||
LCDDisplay
|
||||
from esphomeyaml.components.display.lcd_gpio import LCDDisplay, LCDDisplayRef, \
|
||||
validate_lcd_dimensions
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_DIMENSIONS, CONF_ID, CONF_LAMBDA
|
||||
from esphomeyaml.helpers import App, Pvariable, add, process_lambda, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, process_lambda
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import display, spi
|
||||
from esphomeyaml.components.spi import SPIComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_NUM_CHIPS, \
|
||||
CONF_SPI_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, add, get_variable, gpio_output_pin_expression, \
|
||||
process_lambda, setup_component, PollingComponent
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ from esphomeyaml.components import display, uart
|
||||
from esphomeyaml.components.uart import UARTComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_UART_ID
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, add, get_variable, \
|
||||
process_lambda, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import display
|
||||
from esphomeyaml.components.display import ssd1306_spi
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_EXTERNAL_VCC, CONF_ID, \
|
||||
CONF_MODEL, CONF_RESET_PIN, CONF_LAMBDA
|
||||
from esphomeyaml.helpers import App, Pvariable, add, \
|
||||
gpio_output_pin_expression, process_lambda, setup_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_EXTERNAL_VCC, CONF_ID, CONF_LAMBDA, CONF_MODEL, \
|
||||
CONF_RESET_PIN
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, process_lambda
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import display, spi
|
||||
from esphomeyaml.components.spi import SPIComponent
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_DC_PIN, CONF_EXTERNAL_VCC, \
|
||||
CONF_ID, CONF_MODEL, \
|
||||
CONF_RESET_PIN, CONF_SPI_ID, CONF_LAMBDA
|
||||
from esphomeyaml.helpers import App, Pvariable, add, get_variable, \
|
||||
gpio_output_pin_expression, process_lambda, setup_component, PollingComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_DC_PIN, CONF_EXTERNAL_VCC, CONF_ID, CONF_LAMBDA, \
|
||||
CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ from esphomeyaml.components import display, spi
|
||||
from esphomeyaml.components.spi import SPIComponent
|
||||
from esphomeyaml.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_FULL_UPDATE_EVERY, \
|
||||
CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, add, get_variable, gpio_input_pin_expression, \
|
||||
gpio_output_pin_expression, process_lambda, setup_component, PollingComponent
|
||||
from esphomeyaml.cpp_generator import get_variable, Pvariable, process_lambda, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, gpio_input_pin_expression, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_types import PollingComponent, App
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml import config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_SCAN_INTERVAL, CONF_TYPE, CONF_UUID, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, Component, Pvariable, RawExpression, add, \
|
||||
esphomelib_ns, setup_component
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, RawExpression, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ from esphomeyaml import config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, ArrayInitializer, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml import config_validation as cv
|
||||
from esphomeyaml.components import binary_sensor
|
||||
from esphomeyaml.const import CONF_ID, CONF_SETUP_MODE, CONF_IIR_FILTER, \
|
||||
CONF_SLEEP_DURATION, CONF_MEASUREMENT_DURATION, CONF_LOW_VOLTAGE_REFERENCE, \
|
||||
CONF_HIGH_VOLTAGE_REFERENCE, CONF_VOLTAGE_ATTENUATION, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.const import CONF_HIGH_VOLTAGE_REFERENCE, CONF_ID, CONF_IIR_FILTER, \
|
||||
CONF_LOW_VOLTAGE_REFERENCE, CONF_MEASUREMENT_DURATION, CONF_SETUP_MODE, CONF_SLEEP_DURATION, \
|
||||
CONF_VOLTAGE_ATTENUATION, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.core import TimePeriod
|
||||
from esphomeyaml.helpers import App, Pvariable, add, global_ns, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, global_ns
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
@@ -19,6 +21,7 @@ def validate_voltage(values):
|
||||
if not value.endswith('V'):
|
||||
value += 'V'
|
||||
return cv.one_of(*values)(value)
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY
|
||||
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_MQTT_ID, CONF_OSCILLATION_COMMAND_TOPIC, \
|
||||
CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC, CONF_INTERNAL, \
|
||||
CONF_SPEED, CONF_OSCILLATING, CONF_OSCILLATION_OUTPUT, CONF_NAME
|
||||
from esphomeyaml.helpers import Application, Pvariable, add, esphomelib_ns, setup_mqtt_component, \
|
||||
TemplateArguments, get_variable, templatable, bool_, Action, Nameable, Component
|
||||
from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_NAME, CONF_OSCILLATING, \
|
||||
CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_OUTPUT, CONF_OSCILLATION_STATE_TOPIC, \
|
||||
CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC
|
||||
from esphomeyaml.cpp_generator import add, Pvariable, get_variable, templatable
|
||||
from esphomeyaml.cpp_types import Application, Component, Nameable, esphomelib_ns, Action, bool_
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -38,7 +39,6 @@ FAN_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
|
||||
|
||||
FAN_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(FAN_SCHEMA.schema)
|
||||
|
||||
|
||||
FAN_SPEEDS = {
|
||||
'OFF': FAN_SPEED_OFF,
|
||||
'LOW': FAN_SPEED_LOW,
|
||||
@@ -70,7 +70,6 @@ def setup_fan(fan_obj, mqtt_obj, config):
|
||||
|
||||
BUILD_FLAGS = '-DUSE_FAN'
|
||||
|
||||
|
||||
CONF_FAN_TOGGLE = 'fan.toggle'
|
||||
FAN_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(FanState),
|
||||
@@ -78,8 +77,7 @@ FAN_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_FAN_TOGGLE, FAN_TOGGLE_ACTION_SCHEMA)
|
||||
def fan_toggle_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def fan_toggle_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_toggle_action(template_arg)
|
||||
@@ -94,8 +92,7 @@ FAN_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_FAN_TURN_OFF, FAN_TURN_OFF_ACTION_SCHEMA)
|
||||
def fan_turn_off_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def fan_turn_off_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_off_action(template_arg)
|
||||
@@ -112,8 +109,7 @@ FAN_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_FAN_TURN_ON, FAN_TURN_ON_ACTION_SCHEMA)
|
||||
def fan_turn_on_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def fan_turn_on_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_on_action(template_arg)
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import fan, output
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT
|
||||
from esphomeyaml.helpers import App, add, get_variable, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import get_variable, variable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(fan.MakeFan),
|
||||
|
||||
@@ -5,7 +5,8 @@ from esphomeyaml.components import fan, mqtt, output
|
||||
from esphomeyaml.const import CONF_HIGH, CONF_LOW, CONF_MAKE_ID, CONF_MEDIUM, CONF_NAME, \
|
||||
CONF_OSCILLATION_OUTPUT, CONF_OUTPUT, CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, \
|
||||
CONF_SPEED_STATE_TOPIC
|
||||
from esphomeyaml.helpers import App, add, get_variable, variable
|
||||
from esphomeyaml.cpp_generator import get_variable, variable, add
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(fan.MakeFan),
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
# coding=utf-8
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.components import display
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_FILE, CONF_GLYPHS, CONF_ID, CONF_SIZE
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, MockObj, Pvariable, RawExpression, add, \
|
||||
relative_path
|
||||
from esphomeyaml.core import CORE, HexInt
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawExpression, add
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
DEPENDENCIES = ['display']
|
||||
MULTI_CONF = True
|
||||
|
||||
Font = display.display_ns.class_('Font')
|
||||
Glyph = display.display_ns.class_('Glyph')
|
||||
@@ -76,46 +77,45 @@ FONT_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.All(validate_pillow_installed, cv.ensure_list, [FONT_SCHEMA])
|
||||
CONFIG_SCHEMA = vol.All(validate_pillow_installed, FONT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
from PIL import ImageFont
|
||||
|
||||
for conf in config:
|
||||
path = relative_path(conf[CONF_FILE])
|
||||
try:
|
||||
font = ImageFont.truetype(path, conf[CONF_SIZE])
|
||||
except Exception as e:
|
||||
raise core.ESPHomeYAMLError(u"Could not load truetype file {}: {}".format(path, e))
|
||||
path = CORE.relative_path(config[CONF_FILE])
|
||||
try:
|
||||
font = ImageFont.truetype(path, config[CONF_SIZE])
|
||||
except Exception as e:
|
||||
raise core.EsphomeyamlError(u"Could not load truetype file {}: {}".format(path, e))
|
||||
|
||||
ascent, descent = font.getmetrics()
|
||||
ascent, descent = font.getmetrics()
|
||||
|
||||
glyph_args = {}
|
||||
data = []
|
||||
for glyph in conf[CONF_GLYPHS]:
|
||||
mask = font.getmask(glyph, mode='1')
|
||||
_, (offset_x, offset_y) = font.font.getsize(glyph)
|
||||
width, height = mask.size
|
||||
width8 = ((width + 7) // 8) * 8
|
||||
glyph_data = [0 for _ in range(height * width8 // 8)] # noqa: F812
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if not mask.getpixel((x, y)):
|
||||
continue
|
||||
pos = x + y * width8
|
||||
glyph_data[pos // 8] |= 0x80 >> (pos % 8)
|
||||
glyph_args[glyph] = (len(data), offset_x, offset_y, width, height)
|
||||
data += glyph_data
|
||||
glyph_args = {}
|
||||
data = []
|
||||
for glyph in config[CONF_GLYPHS]:
|
||||
mask = font.getmask(glyph, mode='1')
|
||||
_, (offset_x, offset_y) = font.font.getsize(glyph)
|
||||
width, height = mask.size
|
||||
width8 = ((width + 7) // 8) * 8
|
||||
glyph_data = [0 for _ in range(height * width8 // 8)] # noqa: F812
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if not mask.getpixel((x, y)):
|
||||
continue
|
||||
pos = x + y * width8
|
||||
glyph_data[pos // 8] |= 0x80 >> (pos % 8)
|
||||
glyph_args[glyph] = (len(data), offset_x, offset_y, width, height)
|
||||
data += glyph_data
|
||||
|
||||
raw_data = MockObj(conf[CONF_RAW_DATA_ID])
|
||||
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
||||
raw_data, len(data),
|
||||
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
||||
raw_data = MockObj(config[CONF_RAW_DATA_ID])
|
||||
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
||||
raw_data, len(data),
|
||||
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
||||
|
||||
glyphs = []
|
||||
for glyph in conf[CONF_GLYPHS]:
|
||||
glyphs.append(Glyph(glyph, raw_data, *glyph_args[glyph]))
|
||||
glyphs = []
|
||||
for glyph in config[CONF_GLYPHS]:
|
||||
glyphs.append(Glyph(glyph, raw_data, *glyph_args[glyph]))
|
||||
|
||||
rhs = App.make_font(ArrayInitializer(*glyphs), ascent, ascent + descent)
|
||||
Pvariable(conf[CONF_ID], rhs)
|
||||
rhs = App.make_font(ArrayInitializer(*glyphs), ascent, ascent + descent)
|
||||
Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
@@ -2,34 +2,34 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml import config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, CONF_TYPE
|
||||
from esphomeyaml.helpers import App, Component, Pvariable, RawExpression, TemplateArguments, add, \
|
||||
esphomelib_ns, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, RawExpression, TemplateArguments, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
GlobalVariableComponent = esphomelib_ns.class_('GlobalVariableComponent', Component)
|
||||
|
||||
GLOBAL_VAR_SCHEMA = vol.Schema({
|
||||
MULTI_CONF = True
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(GlobalVariableComponent),
|
||||
vol.Required(CONF_TYPE): cv.string_strict,
|
||||
vol.Optional(CONF_INITIAL_VALUE): cv.string_strict,
|
||||
vol.Optional(CONF_RESTORE_VALUE): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [GLOBAL_VAR_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
type_ = RawExpression(conf[CONF_TYPE])
|
||||
template_args = TemplateArguments(type_)
|
||||
res_type = GlobalVariableComponent.template(template_args)
|
||||
initial_value = None
|
||||
if CONF_INITIAL_VALUE in conf:
|
||||
initial_value = RawExpression(conf[CONF_INITIAL_VALUE])
|
||||
rhs = App.Pmake_global_variable(template_args, initial_value)
|
||||
glob = Pvariable(conf[CONF_ID], rhs, type=res_type)
|
||||
type_ = RawExpression(config[CONF_TYPE])
|
||||
template_args = TemplateArguments(type_)
|
||||
res_type = GlobalVariableComponent.template(template_args)
|
||||
initial_value = None
|
||||
if CONF_INITIAL_VALUE in config:
|
||||
initial_value = RawExpression(config[CONF_INITIAL_VALUE])
|
||||
rhs = App.Pmake_global_variable(template_args, initial_value)
|
||||
glob = Pvariable(config[CONF_ID], rhs, type=res_type)
|
||||
|
||||
if conf.get(CONF_RESTORE_VALUE, False):
|
||||
hash_ = hash(conf[CONF_ID].id) % 2**32
|
||||
add(glob.set_restore_value(hash_))
|
||||
if config.get(CONF_RESTORE_VALUE, False):
|
||||
hash_ = hash(config[CONF_ID].id) % 2**32
|
||||
add(glob.set_restore_value(hash_))
|
||||
|
||||
setup_component(glob, conf)
|
||||
setup_component(glob, config)
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.const import CONF_FREQUENCY, CONF_SCL, CONF_SDA, CONF_SCAN, CONF_ID, \
|
||||
CONF_RECEIVE_TIMEOUT
|
||||
from esphomeyaml.helpers import App, add, Pvariable, esphomelib_ns, setup_component, Component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_FREQUENCY, CONF_ID, CONF_RECEIVE_TIMEOUT, CONF_SCAN, CONF_SCL, \
|
||||
CONF_SDA
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
I2CComponent = esphomelib_ns.class_('I2CComponent', Component)
|
||||
I2CDevice = pins.I2CDevice
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(I2CComponent),
|
||||
vol.Required(CONF_SDA, default='SDA'): pins.input_output_pin,
|
||||
vol.Required(CONF_SCL, default='SCL'): pins.input_output_pin,
|
||||
vol.Optional(CONF_SDA, default='SDA'): pins.input_pullup_pin,
|
||||
vol.Optional(CONF_SCL, default='SCL'): pins.input_pullup_pin,
|
||||
vol.Optional(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=0, min_included=False)),
|
||||
vol.Optional(CONF_SCAN): cv.boolean,
|
||||
|
||||
|
||||
@@ -3,17 +3,18 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.components import display, font
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_FILE, CONF_ID, CONF_RESIZE
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, MockObj, Pvariable, RawExpression, add, \
|
||||
relative_path
|
||||
from esphomeyaml.core import CORE, HexInt
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawExpression, add
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['display']
|
||||
MULTI_CONF = True
|
||||
|
||||
Image_ = display.display_ns.class_('Image')
|
||||
|
||||
@@ -26,40 +27,39 @@ IMAGE_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.All(font.validate_pillow_installed, cv.ensure_list, [IMAGE_SCHEMA])
|
||||
CONFIG_SCHEMA = vol.All(font.validate_pillow_installed, IMAGE_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
from PIL import Image
|
||||
|
||||
for conf in config:
|
||||
path = relative_path(conf[CONF_FILE])
|
||||
try:
|
||||
image = Image.open(path)
|
||||
except Exception as e:
|
||||
raise core.ESPHomeYAMLError(u"Could not load image file {}: {}".format(path, e))
|
||||
path = CORE.relative_path(config[CONF_FILE])
|
||||
try:
|
||||
image = Image.open(path)
|
||||
except Exception as e:
|
||||
raise core.EsphomeyamlError(u"Could not load image file {}: {}".format(path, e))
|
||||
|
||||
if CONF_RESIZE in conf:
|
||||
image.thumbnail(conf[CONF_RESIZE])
|
||||
if CONF_RESIZE in config:
|
||||
image.thumbnail(config[CONF_RESIZE])
|
||||
|
||||
image = image.convert('1', dither=Image.NONE)
|
||||
width, height = image.size
|
||||
if width > 500 or height > 500:
|
||||
_LOGGER.warning("The image you requested is very big. Please consider using the resize "
|
||||
"parameter")
|
||||
width8 = ((width + 7) // 8) * 8
|
||||
data = [0 for _ in range(height * width8 // 8)]
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if image.getpixel((x, y)):
|
||||
continue
|
||||
pos = x + y * width8
|
||||
data[pos // 8] |= 0x80 >> (pos % 8)
|
||||
image = image.convert('1', dither=Image.NONE)
|
||||
width, height = image.size
|
||||
if width > 500 or height > 500:
|
||||
_LOGGER.warning("The image you requested is very big. Please consider using the resize "
|
||||
"parameter")
|
||||
width8 = ((width + 7) // 8) * 8
|
||||
data = [0 for _ in range(height * width8 // 8)]
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if image.getpixel((x, y)):
|
||||
continue
|
||||
pos = x + y * width8
|
||||
data[pos // 8] |= 0x80 >> (pos % 8)
|
||||
|
||||
raw_data = MockObj(conf[CONF_RAW_DATA_ID])
|
||||
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
||||
raw_data, len(data),
|
||||
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
||||
raw_data = MockObj(config[CONF_RAW_DATA_ID])
|
||||
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
||||
raw_data, len(data),
|
||||
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
||||
|
||||
rhs = App.make_image(raw_data, width, height)
|
||||
Pvariable(conf[CONF_ID], rhs)
|
||||
rhs = App.make_image(raw_data, width, height)
|
||||
Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
@@ -2,15 +2,19 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLORS, \
|
||||
CONF_COLOR_TEMPERATURE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_DURATION, CONF_EFFECT, \
|
||||
CONF_EFFECTS, CONF_EFFECT_ID, CONF_FLASH_LENGTH, CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, \
|
||||
CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, \
|
||||
CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH
|
||||
from esphomeyaml.helpers import Action, Application, ArrayInitializer, Component, Nameable, \
|
||||
Pvariable, StructInitializer, TemplateArguments, add, add_job, esphomelib_ns, float_, \
|
||||
get_variable, process_lambda, setup_mqtt_component, std_string, templatable, uint32
|
||||
CONF_DEFAULT_TRANSITION_LENGTH, CONF_DURATION, CONF_EFFECTS, CONF_EFFECT_ID, \
|
||||
CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, \
|
||||
CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, \
|
||||
CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH, CONF_FLASH_LENGTH, CONF_COLOR_TEMPERATURE, \
|
||||
CONF_EFFECT
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import process_lambda, Pvariable, add, StructInitializer, \
|
||||
ArrayInitializer, get_variable, templatable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Application, Component, Nameable, Action, uint32, \
|
||||
float_, std_string
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -173,26 +177,35 @@ EFFECTS_SCHEMA = vol.Schema({
|
||||
|
||||
def validate_effects(allowed_effects):
|
||||
def validator(value):
|
||||
is_list = isinstance(value, list)
|
||||
value = cv.ensure_list(value)
|
||||
names = set()
|
||||
ret = []
|
||||
for i, effect in enumerate(value):
|
||||
path = [i] if is_list else []
|
||||
if not isinstance(effect, dict):
|
||||
raise vol.Invalid("Each effect must be a dictionary, not {}".format(type(value)))
|
||||
raise vol.Invalid("Each effect must be a dictionary, not {}".format(type(value)),
|
||||
path)
|
||||
if len(effect) > 1:
|
||||
raise vol.Invalid("Each entry in the 'effects:' option must be a single effect.")
|
||||
raise vol.Invalid("Each entry in the 'effects:' option must be a single effect.",
|
||||
path)
|
||||
if not effect:
|
||||
raise vol.Invalid("Found no effect for the {}th entry in 'effects:'!".format(i))
|
||||
raise vol.Invalid("Found no effect for the {}th entry in 'effects:'!".format(i),
|
||||
path)
|
||||
key = next(iter(effect.keys()))
|
||||
if key not in allowed_effects:
|
||||
raise vol.Invalid("The effect '{}' does not exist or is not allowed for this "
|
||||
"light type".format(key))
|
||||
"light type".format(key), path)
|
||||
effect[key] = effect[key] or {}
|
||||
conf = EFFECTS_SCHEMA(effect)
|
||||
try:
|
||||
conf = EFFECTS_SCHEMA(effect)
|
||||
except vol.Invalid as err:
|
||||
err.prepend(path)
|
||||
raise err
|
||||
name = conf[key][CONF_NAME]
|
||||
if name in names:
|
||||
raise vol.Invalid(u"Found the effect name '{}' twice. All effects must have "
|
||||
u"unique names".format(name))
|
||||
u"unique names".format(name), [i])
|
||||
names.add(name)
|
||||
ret.append(conf)
|
||||
return ret
|
||||
@@ -346,7 +359,7 @@ def setup_light_core_(light_var, mqtt_var, config):
|
||||
def setup_light(light_obj, mqtt_obj, config):
|
||||
light_var = Pvariable(config[CONF_ID], light_obj, has_side_effects=False)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
|
||||
add_job(setup_light_core_, light_var, mqtt_var, config)
|
||||
CORE.add_job(setup_light_core_, light_var, mqtt_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_LIGHT'
|
||||
@@ -359,8 +372,7 @@ LIGHT_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_LIGHT_TOGGLE, LIGHT_TOGGLE_ACTION_SCHEMA)
|
||||
def light_toggle_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def light_toggle_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_toggle_action(template_arg)
|
||||
@@ -381,8 +393,7 @@ LIGHT_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_LIGHT_TURN_OFF, LIGHT_TURN_OFF_ACTION_SCHEMA)
|
||||
def light_turn_off_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def light_turn_off_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_off_action(template_arg)
|
||||
@@ -413,8 +424,7 @@ LIGHT_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_LIGHT_TURN_ON, LIGHT_TURN_ON_ACTION_SCHEMA)
|
||||
def light_turn_on_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def light_turn_on_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_on_action(template_arg)
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import light, output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_EFFECTS, CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
|
||||
from esphomeyaml.helpers import App, get_variable, setup_component, variable
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
|
||||
|
||||
@@ -7,7 +7,9 @@ from esphomeyaml.components.light.rgbww import validate_cold_white_colder, \
|
||||
from esphomeyaml.const import CONF_COLD_WHITE, CONF_COLD_WHITE_COLOR_TEMPERATURE, \
|
||||
CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_MAKE_ID, \
|
||||
CONF_NAME, CONF_WARM_WHITE, CONF_WARM_WHITE_COLOR_TEMPERATURE
|
||||
from esphomeyaml.helpers import App, get_variable, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import light
|
||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
|
||||
from esphomeyaml.const import CONF_CHIPSET, CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, \
|
||||
CONF_MAKE_ID, CONF_MAX_REFRESH_RATE, CONF_NAME, CONF_NUM_LEDS, CONF_PIN, CONF_POWER_SUPPLY, \
|
||||
CONF_RGB_ORDER, CONF_EFFECTS, CONF_COLOR_CORRECT
|
||||
from esphomeyaml.helpers import App, Application, RawExpression, TemplateArguments, add, \
|
||||
get_variable, variable, setup_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CHIPSET, CONF_COLOR_CORRECT, CONF_DEFAULT_TRANSITION_LENGTH, \
|
||||
CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_MAKE_ID, CONF_MAX_REFRESH_RATE, CONF_NAME, \
|
||||
CONF_NUM_LEDS, CONF_PIN, CONF_POWER_SUPPLY, CONF_RGB_ORDER
|
||||
from esphomeyaml.cpp_generator import RawExpression, TemplateArguments, add, get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
TYPES = [
|
||||
'NEOPIXEL',
|
||||
@@ -103,6 +104,8 @@ def to_code(config):
|
||||
|
||||
BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT'
|
||||
|
||||
LIB_DEPS = 'FastLED@3.2.0'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False,
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import light
|
||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
|
||||
from esphomeyaml.const import CONF_CHIPSET, CONF_CLOCK_PIN, CONF_DATA_PIN, \
|
||||
CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, CONF_MAKE_ID, CONF_MAX_REFRESH_RATE, \
|
||||
CONF_NAME, CONF_NUM_LEDS, CONF_POWER_SUPPLY, CONF_RGB_ORDER, CONF_EFFECTS, CONF_COLOR_CORRECT
|
||||
from esphomeyaml.helpers import App, Application, RawExpression, TemplateArguments, add, \
|
||||
get_variable, variable, setup_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CHIPSET, CONF_CLOCK_PIN, CONF_COLOR_CORRECT, CONF_DATA_PIN, \
|
||||
CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_MAKE_ID, \
|
||||
CONF_MAX_REFRESH_RATE, CONF_NAME, CONF_NUM_LEDS, CONF_POWER_SUPPLY, CONF_RGB_ORDER
|
||||
from esphomeyaml.cpp_generator import RawExpression, TemplateArguments, add, get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
CHIPSETS = [
|
||||
'LPD8806',
|
||||
@@ -83,6 +84,8 @@ def to_code(config):
|
||||
|
||||
BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT'
|
||||
|
||||
LIB_DEPS = 'FastLED@3.2.0'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False,
|
||||
|
||||
@@ -4,7 +4,9 @@ from esphomeyaml.components import light, output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, \
|
||||
CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
|
||||
from esphomeyaml.helpers import App, get_variable, setup_component, variable
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import light, output
|
||||
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, \
|
||||
CONF_GREEN, CONF_MAKE_ID, CONF_NAME, CONF_RED, CONF_EFFECTS
|
||||
from esphomeyaml.helpers import App, get_variable, variable, setup_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, \
|
||||
CONF_GAMMA_CORRECT, CONF_GREEN, CONF_MAKE_ID, CONF_NAME, CONF_RED
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import light, output
|
||||
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, \
|
||||
CONF_GREEN, CONF_MAKE_ID, CONF_NAME, CONF_RED, CONF_WHITE, CONF_EFFECTS
|
||||
from esphomeyaml.helpers import App, get_variable, variable, setup_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, \
|
||||
CONF_GAMMA_CORRECT, CONF_GREEN, CONF_MAKE_ID, CONF_NAME, CONF_RED, CONF_WHITE
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import light, output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BLUE, CONF_COLD_WHITE, CONF_COLD_WHITE_COLOR_TEMPERATURE, \
|
||||
CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_GREEN, CONF_MAKE_ID, \
|
||||
CONF_NAME, CONF_RED, CONF_WARM_WHITE, CONF_WARM_WHITE_COLOR_TEMPERATURE
|
||||
from esphomeyaml.helpers import App, get_variable, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
|
||||
def validate_color_temperature(value):
|
||||
|
||||
@@ -6,9 +6,9 @@ from esphomeyaml.automation import ACTION_REGISTRY, LambdaAction
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ARGS, CONF_BAUD_RATE, CONF_FORMAT, CONF_ID, CONF_LEVEL, \
|
||||
CONF_LOGS, CONF_TAG, CONF_TX_BUFFER_SIZE
|
||||
from esphomeyaml.core import ESPHomeYAMLError, Lambda
|
||||
from esphomeyaml.helpers import App, Pvariable, RawExpression, TemplateArguments, add, \
|
||||
esphomelib_ns, global_ns, process_lambda, statement, Component
|
||||
from esphomeyaml.core import EsphomeyamlError, Lambda
|
||||
from esphomeyaml.cpp_generator import Pvariable, RawExpression, add, process_lambda, statement
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns
|
||||
|
||||
LOG_LEVELS = {
|
||||
'NONE': global_ns.ESPHOMELIB_LOG_LEVEL_NONE,
|
||||
@@ -39,7 +39,7 @@ def validate_local_no_higher_than_global(value):
|
||||
global_level = value.get(CONF_LEVEL, 'DEBUG')
|
||||
for tag, level in value.get(CONF_LOGS, {}).iteritems():
|
||||
if LOG_LEVEL_SEVERITY.index(level) > LOG_LEVEL_SEVERITY.index(global_level):
|
||||
raise ESPHomeYAMLError(u"The local log level {} for {} must be less severe than the "
|
||||
raise EsphomeyamlError(u"The local log level {} for {} must be less severe than the "
|
||||
u"global log level {}.".format(level, tag, global_level))
|
||||
return value
|
||||
|
||||
@@ -115,8 +115,7 @@ LOGGER_LOG_ACTION_SCHEMA = vol.All(maybe_simple_message({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_LOGGER_LOG, LOGGER_LOG_ACTION_SCHEMA)
|
||||
def logger_log_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def logger_log_action_to_code(config, action_id, arg_type, template_arg):
|
||||
esp_log = LOG_LEVEL_TO_ESP_LOG[config[CONF_LEVEL]]
|
||||
args = [RawExpression(unicode(x)) for x in config[CONF_ARGS]]
|
||||
|
||||
|
||||
@@ -7,17 +7,18 @@ from esphomeyaml import automation
|
||||
from esphomeyaml.automation import ACTION_REGISTRY
|
||||
from esphomeyaml.components import logger
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BIRTH_MESSAGE, CONF_BROKER, CONF_CLIENT_ID, CONF_DISCOVERY, \
|
||||
CONF_DISCOVERY_PREFIX, CONF_DISCOVERY_RETAIN, CONF_ID, CONF_KEEPALIVE, CONF_LEVEL, \
|
||||
CONF_LOG_TOPIC, CONF_ON_MESSAGE, CONF_PASSWORD, CONF_PAYLOAD, CONF_PORT, CONF_QOS, \
|
||||
CONF_REBOOT_TIMEOUT, CONF_RETAIN, CONF_SHUTDOWN_MESSAGE, CONF_SSL_FINGERPRINTS, CONF_TOPIC, \
|
||||
CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, CONF_WILL_MESSAGE, CONF_ON_JSON_MESSAGE, \
|
||||
CONF_STATE_TOPIC, CONF_MQTT, CONF_ESPHOMEYAML, CONF_NAME, CONF_AVAILABILITY, \
|
||||
CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_INTERNAL
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, RawExpression, \
|
||||
StructInitializer, TemplateArguments, add, esphomelib_ns, optional, std_string, templatable, \
|
||||
uint8, bool_, JsonObjectRef, process_lambda, JsonObjectConstRef, Component, Action, Trigger
|
||||
from esphomeyaml.const import CONF_AVAILABILITY, CONF_BIRTH_MESSAGE, CONF_BROKER, CONF_CLIENT_ID, \
|
||||
CONF_COMMAND_TOPIC, CONF_DISCOVERY, CONF_DISCOVERY_PREFIX, CONF_DISCOVERY_RETAIN, \
|
||||
CONF_ESPHOMEYAML, CONF_ID, CONF_INTERNAL, CONF_KEEPALIVE, CONF_LEVEL, CONF_LOG_TOPIC, \
|
||||
CONF_MQTT, CONF_NAME, CONF_ON_JSON_MESSAGE, CONF_ON_MESSAGE, CONF_PASSWORD, CONF_PAYLOAD, \
|
||||
CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_PORT, CONF_QOS, CONF_REBOOT_TIMEOUT, \
|
||||
CONF_RETAIN, CONF_SHUTDOWN_MESSAGE, CONF_SSL_FINGERPRINTS, CONF_STATE_TOPIC, CONF_TOPIC, \
|
||||
CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, CONF_WILL_MESSAGE
|
||||
from esphomeyaml.core import EsphomeyamlError
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, RawExpression, \
|
||||
StructInitializer, TemplateArguments, add, process_lambda, templatable
|
||||
from esphomeyaml.cpp_types import Action, App, Component, JsonObjectConstRef, JsonObjectRef, \
|
||||
Trigger, bool_, esphomelib_ns, optional, std_string, uint8
|
||||
|
||||
|
||||
def validate_message_just_topic(value):
|
||||
@@ -48,12 +49,14 @@ MQTTJsonMessageTrigger = mqtt_ns.class_('MQTTJsonMessageTrigger',
|
||||
MQTTComponent = mqtt_ns.class_('MQTTComponent', Component)
|
||||
|
||||
|
||||
def validate_broker(value):
|
||||
value = cv.string_strict(value)
|
||||
if u':' in value:
|
||||
raise vol.Invalid(u"Please specify the port using the port: option")
|
||||
if not value:
|
||||
raise vol.Invalid(u"Broker cannot be empty")
|
||||
def validate_config(value):
|
||||
if CONF_PORT not in value:
|
||||
parts = value[CONF_BROKER].split(u':')
|
||||
if len(parts) == 2:
|
||||
value[CONF_BROKER] = parts[0]
|
||||
value[CONF_PORT] = cv.port(parts[1])
|
||||
else:
|
||||
value[CONF_PORT] = 1883
|
||||
return value
|
||||
|
||||
|
||||
@@ -64,10 +67,10 @@ def validate_fingerprint(value):
|
||||
return value
|
||||
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
CONFIG_SCHEMA = vol.All(vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(MQTTClientComponent),
|
||||
vol.Required(CONF_BROKER): validate_broker,
|
||||
vol.Optional(CONF_PORT, default=1883): cv.port,
|
||||
vol.Required(CONF_BROKER): cv.string_strict,
|
||||
vol.Optional(CONF_PORT): cv.port,
|
||||
vol.Optional(CONF_USERNAME, default=''): cv.string,
|
||||
vol.Optional(CONF_PASSWORD, default=''): cv.string,
|
||||
vol.Optional(CONF_CLIENT_ID): vol.All(cv.string, vol.Length(max=23)),
|
||||
@@ -88,14 +91,15 @@ CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_ON_MESSAGE): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(MQTTMessageTrigger),
|
||||
vol.Required(CONF_TOPIC): cv.subscribe_topic,
|
||||
vol.Optional(CONF_QOS, default=0): cv.mqtt_qos,
|
||||
vol.Optional(CONF_QOS): cv.mqtt_qos,
|
||||
vol.Optional(CONF_PAYLOAD): cv.string_strict,
|
||||
}),
|
||||
vol.Optional(CONF_ON_JSON_MESSAGE): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(MQTTJsonMessageTrigger),
|
||||
vol.Required(CONF_TOPIC): cv.subscribe_topic,
|
||||
vol.Optional(CONF_QOS, default=0): cv.mqtt_qos,
|
||||
}),
|
||||
})
|
||||
}), validate_config)
|
||||
|
||||
|
||||
def exp_mqtt_message(config):
|
||||
@@ -169,8 +173,12 @@ def to_code(config):
|
||||
add(mqtt.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT]))
|
||||
|
||||
for conf in config.get(CONF_ON_MESSAGE, []):
|
||||
rhs = mqtt.make_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
|
||||
rhs = mqtt.make_message_trigger(conf[CONF_TOPIC])
|
||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||
if CONF_QOS in conf:
|
||||
add(trigger.set_qos(conf[CONF_QOS]))
|
||||
if CONF_PAYLOAD in conf:
|
||||
add(trigger.set_payload(conf[CONF_PAYLOAD]))
|
||||
automation.build_automation(trigger, std_string, conf)
|
||||
|
||||
for conf in config.get(CONF_ON_JSON_MESSAGE, []):
|
||||
@@ -189,8 +197,7 @@ MQTT_PUBLISH_ACTION_SCHEMA = vol.Schema({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH, MQTT_PUBLISH_ACTION_SCHEMA)
|
||||
def mqtt_publish_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg):
|
||||
rhs = App.Pget_mqtt_client().Pmake_publish_action(template_arg)
|
||||
type = MQTTPublishAction.template(template_arg)
|
||||
action = Pvariable(action_id, rhs, type=type)
|
||||
@@ -222,8 +229,7 @@ MQTT_PUBLISH_JSON_ACTION_SCHEMA = vol.Schema({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH_JSON, MQTT_PUBLISH_JSON_ACTION_SCHEMA)
|
||||
def mqtt_publish_json_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def mqtt_publish_json_action_to_code(config, action_id, arg_type, template_arg):
|
||||
rhs = App.Pget_mqtt_client().Pmake_publish_json_action(template_arg)
|
||||
type = MQTTPublishJsonAction.template(template_arg)
|
||||
action = Pvariable(action_id, rhs, type=type)
|
||||
@@ -282,7 +288,7 @@ def build_hass_config(data, component_type, config, include_state=True, include_
|
||||
class GenerateHassConfigData(object):
|
||||
def __init__(self, config):
|
||||
if 'mqtt' not in config:
|
||||
raise ESPHomeYAMLError("Cannot generate Home Assistant MQTT config if MQTT is not "
|
||||
raise EsphomeyamlError("Cannot generate Home Assistant MQTT config if MQTT is not "
|
||||
"used!")
|
||||
mqtt = config[CONF_MQTT]
|
||||
self.topic_prefix = mqtt.get(CONF_TOPIC_PREFIX, config[CONF_ESPHOMEYAML][CONF_NAME])
|
||||
@@ -308,3 +314,21 @@ class GenerateHassConfigData(object):
|
||||
CONF_PAYLOAD_AVAILABLE: birth_message[CONF_PAYLOAD],
|
||||
CONF_PAYLOAD_NOT_AVAILABLE: will_message[CONF_PAYLOAD],
|
||||
}
|
||||
|
||||
|
||||
def setup_mqtt_component(obj, config):
|
||||
if CONF_RETAIN in config:
|
||||
add(obj.set_retain(config[CONF_RETAIN]))
|
||||
if not config.get(CONF_DISCOVERY, True):
|
||||
add(obj.disable_discovery())
|
||||
if CONF_STATE_TOPIC in config:
|
||||
add(obj.set_custom_state_topic(config[CONF_STATE_TOPIC]))
|
||||
if CONF_COMMAND_TOPIC in config:
|
||||
add(obj.set_custom_command_topic(config[CONF_COMMAND_TOPIC]))
|
||||
if CONF_AVAILABILITY in config:
|
||||
availability = config[CONF_AVAILABILITY]
|
||||
if not availability:
|
||||
add(obj.disable_availability())
|
||||
else:
|
||||
add(obj.set_availability(availability[CONF_TOPIC], availability[CONF_PAYLOAD_AVAILABLE],
|
||||
availability[CONF_PAYLOAD_NOT_AVAILABLE]))
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.const import (CONF_DATA_PIN, CONF_CLOCK_PIN, CONF_NUM_CHANNELS,
|
||||
CONF_NUM_CHIPS, CONF_BIT_DEPTH, CONF_ID,
|
||||
CONF_UPDATE_ON_BOOT)
|
||||
from esphomeyaml.helpers import (gpio_output_pin_expression, App, Pvariable,
|
||||
add, setup_component, Component)
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import (CONF_BIT_DEPTH, CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID,
|
||||
CONF_NUM_CHANNELS, CONF_NUM_CHIPS, CONF_UPDATE_ON_BOOT)
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component)
|
||||
MULTI_CONF = True
|
||||
|
||||
|
||||
MY9231_SCHEMA = vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent),
|
||||
vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
||||
@@ -24,28 +24,23 @@ MY9231_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [MY9231_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
di = None
|
||||
for di in gpio_output_pin_expression(conf[CONF_DATA_PIN]):
|
||||
yield
|
||||
dcki = None
|
||||
for dcki in gpio_output_pin_expression(conf[CONF_CLOCK_PIN]):
|
||||
yield
|
||||
rhs = App.make_my9231_component(di, dcki)
|
||||
my9231 = Pvariable(conf[CONF_ID], rhs)
|
||||
if CONF_NUM_CHANNELS in conf:
|
||||
add(my9231.set_num_channels(conf[CONF_NUM_CHANNELS]))
|
||||
if CONF_NUM_CHIPS in conf:
|
||||
add(my9231.set_num_chips(conf[CONF_NUM_CHIPS]))
|
||||
if CONF_BIT_DEPTH in conf:
|
||||
add(my9231.set_bit_depth(conf[CONF_BIT_DEPTH]))
|
||||
if CONF_UPDATE_ON_BOOT in conf:
|
||||
add(my9231.set_update(conf[CONF_UPDATE_ON_BOOT]))
|
||||
setup_component(my9231, conf)
|
||||
for di in gpio_output_pin_expression(config[CONF_DATA_PIN]):
|
||||
yield
|
||||
for dcki in gpio_output_pin_expression(config[CONF_CLOCK_PIN]):
|
||||
yield
|
||||
rhs = App.make_my9231_component(di, dcki)
|
||||
my9231 = Pvariable(config[CONF_ID], rhs)
|
||||
if CONF_NUM_CHANNELS in config:
|
||||
add(my9231.set_num_channels(config[CONF_NUM_CHANNELS]))
|
||||
if CONF_NUM_CHIPS in config:
|
||||
add(my9231.set_num_chips(config[CONF_NUM_CHIPS]))
|
||||
if CONF_BIT_DEPTH in config:
|
||||
add(my9231.set_bit_depth(config[CONF_BIT_DEPTH]))
|
||||
if CONF_UPDATE_ON_BOOT in config:
|
||||
add(my9231.set_update(config[CONF_UPDATE_ON_BOOT]))
|
||||
setup_component(my9231, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
||||
|
||||
@@ -2,12 +2,11 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_OTA, CONF_PASSWORD, CONF_PORT, CONF_SAFE_MODE, \
|
||||
ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, Component
|
||||
from esphomeyaml.const import CONF_ID, CONF_OTA, CONF_PASSWORD, CONF_PORT, CONF_SAFE_MODE
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -35,11 +34,11 @@ def to_code(config):
|
||||
def get_port(config):
|
||||
if CONF_PORT in config[CONF_OTA]:
|
||||
return config[CONF_OTA][CONF_PORT]
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
if CORE.is_esp32:
|
||||
return 3232
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
elif CORE.is_esp8266:
|
||||
return 8266
|
||||
raise ESPHomeYAMLError(u"Invalid ESP Platform for ESP OTA port.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def get_auth(config):
|
||||
@@ -51,6 +50,8 @@ REQUIRED_BUILD_FLAGS = '-DUSE_NEW_OTA'
|
||||
|
||||
|
||||
def lib_deps(config):
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
return ['ArduinoOTA', 'Update', 'ESPmDNS']
|
||||
return ['Hash', 'ESP8266mDNS', 'ArduinoOTA']
|
||||
if CORE.is_esp32:
|
||||
return ['Update', 'ESPmDNS']
|
||||
elif CORE.is_esp8266:
|
||||
return ['Hash', 'ESP8266mDNS']
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -4,8 +4,9 @@ from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
|
||||
from esphomeyaml.const import CONF_INVERTED, CONF_MAX_POWER, CONF_POWER_SUPPLY, CONF_ID, CONF_LEVEL
|
||||
from esphomeyaml.helpers import add, esphomelib_ns, get_variable, TemplateArguments, Pvariable, \
|
||||
templatable, float_, add_job, Action
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import add, get_variable, Pvariable, templatable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Action, float_
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -26,7 +27,9 @@ FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(FLOAT_OUTPUT_SCHEMA.schema
|
||||
|
||||
output_ns = esphomelib_ns.namespace('output')
|
||||
BinaryOutput = output_ns.class_('BinaryOutput')
|
||||
BinaryOutputPtr = BinaryOutput.operator('ptr')
|
||||
FloatOutput = output_ns.class_('FloatOutput', BinaryOutput)
|
||||
FloatOutputPtr = FloatOutput.operator('ptr')
|
||||
|
||||
# Actions
|
||||
TurnOffAction = output_ns.class_('TurnOffAction', Action)
|
||||
@@ -47,7 +50,12 @@ def setup_output_platform_(obj, config, skip_power_supply=False):
|
||||
|
||||
|
||||
def setup_output_platform(obj, config, skip_power_supply=False):
|
||||
add_job(setup_output_platform_, obj, config, skip_power_supply)
|
||||
CORE.add_job(setup_output_platform_, obj, config, skip_power_supply)
|
||||
|
||||
|
||||
def register_output(var, config):
|
||||
output_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||
CORE.add_job(setup_output_platform_, output_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_OUTPUT'
|
||||
@@ -60,8 +68,7 @@ OUTPUT_TURN_ON_ACTION = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_ON, OUTPUT_TURN_ON_ACTION)
|
||||
def output_turn_on_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def output_turn_on_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_on_action(template_arg)
|
||||
@@ -76,8 +83,7 @@ OUTPUT_TURN_OFF_ACTION = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_OFF, OUTPUT_TURN_OFF_ACTION)
|
||||
def output_turn_off_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def output_turn_off_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_off_action(template_arg)
|
||||
@@ -93,8 +99,7 @@ OUTPUT_SET_LEVEL_ACTION = vol.Schema({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_OUTPUT_SET_LEVEL, OUTPUT_SET_LEVEL_ACTION)
|
||||
def output_set_level_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def output_set_level_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_set_level_action(template_arg)
|
||||
|
||||
66
esphomeyaml/components/output/custom.py
Normal file
66
esphomeyaml/components/output/custom.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable
|
||||
from esphomeyaml.cpp_types import std_vector
|
||||
|
||||
CustomBinaryOutputConstructor = output.output_ns.class_('CustomBinaryOutputConstructor')
|
||||
CustomFloatOutputConstructor = output.output_ns.class_('CustomFloatOutputConstructor')
|
||||
|
||||
BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomBinaryOutputConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_OUTPUTS):
|
||||
vol.All(cv.ensure_list, [output.BINARY_OUTPUT_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(output.BinaryOutput),
|
||||
})]),
|
||||
})
|
||||
|
||||
FLOAT_SCHEMA = output.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomFloatOutputConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_OUTPUTS):
|
||||
vol.All(cv.ensure_list, [output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(output.FloatOutput),
|
||||
})]),
|
||||
})
|
||||
|
||||
|
||||
def validate_custom_output(value):
|
||||
if not isinstance(value, dict):
|
||||
raise vol.Invalid("Value must be dict")
|
||||
if CONF_TYPE not in value:
|
||||
raise vol.Invalid("type not specified!")
|
||||
type = cv.string_strict(value[CONF_TYPE]).lower()
|
||||
value[CONF_TYPE] = type
|
||||
if type == 'binary':
|
||||
return BINARY_SCHEMA(value)
|
||||
elif type == 'float':
|
||||
return FLOAT_SCHEMA(value)
|
||||
raise vol.Invalid("type must either be binary or float, not {}!".format(type))
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = validate_custom_output
|
||||
|
||||
|
||||
def to_code(config):
|
||||
type = config[CONF_TYPE]
|
||||
if type == 'binary':
|
||||
ret_type = output.BinaryOutputPtr
|
||||
klass = CustomBinaryOutputConstructor
|
||||
else:
|
||||
ret_type = output.FloatOutputPtr
|
||||
klass = CustomFloatOutputConstructor
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(ret_type)):
|
||||
yield
|
||||
|
||||
rhs = klass(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, sens in enumerate(config[CONF_OUTPUTS]):
|
||||
output.register_output(custom.get_output(i), sens)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_OUTPUT'
|
||||
@@ -3,9 +3,10 @@ import voluptuous as vol
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266, CONF_FREQUENCY
|
||||
from esphomeyaml.helpers import App, Component, Pvariable, gpio_output_pin_expression, \
|
||||
setup_component, add
|
||||
from esphomeyaml.const import CONF_FREQUENCY, CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP8266]
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, gpio_output_pin_expression, setup_component, \
|
||||
Component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
GPIOBinaryOutputComponent = output.output_ns.class_('GPIOBinaryOutputComponent',
|
||||
output.BinaryOutput, Component)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import APB_CLOCK_FREQ, CONF_BIT_DEPTH, CONF_CHANNEL, CONF_FREQUENCY, \
|
||||
CONF_ID, CONF_PIN, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.helpers import App, Pvariable, add, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.components.my9231 import MY9231OutputComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_MY9231_ID, CONF_POWER_SUPPLY
|
||||
from esphomeyaml.helpers import Pvariable, get_variable, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
|
||||
DEPENDENCIES = ['my9231']
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.components.pca9685 import PCA9685OutputComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY
|
||||
from esphomeyaml.helpers import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
|
||||
DEPENDENCIES = ['pca9685']
|
||||
|
||||
|
||||
@@ -1,37 +1,32 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import i2c, output
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output, i2c
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_FREQUENCY, CONF_ID, CONF_PHASE_BALANCER
|
||||
from esphomeyaml.helpers import App, HexIntLiteral, Pvariable, add, setup_component, Component
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_FREQUENCY, CONF_ID
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
MULTI_CONF = True
|
||||
|
||||
PCA9685OutputComponent = output.output_ns.class_('PCA9685OutputComponent',
|
||||
Component, i2c.I2CDevice)
|
||||
|
||||
PHASE_BALANCER_MESSAGE = ("The phase_balancer option has been removed in version 1.5.0. "
|
||||
"esphomelib will now automatically choose a suitable phase balancer.")
|
||||
|
||||
PCA9685_SCHEMA = vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(PCA9685OutputComponent),
|
||||
vol.Required(CONF_FREQUENCY): vol.All(cv.frequency,
|
||||
vol.Range(min=23.84, max=1525.88)),
|
||||
vol.Optional(CONF_ADDRESS): cv.i2c_address,
|
||||
|
||||
vol.Optional(CONF_PHASE_BALANCER): cv.invalid(PHASE_BALANCER_MESSAGE),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [PCA9685_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
rhs = App.make_pca9685_component(conf.get(CONF_FREQUENCY))
|
||||
pca9685 = Pvariable(conf[CONF_ID], rhs)
|
||||
if CONF_ADDRESS in conf:
|
||||
add(pca9685.set_address(HexIntLiteral(conf[CONF_ADDRESS])))
|
||||
setup_component(pca9685, conf)
|
||||
rhs = App.make_pca9685_component(config.get(CONF_FREQUENCY))
|
||||
pca9685 = Pvariable(config[CONF_ID], rhs)
|
||||
if CONF_ADDRESS in config:
|
||||
add(pca9685.set_address(config[CONF_ADDRESS]))
|
||||
setup_component(pca9685, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_PCA9685_OUTPUT'
|
||||
|
||||
@@ -3,9 +3,12 @@ import voluptuous as vol
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_PCF8575
|
||||
from esphomeyaml.helpers import App, GPIOInputPin, GPIOOutputPin, Pvariable, io_ns, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, GPIOInputPin, GPIOOutputPin, io_ns
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
MULTI_CONF = True
|
||||
|
||||
PCF8574GPIOMode = io_ns.enum('PCF8574GPIOMode')
|
||||
PCF8675_GPIO_MODES = {
|
||||
@@ -17,20 +20,17 @@ PCF8675_GPIO_MODES = {
|
||||
PCF8574GPIOInputPin = io_ns.class_('PCF8574GPIOInputPin', GPIOInputPin)
|
||||
PCF8574GPIOOutputPin = io_ns.class_('PCF8574GPIOOutputPin', GPIOOutputPin)
|
||||
|
||||
PCF8574_SCHEMA = vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(pins.PCF8574Component),
|
||||
vol.Optional(CONF_ADDRESS, default=0x21): cv.i2c_address,
|
||||
vol.Optional(CONF_PCF8575, default=False): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [PCF8574_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
rhs = App.make_pcf8574_component(conf[CONF_ADDRESS], conf[CONF_PCF8575])
|
||||
var = Pvariable(conf[CONF_ID], rhs)
|
||||
setup_component(var, conf)
|
||||
rhs = App.make_pcf8574_component(config[CONF_ADDRESS], config[CONF_PCF8575])
|
||||
var = Pvariable(config[CONF_ID], rhs)
|
||||
setup_component(var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_PCF8574'
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins, automation
|
||||
from esphomeyaml import automation, pins
|
||||
from esphomeyaml.components import binary_sensor, spi
|
||||
from esphomeyaml.components.spi import SPIComponent
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_SPI_ID, CONF_UPDATE_INTERVAL, \
|
||||
CONF_ON_TAG, CONF_TRIGGER_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, get_variable, gpio_output_pin_expression, \
|
||||
std_string, setup_component, PollingComponent, Trigger
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_ON_TAG, CONF_SPI_ID, CONF_TRIGGER_ID, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent, Trigger, std_string
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
MULTI_CONF = True
|
||||
|
||||
PN532Component = binary_sensor.binary_sensor_ns.class_('PN532Component', PollingComponent,
|
||||
spi.SPIDevice)
|
||||
PN532Trigger = binary_sensor.binary_sensor_ns.class_('PN532Trigger', Trigger.template(std_string))
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(PN532Component),
|
||||
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
||||
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
||||
@@ -23,23 +25,22 @@ CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
vol.Optional(CONF_ON_TAG): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger),
|
||||
}),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
for spi_ in get_variable(conf[CONF_SPI_ID]):
|
||||
yield
|
||||
for cs in gpio_output_pin_expression(conf[CONF_CS_PIN]):
|
||||
yield
|
||||
rhs = App.make_pn532_component(spi_, cs, conf.get(CONF_UPDATE_INTERVAL))
|
||||
pn532 = Pvariable(conf[CONF_ID], rhs)
|
||||
for spi_ in get_variable(config[CONF_SPI_ID]):
|
||||
yield
|
||||
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
|
||||
yield
|
||||
rhs = App.make_pn532_component(spi_, cs, config.get(CONF_UPDATE_INTERVAL))
|
||||
pn532 = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
for conf_ in conf.get(CONF_ON_TAG, []):
|
||||
trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger())
|
||||
automation.build_automation(trigger, std_string, conf_)
|
||||
for conf_ in config.get(CONF_ON_TAG, []):
|
||||
trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger())
|
||||
automation.build_automation(trigger, std_string, conf_)
|
||||
|
||||
setup_component(pn532, conf)
|
||||
setup_component(pn532, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_PN532'
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ENABLE_TIME, CONF_ID, CONF_KEEP_ON_TIME, CONF_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, gpio_output_pin_expression, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
PowerSupplyComponent = esphomelib_ns.class_('PowerSupplyComponent', Component)
|
||||
|
||||
POWER_SUPPLY_SCHEMA = vol.Schema({
|
||||
MULTI_CONF = True
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(PowerSupplyComponent),
|
||||
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_ENABLE_TIME): cv.positive_time_period_milliseconds,
|
||||
vol.Optional(CONF_KEEP_ON_TIME): cv.positive_time_period_milliseconds,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [POWER_SUPPLY_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
for pin in gpio_output_pin_expression(conf[CONF_PIN]):
|
||||
yield
|
||||
for pin in gpio_output_pin_expression(config[CONF_PIN]):
|
||||
yield
|
||||
|
||||
rhs = App.make_power_supply(pin)
|
||||
psu = Pvariable(conf[CONF_ID], rhs)
|
||||
if CONF_ENABLE_TIME in conf:
|
||||
add(psu.set_enable_time(conf[CONF_ENABLE_TIME]))
|
||||
if CONF_KEEP_ON_TIME in conf:
|
||||
add(psu.set_keep_on_time(conf[CONF_KEEP_ON_TIME]))
|
||||
rhs = App.make_power_supply(pin)
|
||||
psu = Pvariable(config[CONF_ID], rhs)
|
||||
if CONF_ENABLE_TIME in config:
|
||||
add(psu.set_enable_time(config[CONF_ENABLE_TIME]))
|
||||
if CONF_KEEP_ON_TIME in config:
|
||||
add(psu.set_keep_on_time(config[CONF_KEEP_ON_TIME]))
|
||||
|
||||
setup_component(psu, conf)
|
||||
setup_component(psu, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_OUTPUT'
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import binary_sensor, uart
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_UART_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, get_variable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
RDM6300Component = binary_sensor.binary_sensor_ns.class_('RDM6300Component', Component,
|
||||
uart.UARTDevice)
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list_not_empty, [vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(RDM6300Component),
|
||||
cv.GenerateID(CONF_UART_ID): cv.use_variable_id(uart.UARTComponent),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
for uart_ in get_variable(conf[CONF_UART_ID]):
|
||||
yield
|
||||
rhs = App.make_rdm6300_component(uart_)
|
||||
var = Pvariable(conf[CONF_ID], rhs)
|
||||
setup_component(var, conf)
|
||||
for uart_ in get_variable(config[CONF_UART_ID]):
|
||||
yield
|
||||
rhs = App.make_rdm6300_component(uart_)
|
||||
var = Pvariable(config[CONF_ID], rhs)
|
||||
setup_component(var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_RDM6300'
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \
|
||||
CONF_PIN, CONF_TOLERANCE
|
||||
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, gpio_input_pin_expression, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
remote_ns = esphomelib_ns.namespace('remote')
|
||||
MULTI_CONF = True
|
||||
|
||||
RemoteControlComponentBase = remote_ns.class_('RemoteControlComponentBase')
|
||||
RemoteReceiverComponent = remote_ns.class_('RemoteReceiverComponent',
|
||||
@@ -35,7 +37,7 @@ def validate_dumpers_all(value):
|
||||
raise vol.Invalid("Not valid dumpers")
|
||||
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(RemoteReceiverComponent),
|
||||
vol.Required(CONF_PIN): pins.gpio_input_pin_schema,
|
||||
vol.Optional(CONF_DUMP, default=[]):
|
||||
@@ -45,28 +47,27 @@ CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
vol.Optional(CONF_BUFFER_SIZE): cv.validate_bytes,
|
||||
vol.Optional(CONF_FILTER): cv.positive_time_period_microseconds,
|
||||
vol.Optional(CONF_IDLE): cv.positive_time_period_microseconds,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
for pin in gpio_input_pin_expression(conf[CONF_PIN]):
|
||||
yield
|
||||
rhs = App.make_remote_receiver_component(pin)
|
||||
receiver = Pvariable(conf[CONF_ID], rhs)
|
||||
for pin in gpio_input_pin_expression(config[CONF_PIN]):
|
||||
yield
|
||||
rhs = App.make_remote_receiver_component(pin)
|
||||
receiver = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
for dumper in conf[CONF_DUMP]:
|
||||
add(receiver.add_dumper(DUMPERS[dumper].new()))
|
||||
if CONF_TOLERANCE in conf:
|
||||
add(receiver.set_tolerance(conf[CONF_TOLERANCE]))
|
||||
if CONF_BUFFER_SIZE in conf:
|
||||
add(receiver.set_buffer_size(conf[CONF_BUFFER_SIZE]))
|
||||
if CONF_FILTER in conf:
|
||||
add(receiver.set_filter_us(conf[CONF_FILTER]))
|
||||
if CONF_IDLE in conf:
|
||||
add(receiver.set_idle_us(conf[CONF_IDLE]))
|
||||
for dumper in config[CONF_DUMP]:
|
||||
add(receiver.add_dumper(DUMPERS[dumper].new()))
|
||||
if CONF_TOLERANCE in config:
|
||||
add(receiver.set_tolerance(config[CONF_TOLERANCE]))
|
||||
if CONF_BUFFER_SIZE in config:
|
||||
add(receiver.set_buffer_size(config[CONF_BUFFER_SIZE]))
|
||||
if CONF_FILTER in config:
|
||||
add(receiver.set_filter_us(config[CONF_FILTER]))
|
||||
if CONF_IDLE in config:
|
||||
add(receiver.set_idle_us(config[CONF_IDLE]))
|
||||
|
||||
setup_component(receiver, conf)
|
||||
setup_component(receiver, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER'
|
||||
|
||||
@@ -7,14 +7,17 @@ from esphomeyaml.const import CONF_ADDRESS, CONF_CARRIER_DUTY_PERCENT, CONF_CHAN
|
||||
CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_ID, CONF_INVERTED, CONF_ONE, CONF_PIN, \
|
||||
CONF_PROTOCOL, CONF_PULSE_LENGTH, CONF_STATE, CONF_SYNC, CONF_ZERO
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.helpers import App, Component, Pvariable, add, gpio_output_pin_expression, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
RemoteTransmitterComponent = remote_ns.class_('RemoteTransmitterComponent',
|
||||
RemoteControlComponentBase, Component)
|
||||
RCSwitchProtocol = remote_ns.class_('RCSwitchProtocol')
|
||||
rc_switch_protocols = remote_ns.rc_switch_protocols
|
||||
|
||||
MULTI_CONF = True
|
||||
|
||||
|
||||
def validate_rc_switch_code(value):
|
||||
if not isinstance(value, (str, unicode)):
|
||||
@@ -75,12 +78,12 @@ RC_SWITCH_TYPE_D_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA,
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(RemoteTransmitterComponent),
|
||||
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_CARRIER_DUTY_PERCENT): vol.All(cv.percentage_int,
|
||||
vol.Range(min=1, max=100)),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||
|
||||
|
||||
def build_rc_switch_protocol(config):
|
||||
@@ -102,16 +105,15 @@ def binary_code(value):
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
for pin in gpio_output_pin_expression(conf[CONF_PIN]):
|
||||
yield
|
||||
rhs = App.make_remote_transmitter_component(pin)
|
||||
transmitter = Pvariable(conf[CONF_ID], rhs)
|
||||
for pin in gpio_output_pin_expression(config[CONF_PIN]):
|
||||
yield
|
||||
rhs = App.make_remote_transmitter_component(pin)
|
||||
transmitter = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
if CONF_CARRIER_DUTY_PERCENT in conf:
|
||||
add(transmitter.set_carrier_duty_percent(conf[CONF_CARRIER_DUTY_PERCENT]))
|
||||
if CONF_CARRIER_DUTY_PERCENT in config:
|
||||
add(transmitter.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
|
||||
|
||||
setup_component(transmitter, conf)
|
||||
setup_component(transmitter, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_REMOTE_TRANSMITTER'
|
||||
|
||||
@@ -4,11 +4,12 @@ from esphomeyaml import automation
|
||||
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID
|
||||
from esphomeyaml.helpers import NoArg, Pvariable, TemplateArguments, esphomelib_ns, get_variable, \
|
||||
Trigger, Action
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_types import Action, NoArg, Trigger, esphomelib_ns
|
||||
|
||||
Script = esphomelib_ns.class_('Script', Trigger.template(NoArg))
|
||||
ScriptExecuteAction = esphomelib_ns.class_('ScriptExecuteAction', Action)
|
||||
ScriptStopAction = esphomelib_ns.class_('ScriptStopAction', Action)
|
||||
|
||||
CONFIG_SCHEMA = automation.validate_automation({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(Script),
|
||||
@@ -28,10 +29,24 @@ SCRIPT_EXECUTE_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SCRIPT_EXECUTE, SCRIPT_EXECUTE_ACTION_SCHEMA)
|
||||
def script_execute_action_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def script_execute_action_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_execute_action(template_arg)
|
||||
type = ScriptExecuteAction.template(arg_type)
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SCRIPT_STOP = 'script.stop'
|
||||
SCRIPT_STOP_ACTION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Script),
|
||||
})
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SCRIPT_STOP, SCRIPT_STOP_ACTION_SCHEMA)
|
||||
def script_stop_action_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_stop_action(template_arg)
|
||||
type = ScriptStopAction.template(arg_type)
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import automation
|
||||
from esphomeyaml.automation import CONDITION_REGISTRY
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ABOVE, CONF_ACCURACY_DECIMALS, CONF_ALPHA, CONF_BELOW, \
|
||||
CONF_DEBOUNCE, CONF_DELTA, CONF_EXPIRE_AFTER, CONF_EXPONENTIAL_MOVING_AVERAGE, CONF_FILTERS, \
|
||||
@@ -10,9 +12,11 @@ from esphomeyaml.const import CONF_ABOVE, CONF_ACCURACY_DECIMALS, CONF_ALPHA, CO
|
||||
CONF_ON_VALUE_RANGE, CONF_OR, CONF_SEND_EVERY, CONF_SEND_FIRST_AT, \
|
||||
CONF_SLIDING_WINDOW_MOVING_AVERAGE, CONF_THROTTLE, CONF_TRIGGER_ID, CONF_UNIQUE, \
|
||||
CONF_UNIT_OF_MEASUREMENT, CONF_WINDOW_SIZE
|
||||
from esphomeyaml.helpers import App, ArrayInitializer, Component, Nameable, PollingComponent, \
|
||||
Pvariable, Trigger, add, add_job, esphomelib_ns, float_, process_lambda, setup_mqtt_component, \
|
||||
templatable
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add, process_lambda, \
|
||||
templatable, get_variable
|
||||
from esphomeyaml.cpp_types import App, Component, Nameable, PollingComponent, Trigger, \
|
||||
esphomelib_ns, float_
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -37,9 +41,9 @@ FILTER_KEYS = [CONF_OFFSET, CONF_MULTIPLY, CONF_FILTER_OUT, CONF_FILTER_NAN,
|
||||
CONF_THROTTLE, CONF_DELTA, CONF_UNIQUE, CONF_HEARTBEAT, CONF_DEBOUNCE, CONF_OR]
|
||||
|
||||
FILTERS_SCHEMA = vol.All(cv.ensure_list, [vol.All({
|
||||
vol.Optional(CONF_OFFSET): vol.Coerce(float),
|
||||
vol.Optional(CONF_MULTIPLY): vol.Coerce(float),
|
||||
vol.Optional(CONF_FILTER_OUT): vol.Coerce(float),
|
||||
vol.Optional(CONF_OFFSET): cv.float_,
|
||||
vol.Optional(CONF_MULTIPLY): cv.float_,
|
||||
vol.Optional(CONF_FILTER_OUT): cv.float_,
|
||||
vol.Optional(CONF_FILTER_NAN): None,
|
||||
vol.Optional(CONF_SLIDING_WINDOW_MOVING_AVERAGE): vol.All(vol.Schema({
|
||||
vol.Required(CONF_WINDOW_SIZE): cv.positive_not_null_int,
|
||||
@@ -52,7 +56,7 @@ FILTERS_SCHEMA = vol.All(cv.ensure_list, [vol.All({
|
||||
}),
|
||||
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Optional(CONF_THROTTLE): cv.positive_time_period_milliseconds,
|
||||
vol.Optional(CONF_DELTA): vol.Coerce(float),
|
||||
vol.Optional(CONF_DELTA): cv.float_,
|
||||
vol.Optional(CONF_UNIQUE): None,
|
||||
vol.Optional(CONF_HEARTBEAT): cv.positive_time_period_milliseconds,
|
||||
vol.Optional(CONF_DEBOUNCE): cv.positive_time_period_milliseconds,
|
||||
@@ -62,6 +66,7 @@ FILTERS_SCHEMA = vol.All(cv.ensure_list, [vol.All({
|
||||
# Base
|
||||
sensor_ns = esphomelib_ns.namespace('sensor')
|
||||
Sensor = sensor_ns.class_('Sensor', Nameable)
|
||||
SensorPtr = Sensor.operator('ptr')
|
||||
MQTTSensorComponent = sensor_ns.class_('MQTTSensorComponent', mqtt.MQTTComponent)
|
||||
|
||||
PollingSensorComponent = sensor_ns.class_('PollingSensorComponent', PollingComponent, Sensor)
|
||||
@@ -71,7 +76,7 @@ EmptyPollingParentSensor = sensor_ns.class_('EmptyPollingParentSensor', EmptySen
|
||||
# Triggers
|
||||
SensorStateTrigger = sensor_ns.class_('SensorStateTrigger', Trigger.template(float_))
|
||||
SensorRawStateTrigger = sensor_ns.class_('SensorRawStateTrigger', Trigger.template(float_))
|
||||
ValueRangeTrigger = sensor_ns.class_('ValueRangeTrigger', Trigger.template(float_))
|
||||
ValueRangeTrigger = sensor_ns.class_('ValueRangeTrigger', Trigger.template(float_), Component)
|
||||
|
||||
# Filters
|
||||
Filter = sensor_ns.class_('Filter')
|
||||
@@ -88,6 +93,7 @@ HeartbeatFilter = sensor_ns.class_('HeartbeatFilter', Filter, Component)
|
||||
DeltaFilter = sensor_ns.class_('DeltaFilter', Filter)
|
||||
OrFilter = sensor_ns.class_('OrFilter', Filter)
|
||||
UniqueFilter = sensor_ns.class_('UniqueFilter', Filter)
|
||||
SensorInRangeCondition = sensor_ns.class_('SensorInRangeCondition', Filter)
|
||||
|
||||
SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTSensorComponent),
|
||||
@@ -104,8 +110,8 @@ SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
|
||||
}),
|
||||
vol.Optional(CONF_ON_VALUE_RANGE): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(ValueRangeTrigger),
|
||||
vol.Optional(CONF_ABOVE): vol.Coerce(float),
|
||||
vol.Optional(CONF_BELOW): vol.Coerce(float),
|
||||
vol.Optional(CONF_ABOVE): cv.float_,
|
||||
vol.Optional(CONF_BELOW): cv.float_,
|
||||
}, cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW)),
|
||||
})
|
||||
|
||||
@@ -186,13 +192,12 @@ def setup_sensor_core_(sensor_var, mqtt_var, config):
|
||||
for conf in config.get(CONF_ON_VALUE_RANGE, []):
|
||||
rhs = sensor_var.make_value_range_trigger()
|
||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||
add(App.register_component(trigger))
|
||||
if CONF_ABOVE in conf:
|
||||
template_ = None
|
||||
for template_ in templatable(conf[CONF_ABOVE], float_, float_):
|
||||
yield
|
||||
add(trigger.set_min(template_))
|
||||
if CONF_BELOW in conf:
|
||||
template_ = None
|
||||
for template_ in templatable(conf[CONF_BELOW], float_, float_):
|
||||
yield
|
||||
add(trigger.set_max(template_))
|
||||
@@ -209,19 +214,43 @@ def setup_sensor_core_(sensor_var, mqtt_var, config):
|
||||
def setup_sensor(sensor_obj, mqtt_obj, config):
|
||||
sensor_var = Pvariable(config[CONF_ID], sensor_obj, has_side_effects=False)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
|
||||
add_job(setup_sensor_core_, sensor_var, mqtt_var, config)
|
||||
CORE.add_job(setup_sensor_core_, sensor_var, mqtt_var, config)
|
||||
|
||||
|
||||
def register_sensor(var, config):
|
||||
sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||
rhs = App.register_sensor(sensor_var)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
||||
add_job(setup_sensor_core_, sensor_var, mqtt_var, config)
|
||||
CORE.add_job(setup_sensor_core_, sensor_var, mqtt_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_SENSOR'
|
||||
|
||||
|
||||
CONF_SENSOR_IN_RANGE = 'sensor.in_range'
|
||||
SENSOR_IN_RANGE_CONDITION_SCHEMA = vol.All({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Sensor),
|
||||
vol.Optional(CONF_ABOVE): cv.float_,
|
||||
vol.Optional(CONF_BELOW): cv.float_,
|
||||
}, cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW))
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_SENSOR_IN_RANGE, SENSOR_IN_RANGE_CONDITION_SCHEMA)
|
||||
def sensor_in_range_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_sensor_in_range_condition(template_arg)
|
||||
type = SensorInRangeCondition.template(arg_type)
|
||||
cond = Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
if CONF_ABOVE in config:
|
||||
add(cond.set_min(config[CONF_ABOVE]))
|
||||
if CONF_BELOW in config:
|
||||
add(cond.set_max(config[CONF_BELOW]))
|
||||
|
||||
yield cond
|
||||
|
||||
|
||||
def core_to_hass_config(data, config):
|
||||
ret = mqtt.build_hass_config(data, 'sensor', config, include_state=True, include_command=False)
|
||||
if ret is None:
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ATTENUATION, CONF_MAKE_ID, CONF_NAME, CONF_PIN, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, global_ns, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, global_ns
|
||||
|
||||
ATTENUATION_MODES = {
|
||||
'0db': global_ns.ADC_0db,
|
||||
@@ -60,3 +62,9 @@ def required_build_flags(config):
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return sensor.core_to_hass_config(data, config)
|
||||
|
||||
|
||||
def includes(config):
|
||||
if config[CONF_PIN] == 'VCC':
|
||||
return 'ADC_MODE(ADC_VCC);'
|
||||
return None
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.components.ads1115 import ADS1115Component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADS1115_ID, CONF_GAIN, CONF_MULTIPLEXER, CONF_NAME, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable
|
||||
|
||||
DEPENDENCIES = ['ads1115']
|
||||
|
||||
@@ -59,7 +59,6 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
||||
|
||||
|
||||
def to_code(config):
|
||||
hub = None
|
||||
for hub in get_variable(config[CONF_ADS1115_ID]):
|
||||
yield
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor, i2c
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_MAKE_ID, CONF_NAME, CONF_RESOLUTION, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
|
||||
make_address_array
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAC_ADDRESS, CONF_NAME
|
||||
from esphomeyaml.helpers import get_variable, esphomelib_ns
|
||||
from esphomeyaml.cpp_generator import get_variable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns
|
||||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_HUMIDITY, CONF_IIR_FILTER, CONF_MAKE_ID, \
|
||||
CONF_NAME, CONF_OVERSAMPLING, CONF_PRESSURE, CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_GAS_RESISTANCE, CONF_HUMIDITY, CONF_IIR_FILTER, \
|
||||
CONF_MAKE_ID, CONF_NAME, CONF_OVERSAMPLING, CONF_PRESSURE, CONF_TEMPERATURE, \
|
||||
CONF_UPDATE_INTERVAL, CONF_HEATER, CONF_DURATION
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_MAKE_ID, CONF_NAME, CONF_PRESSURE, \
|
||||
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, HexIntLiteral, add, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable, add, HexIntLiteral
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_IIR_FILTER, CONF_MAKE_ID, \
|
||||
CONF_NAME, CONF_OVERSAMPLING, CONF_PRESSURE, CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ from esphomeyaml.components.uart import UARTComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CURRENT, CONF_ID, CONF_NAME, CONF_POWER, CONF_UART_ID, \
|
||||
CONF_UPDATE_INTERVAL, CONF_VOLTAGE
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, get_variable, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
|
||||
35
esphomeyaml/components/sensor/custom.py
Normal file
35
esphomeyaml/components/sensor/custom.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SENSORS
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable
|
||||
from esphomeyaml.cpp_types import std_vector
|
||||
|
||||
CustomSensorConstructor = sensor.sensor_ns.class_('CustomSensorConstructor')
|
||||
|
||||
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomSensorConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_SENSORS): vol.All(cv.ensure_list, [sensor.SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(sensor.Sensor),
|
||||
})]),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(sensor.SensorPtr)):
|
||||
yield
|
||||
|
||||
rhs = CustomSensorConstructor(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, sens in enumerate(config[CONF_SENSORS]):
|
||||
sensor.register_sensor(custom.get_sensor(i), sens)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_SENSOR'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return [sensor.core_to_hass_config(data, sens) for sens in config[CONF_SENSORS]]
|
||||
@@ -1,11 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.components.dallas import DallasComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_DALLAS_ID, CONF_INDEX, CONF_NAME, \
|
||||
CONF_RESOLUTION
|
||||
from esphomeyaml.helpers import HexIntLiteral, get_variable
|
||||
from esphomeyaml.cpp_generator import HexIntLiteral, get_variable
|
||||
|
||||
DallasTemperatureSensor = sensor.sensor_ns.class_('DallasTemperatureSensor',
|
||||
sensor.EmptyPollingParentSensor)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_MODEL, CONF_NAME, CONF_PIN, \
|
||||
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL, CONF_ID
|
||||
from esphomeyaml.helpers import App, Application, add, gpio_output_pin_expression, variable, \
|
||||
setup_component, PollingComponent, Pvariable
|
||||
from esphomeyaml.pins import gpio_output_pin_schema
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_ID, CONF_MAKE_ID, CONF_MODEL, CONF_NAME, \
|
||||
CONF_PIN, CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, variable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, PollingComponent
|
||||
from esphomeyaml.pins import gpio_input_pullup_pin_schema
|
||||
|
||||
DHTModel = sensor.sensor_ns.enum('DHTModel')
|
||||
DHT_MODELS = {
|
||||
@@ -27,7 +28,7 @@ DHTHumiditySensor = sensor.sensor_ns.class_('DHTHumiditySensor',
|
||||
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeDHTSensor),
|
||||
cv.GenerateID(): cv.declare_variable_id(DHTComponent),
|
||||
vol.Required(CONF_PIN): gpio_output_pin_schema,
|
||||
vol.Required(CONF_PIN): gpio_input_pullup_pin_schema,
|
||||
vol.Required(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(DHTTemperatureSensor),
|
||||
})),
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor, i2c
|
||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||
CONF_UPDATE_INTERVAL, CONF_ID
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component, PollingComponent, \
|
||||
Pvariable
|
||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_ID, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.cpp_generator import Pvariable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, gpio_input_pin_expression, variable, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
MakeDutyCycleSensor = Application.struct('MakeDutyCycleSensor')
|
||||
DutyCycleSensor = sensor.sensor_ns.class_('DutyCycleSensor', sensor.PollingSensorComponent)
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
|
||||
34
esphomeyaml/components/sensor/esp32_temperature.py
Normal file
34
esphomeyaml/components/sensor/esp32_temperature.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
|
||||
MakeESP32TemperatureSensor = Application.struct('MakeESP32TemperatureSensor')
|
||||
ESP32TemperatureSensor = sensor.sensor_ns.class_('ESP32TemperatureSensor',
|
||||
sensor.PollingSensorComponent)
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(ESP32TemperatureSensor),
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeESP32TemperatureSensor),
|
||||
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
rhs = App.make_esp32_temperature_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
|
||||
make = variable(config[CONF_MAKE_ID], rhs)
|
||||
sensor.setup_sensor(make.Phall, make.Pmqtt, config)
|
||||
setup_component(make.Phall, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_ESP32_TEMPERATURE_SENSOR'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return sensor.core_to_hass_config(data, config)
|
||||
@@ -4,8 +4,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor, i2c
|
||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||
CONF_UPDATE_INTERVAL, CONF_ID
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component, PollingComponent, \
|
||||
Pvariable
|
||||
from esphomeyaml.cpp_generator import variable, Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, PollingComponent, App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CF1_PIN, CONF_CF_PIN, CONF_CHANGE_MODE_EVERY, CONF_CURRENT, \
|
||||
CONF_CURRENT_RESISTOR, CONF_ID, CONF_NAME, CONF_POWER, CONF_SEL_PIN, CONF_UPDATE_INTERVAL, \
|
||||
CONF_VOLTAGE, CONF_VOLTAGE_DIVIDER
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, add, gpio_output_pin_expression, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import PollingComponent, App
|
||||
|
||||
HLW8012Component = sensor.sensor_ns.class_('HLW8012Component', PollingComponent)
|
||||
HLW8012VoltageSensor = sensor.sensor_ns.class_('HLW8012VoltageSensor', sensor.EmptySensor)
|
||||
|
||||
@@ -4,7 +4,9 @@ import voluptuous as vol
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor, i2c
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_NAME, CONF_UPDATE_INTERVAL, CONF_RANGE
|
||||
from esphomeyaml.helpers import App, Pvariable, add, setup_component, PollingComponent
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import PollingComponent, App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||
CONF_UPDATE_INTERVAL, CONF_ID
|
||||
from esphomeyaml.helpers import App, Application, PollingComponent, setup_component, variable, \
|
||||
Pvariable
|
||||
from esphomeyaml.cpp_generator import variable, Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, PollingComponent, App
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_GAIN, CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL, CONF_CLK_PIN
|
||||
from esphomeyaml.helpers import App, Application, add, gpio_input_pin_expression, variable, \
|
||||
setup_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CLK_PIN, CONF_GAIN, CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
MakeHX711Sensor = Application.struct('MakeHX711Sensor')
|
||||
HX711Sensor = sensor.sensor_ns.class_('HX711Sensor', sensor.PollingSensorComponent)
|
||||
|
||||
@@ -6,7 +6,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_BUS_VOLTAGE, CONF_CURRENT, CONF_ID, \
|
||||
CONF_MAX_CURRENT, CONF_MAX_VOLTAGE, CONF_NAME, CONF_POWER, CONF_SHUNT_RESISTANCE, \
|
||||
CONF_SHUNT_VOLTAGE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_BUS_VOLTAGE, CONF_CURRENT, CONF_ID, CONF_NAME, \
|
||||
CONF_POWER, CONF_SHUNT_RESISTANCE, CONF_SHUNT_VOLTAGE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, add, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor, spi
|
||||
from esphomeyaml.components.spi import SPIComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_MAKE_ID, CONF_NAME, CONF_SPI_ID, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, get_variable, gpio_output_pin_expression, \
|
||||
variable, setup_component
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
MakeMAX6675Sensor = Application.struct('MakeMAX6675Sensor')
|
||||
MAX6675Sensor = sensor.sensor_ns.class_('MAX6675Sensor', sensor.PollingSensorComponent,
|
||||
|
||||
@@ -5,8 +5,9 @@ from esphomeyaml.components.uart import UARTComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CO2, CONF_MAKE_ID, CONF_NAME, CONF_TEMPERATURE, CONF_UART_ID, \
|
||||
CONF_UPDATE_INTERVAL, CONF_ID
|
||||
from esphomeyaml.helpers import App, Application, PollingComponent, get_variable, setup_component, \
|
||||
variable, Pvariable
|
||||
from esphomeyaml.cpp_generator import get_variable, variable, Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, PollingComponent, App
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_NAME, CONF_TEMPERATURE, \
|
||||
CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_QOS, CONF_TOPIC
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component
|
||||
|
||||
DEPENDENCIES = ['mqtt']
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_MAKE_ID, CONF_NAME, CONF_PRESSURE, \
|
||||
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, PollingComponent, Pvariable, add, \
|
||||
setup_component, \
|
||||
variable
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ from esphomeyaml.components.uart import UARTComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_FORMALDEHYDE, CONF_HUMIDITY, CONF_ID, CONF_NAME, CONF_PM_10_0, \
|
||||
CONF_PM_1_0, CONF_PM_2_5, CONF_TEMPERATURE, CONF_TYPE, CONF_UART_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, get_variable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
@@ -44,7 +46,6 @@ PMSX003_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(PMSX003Sensor),
|
||||
})
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(PMSX003Component),
|
||||
cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent),
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import core, pins
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_COUNT_MODE, CONF_FALLING_EDGE, CONF_INTERNAL_FILTER, \
|
||||
CONF_MAKE_ID, CONF_NAME, CONF_PIN, CONF_PULL_MODE, CONF_RISING_EDGE, CONF_UPDATE_INTERVAL, \
|
||||
ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.helpers import App, Application, add, variable, gpio_input_pin_expression, \
|
||||
setup_component
|
||||
CONF_MAKE_ID, CONF_NAME, CONF_PIN, CONF_RISING_EDGE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
PulseCounterCountMode = sensor.sensor_ns.enum('PulseCounterCountMode')
|
||||
COUNT_MODES = {
|
||||
@@ -26,7 +27,7 @@ PulseCounterSensorComponent = sensor.sensor_ns.class_('PulseCounterSensorCompone
|
||||
|
||||
|
||||
def validate_internal_filter(value):
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
if CORE.is_esp32:
|
||||
if isinstance(value, int):
|
||||
raise vol.Invalid("Please specify the internal filter in microseconds now "
|
||||
"(since 1.7.0). For example '17ms'")
|
||||
@@ -48,9 +49,6 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
||||
}),
|
||||
vol.Optional(CONF_INTERNAL_FILTER): validate_internal_filter,
|
||||
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
|
||||
|
||||
vol.Optional(CONF_PULL_MODE): cv.invalid("The pull_mode option has been removed in 1.7.0, "
|
||||
"please use the pin mode schema now.")
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema))
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_RESOLUTION
|
||||
from esphomeyaml.helpers import App, Application, add, gpio_input_pin_expression, variable, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component
|
||||
|
||||
RotaryEncoderResolution = sensor.sensor_ns.enum('RotaryEncoderResolution')
|
||||
RESOLUTIONS = {
|
||||
|
||||
@@ -2,10 +2,11 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_HUMIDITY, CONF_MAKE_ID, CONF_NAME, \
|
||||
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL, CONF_ID
|
||||
from esphomeyaml.helpers import App, Application, PollingComponent, setup_component, variable, \
|
||||
Pvariable
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_HUMIDITY, CONF_ID, CONF_MAKE_ID, CONF_NAME, \
|
||||
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.cpp_generator import Pvariable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_COLOR_TEMPERATURE, CONF_GAIN, CONF_ID, \
|
||||
CONF_ILLUMINANCE, CONF_INTEGRATION_TIME, CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, PollingComponent, Pvariable, add, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, PollingComponent
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, process_lambda, variable, Application, float_, optional, add, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_generator import add, process_lambda, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, float_, optional
|
||||
|
||||
MakeTemplateSensor = Application.struct('MakeTemplateSensor')
|
||||
TemplateSensor = sensor.sensor_ns.class_('TemplateSensor', sensor.PollingSensorComponent)
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import sensor, time
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_TIME_ID
|
||||
from esphomeyaml.helpers import App, Application, Component, get_variable, setup_component, variable
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Application, Component, App
|
||||
|
||||
DEPENDENCIES = ['time']
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import i2c, sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor, i2c
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_GAIN, CONF_INTEGRATION_TIME, CONF_MAKE_ID, \
|
||||
CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ from esphomeyaml import pins
|
||||
from esphomeyaml.components import sensor
|
||||
from esphomeyaml.const import CONF_ECHO_PIN, CONF_MAKE_ID, CONF_NAME, CONF_TIMEOUT_METER, \
|
||||
CONF_TIMEOUT_TIME, CONF_TRIGGER_PIN, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, gpio_input_pin_expression, \
|
||||
gpio_output_pin_expression, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, gpio_input_pin_expression, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
MakeUltrasonicSensor = Application.struct('MakeUltrasonicSensor')
|
||||
UltrasonicSensorComponent = sensor.sensor_ns.class_('UltrasonicSensorComponent',
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
MakeUptimeSensor = Application.struct('MakeUptimeSensor')
|
||||
UptimeSensor = sensor.sensor_ns.class_('UptimeSensor', sensor.PollingSensorComponent)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
MakeWiFiSignalSensor = Application.struct('MakeWiFiSignalSensor')
|
||||
WiFiSignalSensor = sensor.sensor_ns.class_('WiFiSignalSensor', sensor.PollingSensorComponent)
|
||||
|
||||
@@ -6,7 +6,7 @@ from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLE
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_CONDUCTIVITY, CONF_ID, CONF_ILLUMINANCE, \
|
||||
CONF_MAC_ADDRESS, CONF_MOISTURE, CONF_NAME, CONF_TEMPERATURE
|
||||
from esphomeyaml.helpers import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable, Pvariable
|
||||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLE
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_MAKE_ID, \
|
||||
CONF_NAME, CONF_TEMPERATURE
|
||||
from esphomeyaml.helpers import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_generator import get_variable, Pvariable
|
||||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CLK_PIN, CONF_ID, CONF_MISO_PIN, CONF_MOSI_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, gpio_input_pin_expression, \
|
||||
gpio_output_pin_expression, add, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, gpio_output_pin_expression, \
|
||||
setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
SPIComponent = esphomelib_ns.class_('SPIComponent', Component)
|
||||
SPIDevice = esphomelib_ns.class_('SPIDevice')
|
||||
MULTI_CONF = True
|
||||
|
||||
SPI_SCHEMA = vol.All(vol.Schema({
|
||||
CONFIG_SCHEMA = vol.All(vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(SPIComponent),
|
||||
vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema,
|
||||
vol.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema,
|
||||
}), cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN))
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [SPI_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
for clk in gpio_output_pin_expression(conf[CONF_CLK_PIN]):
|
||||
for clk in gpio_output_pin_expression(config[CONF_CLK_PIN]):
|
||||
yield
|
||||
rhs = App.init_spi(clk)
|
||||
spi = Pvariable(config[CONF_ID], rhs)
|
||||
if CONF_MISO_PIN in config:
|
||||
for miso in gpio_input_pin_expression(config[CONF_MISO_PIN]):
|
||||
yield
|
||||
rhs = App.init_spi(clk)
|
||||
spi = Pvariable(conf[CONF_ID], rhs)
|
||||
if CONF_MISO_PIN in conf:
|
||||
for miso in gpio_input_pin_expression(conf[CONF_MISO_PIN]):
|
||||
yield
|
||||
add(spi.set_miso(miso))
|
||||
if CONF_MOSI_PIN in conf:
|
||||
for mosi in gpio_input_pin_expression(conf[CONF_MOSI_PIN]):
|
||||
yield
|
||||
add(spi.set_mosi(mosi))
|
||||
add(spi.set_miso(miso))
|
||||
if CONF_MOSI_PIN in config:
|
||||
for mosi in gpio_input_pin_expression(config[CONF_MOSI_PIN]):
|
||||
yield
|
||||
add(spi.set_mosi(mosi))
|
||||
|
||||
setup_component(spi, conf)
|
||||
setup_component(spi, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_SPI'
|
||||
|
||||
@@ -2,8 +2,9 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml import config_validation as cv, pins
|
||||
from esphomeyaml.const import CONF_ID, CONF_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, gpio_output_pin_expression, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
StatusLEDComponent = esphomelib_ns.class_('StatusLEDComponent', Component)
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ from esphomeyaml.automation import ACTION_REGISTRY
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
|
||||
CONF_POSITION, CONF_TARGET
|
||||
from esphomeyaml.helpers import Pvariable, TemplateArguments, add, add_job, esphomelib_ns, \
|
||||
get_variable, int32, templatable, Action
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, templatable
|
||||
from esphomeyaml.cpp_types import Action, esphomelib_ns, int32
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -78,7 +79,7 @@ def setup_stepper_core_(stepper_var, config):
|
||||
|
||||
|
||||
def setup_stepper(stepper_var, config):
|
||||
add_job(setup_stepper_core_, stepper_var, config)
|
||||
CORE.add_job(setup_stepper_core_, stepper_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_STEPPER'
|
||||
@@ -91,8 +92,7 @@ STEPPER_SET_TARGET_ACTION_SCHEMA = vol.Schema({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_STEPPER_SET_TARGET, STEPPER_SET_TARGET_ACTION_SCHEMA)
|
||||
def stepper_set_target_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def stepper_set_target_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_set_target_action(template_arg)
|
||||
@@ -112,8 +112,7 @@ STEPPER_REPORT_POSITION_ACTION_SCHEMA = vol.Schema({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_STEPPER_REPORT_POSITION, STEPPER_REPORT_POSITION_ACTION_SCHEMA)
|
||||
def stepper_report_position_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def stepper_report_position_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_report_position_action(template_arg)
|
||||
|
||||
@@ -4,8 +4,9 @@ from esphomeyaml import pins
|
||||
from esphomeyaml.components import stepper
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_DIR_PIN, CONF_ID, CONF_SLEEP_PIN, CONF_STEP_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, add, gpio_output_pin_expression, setup_component, \
|
||||
Component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import Component, App
|
||||
|
||||
A4988 = stepper.stepper_ns.class_('A4988', stepper.Stepper, Component)
|
||||
|
||||
|
||||
135
esphomeyaml/components/substitutions.py
Normal file
135
esphomeyaml/components/substitutions.py
Normal file
@@ -0,0 +1,135 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.core import EsphomeyamlError
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_SUBSTITUTIONS = 'substitutions'
|
||||
|
||||
VALID_SUBSTITUTIONS_CHARACTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
|
||||
'0123456789_'
|
||||
|
||||
|
||||
def validate_substitution_key(value):
|
||||
value = cv.string(value)
|
||||
if not value:
|
||||
raise vol.Invalid("Substitution key must not be empty")
|
||||
if value[0] == '$':
|
||||
value = value[1:]
|
||||
if value[0].isdigit():
|
||||
raise vol.Invalid("First character in substitutions cannot be a digit.")
|
||||
for char in value:
|
||||
if char not in VALID_SUBSTITUTIONS_CHARACTERS:
|
||||
raise vol.Invalid(
|
||||
u"Substitution must only consist of upper/lowercase characters, the underscore "
|
||||
u"and numbers. The character '{}' cannot be used".format(char))
|
||||
return value
|
||||
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
validate_substitution_key: cv.string_strict,
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
pass
|
||||
|
||||
|
||||
VARIABLE_PROG = re.compile('\\$([{0}]+|\\{{[{0}]*\\}})'.format(VALID_SUBSTITUTIONS_CHARACTERS))
|
||||
|
||||
|
||||
def _expand_substitutions(substitutions, value, path):
|
||||
if u'$' not in value:
|
||||
return value
|
||||
|
||||
orig_value = value
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
m = VARIABLE_PROG.search(value, i)
|
||||
if not m:
|
||||
# Nothing more to match. Done
|
||||
break
|
||||
|
||||
i, j = m.span(0)
|
||||
name = m.group(1)
|
||||
if name.startswith(u'{') and name.endswith(u'}'):
|
||||
name = name[1:-1]
|
||||
if name not in substitutions:
|
||||
_LOGGER.warn(u"Found '%s' (see %s) which looks like a substitution, but '%s' was not "
|
||||
u"declared", orig_value, u'->'.join(str(x) for x in path), name)
|
||||
i = j
|
||||
continue
|
||||
|
||||
sub = substitutions[name]
|
||||
tail = value[j:]
|
||||
value = value[:i] + sub
|
||||
i = len(value)
|
||||
value += tail
|
||||
return value
|
||||
|
||||
|
||||
def _substitute_item(substitutions, item, path):
|
||||
if isinstance(item, list):
|
||||
for i, it in enumerate(item):
|
||||
sub = _substitute_item(substitutions, it, path + [i])
|
||||
if sub is not None:
|
||||
item[i] = sub
|
||||
elif isinstance(item, dict):
|
||||
replace_keys = []
|
||||
for k, v in item.iteritems():
|
||||
if path or k != CONF_SUBSTITUTIONS:
|
||||
sub = _substitute_item(substitutions, k, path + [k])
|
||||
if sub is not None:
|
||||
replace_keys.append((k, sub))
|
||||
sub = _substitute_item(substitutions, v, path + [k])
|
||||
if sub is not None:
|
||||
item[k] = sub
|
||||
for old, new in replace_keys:
|
||||
item[new] = item[old]
|
||||
del item[old]
|
||||
elif isinstance(item, str):
|
||||
sub = _expand_substitutions(substitutions, item, path)
|
||||
if sub != item:
|
||||
return sub
|
||||
elif isinstance(item, core.Lambda):
|
||||
sub = _expand_substitutions(substitutions, item.value, path)
|
||||
if sub != item:
|
||||
item.value = sub
|
||||
return None
|
||||
|
||||
|
||||
def do_substitution_pass(config):
|
||||
if CONF_SUBSTITUTIONS not in config:
|
||||
return config
|
||||
|
||||
substitutions = config[CONF_SUBSTITUTIONS]
|
||||
if not isinstance(substitutions, dict):
|
||||
raise EsphomeyamlError(u"Substitutions must be a key to value mapping, got {}"
|
||||
u"".format(type(substitutions)))
|
||||
|
||||
key = ''
|
||||
try:
|
||||
replace_keys = []
|
||||
for key, value in substitutions.iteritems():
|
||||
sub = validate_substitution_key(key)
|
||||
if sub != key:
|
||||
replace_keys.append((key, sub))
|
||||
substitutions[key] = cv.string_strict(value)
|
||||
for old, new in replace_keys:
|
||||
substitutions[new] = substitutions[old]
|
||||
del substitutions[old]
|
||||
except vol.Invalid as err:
|
||||
err.path.append(key)
|
||||
|
||||
raise EsphomeyamlError(u"Error while parsing substitutions: {}".format(err))
|
||||
|
||||
config[CONF_SUBSTITUTIONS] = substitutions
|
||||
_substitute_item(substitutions, config, [])
|
||||
|
||||
return config
|
||||
@@ -1,12 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY
|
||||
from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY, CONDITION_REGISTRY, Condition
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INVERTED, CONF_MQTT_ID, CONF_INTERNAL, \
|
||||
CONF_OPTIMISTIC
|
||||
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, setup_mqtt_component, \
|
||||
TemplateArguments, get_variable, Nameable, Action
|
||||
from esphomeyaml.cpp_generator import add, Pvariable, get_variable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Action, App
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -14,12 +15,15 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
switch_ns = esphomelib_ns.namespace('switch_')
|
||||
Switch = switch_ns.class_('Switch', Nameable)
|
||||
SwitchPtr = Switch.operator('ptr')
|
||||
MQTTSwitchComponent = switch_ns.class_('MQTTSwitchComponent', mqtt.MQTTComponent)
|
||||
|
||||
ToggleAction = switch_ns.class_('ToggleAction', Action)
|
||||
TurnOffAction = switch_ns.class_('TurnOffAction', Action)
|
||||
TurnOnAction = switch_ns.class_('TurnOnAction', Action)
|
||||
|
||||
SwitchCondition = switch_ns.class_('SwitchCondition', Condition)
|
||||
|
||||
SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTSwitchComponent),
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
@@ -63,8 +67,7 @@ SWITCH_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TOGGLE, SWITCH_TOGGLE_ACTION_SCHEMA)
|
||||
def switch_toggle_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def switch_toggle_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_toggle_action(template_arg)
|
||||
@@ -79,8 +82,7 @@ SWITCH_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TURN_OFF, SWITCH_TURN_OFF_ACTION_SCHEMA)
|
||||
def switch_turn_off_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def switch_turn_off_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_off_action(template_arg)
|
||||
@@ -95,8 +97,7 @@ SWITCH_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TURN_ON, SWITCH_TURN_ON_ACTION_SCHEMA)
|
||||
def switch_turn_on_to_code(config, action_id, arg_type):
|
||||
template_arg = TemplateArguments(arg_type)
|
||||
def switch_turn_on_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_on_action(template_arg)
|
||||
@@ -104,6 +105,36 @@ def switch_turn_on_to_code(config, action_id, arg_type):
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SWITCH_IS_ON = 'switch.is_on'
|
||||
SWITCH_IS_ON_CONDITION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_SWITCH_IS_ON, SWITCH_IS_ON_CONDITION_SCHEMA)
|
||||
def switch_is_on_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_switch_is_on_condition(template_arg)
|
||||
type = SwitchCondition.template(arg_type)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SWITCH_IS_OFF = 'switch.is_off'
|
||||
SWITCH_IS_OFF_CONDITION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_SWITCH_IS_OFF, SWITCH_IS_OFF_CONDITION_SCHEMA)
|
||||
def switch_is_off_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_switch_is_off_condition(template_arg)
|
||||
type = SwitchCondition.template(arg_type)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
def core_to_hass_config(data, config):
|
||||
ret = mqtt.build_hass_config(data, 'switch', config, include_state=True, include_command=True)
|
||||
if ret is None:
|
||||
|
||||
36
esphomeyaml/components/switch/custom.py
Normal file
36
esphomeyaml/components/switch/custom.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SWITCHES
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable
|
||||
from esphomeyaml.cpp_types import std_vector
|
||||
|
||||
CustomSwitchConstructor = switch.switch_ns.class_('CustomSwitchConstructor')
|
||||
|
||||
PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomSwitchConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_SWITCHES):
|
||||
vol.All(cv.ensure_list, [switch.SWITCH_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(switch.Switch),
|
||||
})]),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(switch.SwitchPtr)):
|
||||
yield
|
||||
|
||||
rhs = CustomSwitchConstructor(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, sens in enumerate(config[CONF_SWITCHES]):
|
||||
switch.register_switch(custom.get_switch(i), sens)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return [switch.core_to_hass_config(data, swi) for swi in config[CONF_SWITCHES]]
|
||||
@@ -4,8 +4,9 @@ from esphomeyaml import pins
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN
|
||||
from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable, \
|
||||
setup_component, Component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component
|
||||
|
||||
MakeGPIOSwitch = Application.struct('MakeGPIOSwitch')
|
||||
GPIOSwitch = switch.switch_ns.class_('GPIOSwitch', switch.Switch, Component)
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import output, switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
|
||||
from esphomeyaml.helpers import App, Application, Component, get_variable, setup_component, variable
|
||||
from esphomeyaml.cpp_generator import get_variable, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component
|
||||
|
||||
MakeOutputSwitch = Application.struct('MakeOutputSwitch')
|
||||
OutputSwitch = switch.switch_ns.class_('OutputSwitch', switch.Switch, Component)
|
||||
|
||||
@@ -12,7 +12,7 @@ from esphomeyaml.const import CONF_ADDRESS, CONF_CARRIER_FREQUENCY, CONF_CHANNEL
|
||||
CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, \
|
||||
CONF_REPEAT, CONF_SAMSUNG, CONF_SONY, CONF_STATE, CONF_TIMES, \
|
||||
CONF_WAIT_TIME
|
||||
from esphomeyaml.helpers import ArrayInitializer, Pvariable, add, get_variable
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add, get_variable
|
||||
|
||||
DEPENDENCIES = ['remote_transmitter']
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_INVERTED, CONF_MAKE_ID, CONF_NAME
|
||||
from esphomeyaml.helpers import App, Application, variable
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
MakeRestartSwitch = Application.struct('MakeRestartSwitch')
|
||||
RestartSwitch = switch.switch_ns.class_('RestartSwitch', switch.Switch)
|
||||
|
||||
@@ -3,7 +3,8 @@ import voluptuous as vol
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import switch
|
||||
from esphomeyaml.const import CONF_INVERTED, CONF_MAKE_ID, CONF_NAME
|
||||
from esphomeyaml.helpers import App, Application, variable
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_types import Application, App
|
||||
|
||||
MakeShutdownSwitch = Application.struct('MakeShutdownSwitch')
|
||||
ShutdownSwitch = switch.switch_ns.class_('ShutdownSwitch', switch.Switch)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import automation
|
||||
from esphomeyaml.components import switch
|
||||
from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, CONF_TURN_OFF_ACTION, \
|
||||
CONF_TURN_ON_ACTION, CONF_OPTIMISTIC, CONF_RESTORE_STATE
|
||||
from esphomeyaml.helpers import App, Application, process_lambda, variable, NoArg, add, bool_, \
|
||||
optional, setup_component, Component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, CONF_OPTIMISTIC, \
|
||||
CONF_RESTORE_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION
|
||||
from esphomeyaml.cpp_generator import add, process_lambda, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component, NoArg, bool_, optional
|
||||
|
||||
MakeTemplateSwitch = Application.struct('MakeTemplateSwitch')
|
||||
TemplateSwitch = switch.switch_ns.class_('TemplateSwitch', switch.Switch, Component)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import switch, uart
|
||||
from esphomeyaml.components.uart import UARTComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_DATA, CONF_INVERTED, CONF_MAKE_ID, CONF_NAME, CONF_UART_ID
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.helpers import App, Application, ArrayInitializer, get_variable, variable
|
||||
from esphomeyaml.cpp_generator import ArrayInitializer, get_variable, variable
|
||||
from esphomeyaml.cpp_types import App, Application
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ import voluptuous as vol
|
||||
|
||||
from esphomeyaml import automation
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_ON_VALUE, \
|
||||
CONF_TRIGGER_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, add, add_job, esphomelib_ns, setup_mqtt_component, \
|
||||
std_string, Nameable, Trigger
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Trigger, std_string, App
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
@@ -15,6 +17,7 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
# pylint: disable=invalid-name
|
||||
text_sensor_ns = esphomelib_ns.namespace('text_sensor')
|
||||
TextSensor = text_sensor_ns.class_('TextSensor', Nameable)
|
||||
TextSensorPtr = TextSensor.operator('ptr')
|
||||
MQTTTextSensor = text_sensor_ns.class_('MQTTTextSensor', mqtt.MQTTComponent)
|
||||
|
||||
TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger',
|
||||
@@ -48,14 +51,14 @@ def setup_text_sensor_core_(text_sensor_var, mqtt_var, config):
|
||||
def setup_text_sensor(text_sensor_obj, mqtt_obj, config):
|
||||
sensor_var = Pvariable(config[CONF_ID], text_sensor_obj, has_side_effects=False)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
|
||||
add_job(setup_text_sensor_core_, sensor_var, mqtt_var, config)
|
||||
CORE.add_job(setup_text_sensor_core_, sensor_var, mqtt_var, config)
|
||||
|
||||
|
||||
def register_text_sensor(var, config):
|
||||
text_sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||
rhs = App.register_text_sensor(text_sensor_var)
|
||||
mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
|
||||
add_job(setup_text_sensor_core_, text_sensor_var, mqtt_var, config)
|
||||
CORE.add_job(setup_text_sensor_core_, text_sensor_var, mqtt_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_TEXT_SENSOR'
|
||||
|
||||
36
esphomeyaml/components/text_sensor/custom.py
Normal file
36
esphomeyaml/components/text_sensor/custom.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import text_sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_TEXT_SENSORS
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable
|
||||
from esphomeyaml.cpp_types import std_vector
|
||||
|
||||
CustomTextSensorConstructor = text_sensor.text_sensor_ns.class_('CustomTextSensorConstructor')
|
||||
|
||||
PLATFORM_SCHEMA = text_sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomTextSensorConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_TEXT_SENSORS):
|
||||
vol.All(cv.ensure_list, [text_sensor.TEXT_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(text_sensor.TextSensor),
|
||||
})]),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(text_sensor.TextSensorPtr)):
|
||||
yield
|
||||
|
||||
rhs = CustomTextSensorConstructor(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, sens in enumerate(config[CONF_TEXT_SENSORS]):
|
||||
text_sensor.register_text_sensor(custom.get_text_sensor(i), sens)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_TEXT_SENSOR'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return [text_sensor.core_to_hass_config(data, sens) for sens in config[CONF_TEXT_SENSORS]]
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import text_sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_QOS, CONF_TOPIC
|
||||
from esphomeyaml.helpers import App, Application, add, variable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import add, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component
|
||||
|
||||
DEPENDENCIES = ['mqtt']
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import voluptuous as vol
|
||||
from esphomeyaml.components import text_sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Application, add, optional, process_lambda, std_string, \
|
||||
variable, setup_component, PollingComponent
|
||||
from esphomeyaml.cpp_generator import add, process_lambda, variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, PollingComponent, optional, std_string
|
||||
|
||||
MakeTemplateTextSensor = Application.struct('MakeTemplateTextSensor')
|
||||
TemplateTextSensor = text_sensor.text_sensor_ns.class_('TemplateTextSensor',
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from esphomeyaml.components import text_sensor
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME
|
||||
from esphomeyaml.helpers import App, Application, variable, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Application, Component
|
||||
|
||||
MakeVersionTextSensor = Application.struct('MakeVersionTextSensor')
|
||||
VersionTextSensor = text_sensor.text_sensor_ns.class_('VersionTextSensor',
|
||||
|
||||
@@ -8,8 +8,9 @@ import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import automation
|
||||
from esphomeyaml.const import CONF_CRON, CONF_DAYS_OF_MONTH, CONF_DAYS_OF_WEEK, CONF_HOURS, \
|
||||
CONF_MINUTES, CONF_MONTHS, CONF_ON_TIME, CONF_SECONDS, CONF_TIMEZONE, CONF_TRIGGER_ID
|
||||
from esphomeyaml.helpers import App, NoArg, Pvariable, add, add_job, esphomelib_ns, \
|
||||
ArrayInitializer, Component, Trigger
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import add, Pvariable, ArrayInitializer
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Component, NoArg, Trigger, App
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -297,7 +298,7 @@ def setup_time_core_(time_var, config):
|
||||
|
||||
|
||||
def setup_time(time_var, config):
|
||||
add_job(setup_time_core_, time_var, config)
|
||||
CORE.add_job(setup_time_core_, time_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_TIME'
|
||||
|
||||
@@ -3,7 +3,9 @@ import voluptuous as vol
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import time as time_
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SERVERS
|
||||
from esphomeyaml.helpers import App, Pvariable, add, setup_component
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
SNTPComponent = time_.time_ns.class_('SNTPComponent', time_.RealTimeClockComponent)
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN
|
||||
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, setup_component, Component
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||
|
||||
UARTComponent = esphomelib_ns.class_('UARTComponent', Component)
|
||||
UARTDevice = esphomelib_ns.class_('UARTDevice')
|
||||
MULTI_CONF = True
|
||||
|
||||
UART_SCHEMA = vol.All(vol.Schema({
|
||||
CONFIG_SCHEMA = vol.All(vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(UARTComponent),
|
||||
vol.Optional(CONF_TX_PIN): pins.output_pin,
|
||||
vol.Optional(CONF_RX_PIN): pins.input_pin,
|
||||
vol.Required(CONF_BAUD_RATE): cv.positive_int,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN))
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [UART_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
tx = conf.get(CONF_TX_PIN, -1)
|
||||
rx = conf.get(CONF_RX_PIN, -1)
|
||||
rhs = App.init_uart(tx, rx, conf[CONF_BAUD_RATE])
|
||||
var = Pvariable(conf[CONF_ID], rhs)
|
||||
tx = config.get(CONF_TX_PIN, -1)
|
||||
rx = config.get(CONF_RX_PIN, -1)
|
||||
rhs = App.init_uart(tx, rx, config[CONF_BAUD_RATE])
|
||||
var = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
setup_component(var, conf)
|
||||
setup_component(var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_UART'
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_CSS_URL, CONF_ID, CONF_JS_URL, CONF_PORT, ESP_PLATFORM_ESP32
|
||||
from esphomeyaml.helpers import App, Component, Pvariable, StoringController, add, esphomelib_ns, \
|
||||
setup_component
|
||||
from esphomeyaml.const import CONF_CSS_URL, CONF_ID, CONF_JS_URL, CONF_PORT
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import Pvariable, add
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, StoringController, Component, App
|
||||
|
||||
WebServer = esphomelib_ns.class_('WebServer', Component, StoringController)
|
||||
|
||||
@@ -31,6 +32,8 @@ BUILD_FLAGS = '-DUSE_WEB_SERVER'
|
||||
|
||||
|
||||
def lib_deps(config):
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
return 'FS'
|
||||
return ''
|
||||
deps = []
|
||||
if CORE.is_esp32:
|
||||
deps.append('FS')
|
||||
deps.append('ESP Async WebServer@1.1.1')
|
||||
return deps
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_AP, CONF_CHANNEL, CONF_DNS1, CONF_DNS2, CONF_DOMAIN, \
|
||||
CONF_GATEWAY, CONF_HOSTNAME, CONF_ID, CONF_MANUAL_IP, CONF_PASSWORD, CONF_POWER_SAVE_MODE,\
|
||||
CONF_REBOOT_TIMEOUT, CONF_SSID, CONF_STATIC_IP, CONF_SUBNET, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.helpers import App, Pvariable, StructInitializer, add, esphomelib_ns, global_ns, \
|
||||
Component
|
||||
CONF_GATEWAY, CONF_HOSTNAME, CONF_ID, CONF_MANUAL_IP, CONF_PASSWORD, CONF_POWER_SAVE_MODE, \
|
||||
CONF_REBOOT_TIMEOUT, CONF_SSID, CONF_STATIC_IP, CONF_SUBNET
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import Pvariable, StructInitializer, add
|
||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns
|
||||
|
||||
|
||||
def validate_password(value):
|
||||
@@ -59,7 +59,7 @@ WIFI_NETWORK_STA = WIFI_NETWORK_BASE.extend({
|
||||
def validate(config):
|
||||
if CONF_PASSWORD in config and CONF_SSID not in config:
|
||||
raise vol.Invalid("Cannot have WiFi password without SSID!")
|
||||
if CONF_SSID not in config and CONF_AP not in config:
|
||||
if (CONF_SSID not in config) and (CONF_AP not in config):
|
||||
raise vol.Invalid("Please specify at least an SSID or an Access Point "
|
||||
"to create.")
|
||||
return config
|
||||
@@ -140,6 +140,8 @@ def to_code(config):
|
||||
|
||||
|
||||
def lib_deps(config):
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
if CORE.is_esp8266:
|
||||
return 'ESP8266WiFi'
|
||||
return None
|
||||
elif CORE.is_esp32:
|
||||
return None
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "esphomeyaml",
|
||||
"version": "1.9.3",
|
||||
"slug": "esphomeyaml",
|
||||
"description": "esphomeyaml HassIO add-on for intelligently managing all your ESP8266/ESP32 devices.",
|
||||
"description": "esphomeyaml Hass.io add-on for intelligently managing all your ESP8266/ESP32 devices.",
|
||||
"url": "https://esphomelib.com/esphomeyaml/index.html",
|
||||
"startup": "application",
|
||||
"webui": "http://[HOST]:[PORT:6052]",
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import importlib
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
import importlib
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
|
||||
import voluptuous as vol
|
||||
from voluptuous.humanize import humanize_error
|
||||
|
||||
from esphomeyaml import core, yaml_util, core_config
|
||||
from esphomeyaml.const import CONF_ESPHOMEYAML, CONF_PLATFORM, CONF_WIFI, ESP_PLATFORMS
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import color, MockObjClass
|
||||
from esphomeyaml import core, core_config, yaml_util
|
||||
from esphomeyaml.components import substitutions
|
||||
from esphomeyaml.const import CONF_ESPHOMEYAML, CONF_PLATFORM, ESP_PLATFORMS
|
||||
from esphomeyaml.core import CORE, EsphomeyamlError
|
||||
from esphomeyaml.helpers import color, indent
|
||||
from esphomeyaml.util import safe_print
|
||||
|
||||
# pylint: disable=unused-import, wrong-import-order
|
||||
from typing import List, Optional, Tuple, Union # noqa
|
||||
from esphomeyaml.core import ConfigType # noqa
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
REQUIRED_COMPONENTS = [
|
||||
CONF_ESPHOMEYAML, CONF_WIFI
|
||||
]
|
||||
_COMPONENT_CACHE = {}
|
||||
_ALL_COMPONENTS = []
|
||||
|
||||
|
||||
def get_component(domain):
|
||||
@@ -50,9 +52,14 @@ def is_platform_component(component):
|
||||
def iter_components(config):
|
||||
for domain, conf in config.iteritems():
|
||||
if domain == CONF_ESPHOMEYAML:
|
||||
yield CONF_ESPHOMEYAML, core_config, conf
|
||||
continue
|
||||
component = get_component(domain)
|
||||
yield domain, component, conf
|
||||
if getattr(component, 'MULTI_CONF', False):
|
||||
for conf_ in conf:
|
||||
yield domain, component, conf_
|
||||
else:
|
||||
yield domain, component, conf
|
||||
if is_platform_component(component):
|
||||
for p_config in conf:
|
||||
p_name = u"{}.{}".format(domain, p_config[CONF_PLATFORM])
|
||||
@@ -60,65 +67,134 @@ def iter_components(config):
|
||||
yield p_name, platform, p_config
|
||||
|
||||
|
||||
ConfigPath = List[Union[basestring, int]]
|
||||
|
||||
|
||||
def _path_begins_with_(path, other): # type: (ConfigPath, ConfigPath) -> bool
|
||||
if len(path) < len(other):
|
||||
return False
|
||||
return path[:len(other)] == other
|
||||
|
||||
|
||||
def _path_begins_with(path, other): # type: (ConfigPath, ConfigPath) -> bool
|
||||
ret = _path_begins_with_(path, other)
|
||||
# print('_path_begins_with({}, {}) -> {}'.format(path, other, ret))
|
||||
return ret
|
||||
|
||||
|
||||
class Config(OrderedDict):
|
||||
def __init__(self):
|
||||
super(Config, self).__init__()
|
||||
self.errors = []
|
||||
self.errors = [] # type: List[Tuple[basestring, ConfigPath]]
|
||||
self.domains = [] # type: List[Tuple[ConfigPath, basestring]]
|
||||
|
||||
def add_error(self, message, domain=None, config=None):
|
||||
def add_error(self, message, path):
|
||||
# type: (basestring, ConfigPath) -> None
|
||||
if not isinstance(message, unicode):
|
||||
message = unicode(message)
|
||||
self.errors.append((message, domain, config))
|
||||
self.errors.append((message, path))
|
||||
|
||||
def add_domain(self, path, name):
|
||||
# type: (ConfigPath, basestring) -> None
|
||||
self.domains.append((path, name))
|
||||
|
||||
def remove_domain(self, path, name):
|
||||
self.domains.remove((path, name))
|
||||
|
||||
def lookup_domain(self, path):
|
||||
# type: (ConfigPath) -> Optional[basestring]
|
||||
best_len = 0
|
||||
best_domain = None
|
||||
for d_path, domain in self.domains:
|
||||
if len(d_path) < best_len:
|
||||
continue
|
||||
if _path_begins_with(path, d_path):
|
||||
best_len = len(d_path)
|
||||
best_domain = domain
|
||||
return best_domain
|
||||
|
||||
def is_in_error_path(self, path):
|
||||
for _, p in self.errors:
|
||||
if _path_begins_with(p, path):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_error_for_path(self, path):
|
||||
for msg, p in self.errors:
|
||||
if self.nested_item_path(p) == path:
|
||||
return msg
|
||||
return None
|
||||
|
||||
def nested_item(self, path):
|
||||
data = self
|
||||
for item_index in path:
|
||||
try:
|
||||
data = data[item_index]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
return {}
|
||||
return data
|
||||
|
||||
def nested_item_path(self, path):
|
||||
data = self
|
||||
part = []
|
||||
for item_index in path:
|
||||
try:
|
||||
data = data[item_index]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
return part
|
||||
part.append(item_index)
|
||||
return part
|
||||
|
||||
|
||||
def iter_ids(config, prefix=None, parent=None):
|
||||
prefix = prefix or []
|
||||
parent = parent or {}
|
||||
def iter_ids(config, path=None):
|
||||
path = path or []
|
||||
if isinstance(config, core.ID):
|
||||
yield config, prefix, parent
|
||||
yield config, path
|
||||
elif isinstance(config, core.Lambda):
|
||||
for id in config.requires_ids:
|
||||
yield id, prefix, parent
|
||||
yield id, path
|
||||
elif isinstance(config, list):
|
||||
for i, item in enumerate(config):
|
||||
for result in iter_ids(item, prefix + [str(i)], config):
|
||||
for result in iter_ids(item, path + [i]):
|
||||
yield result
|
||||
elif isinstance(config, dict):
|
||||
for key, value in config.iteritems():
|
||||
for result in iter_ids(value, prefix + [str(key)], config):
|
||||
for result in iter_ids(value, path + [key]):
|
||||
yield result
|
||||
|
||||
|
||||
def do_id_pass(result):
|
||||
declare_ids = []
|
||||
searching_ids = []
|
||||
for id, prefix, config in iter_ids(result):
|
||||
def do_id_pass(result): # type: (Config) -> None
|
||||
from esphomeyaml.cpp_generator import MockObjClass
|
||||
|
||||
declare_ids = [] # type: List[Tuple[core.ID, ConfigPath]]
|
||||
searching_ids = [] # type: List[Tuple[core.ID, ConfigPath]]
|
||||
for id, path in iter_ids(result):
|
||||
if id.is_declaration:
|
||||
if id.id is not None and any(v[0].id == id.id for v in declare_ids):
|
||||
result.add_error("ID {} redefined!".format(id.id), '.'.join(prefix), config)
|
||||
result.add_error(u"ID {} redefined!".format(id.id), path)
|
||||
continue
|
||||
declare_ids.append((id, prefix, config))
|
||||
declare_ids.append((id, path))
|
||||
else:
|
||||
searching_ids.append((id, prefix, config))
|
||||
searching_ids.append((id, path))
|
||||
# Resolve default ids after manual IDs
|
||||
for id, _, _ in declare_ids:
|
||||
for id, _ in declare_ids:
|
||||
id.resolve([v[0].id for v in declare_ids])
|
||||
|
||||
# Check searched IDs
|
||||
for id, prefix, config in searching_ids:
|
||||
for id, path in searching_ids:
|
||||
if id.id is not None:
|
||||
# manually declared
|
||||
match = next((v[0] for v in declare_ids if v[0].id == id.id), None)
|
||||
if match is None:
|
||||
# No declared ID with this name
|
||||
result.add_error("Couldn't find ID {}".format(id.id), '.'.join(prefix), config)
|
||||
result.add_error("Couldn't find ID '{}'".format(id.id), path)
|
||||
continue
|
||||
if not isinstance(match.type, MockObjClass) or not isinstance(id.type, MockObjClass):
|
||||
continue
|
||||
if not match.type.inherits_from(id.type):
|
||||
result.add_error("ID '{}' of type {} doesn't inherit from {}. Please double check "
|
||||
"your ID is pointing to the correct value"
|
||||
"".format(id.id, match.type, id.type))
|
||||
"".format(id.id, match.type, id.type), path)
|
||||
|
||||
if id.id is None and id.type is not None:
|
||||
for v in declare_ids:
|
||||
@@ -129,173 +205,244 @@ def do_id_pass(result):
|
||||
id.id = v[0].id
|
||||
break
|
||||
else:
|
||||
result.add_error("Couldn't resolve ID for type {}".format(id.type),
|
||||
'.'.join(prefix), config)
|
||||
result.add_error("Couldn't resolve ID for type '{}'".format(id.type), path)
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
global _ALL_COMPONENTS
|
||||
|
||||
for req in REQUIRED_COMPONENTS:
|
||||
if req not in config:
|
||||
raise ESPHomeYAMLError("Component {} is required for esphomeyaml.".format(req))
|
||||
|
||||
_ALL_COMPONENTS = list(config.keys())
|
||||
|
||||
result = Config()
|
||||
|
||||
def _comp_error(ex, domain, config):
|
||||
result.add_error(_format_config_error(ex, domain, config), domain, config)
|
||||
def _comp_error(ex, path):
|
||||
# type: (vol.Invalid, List[basestring]) -> None
|
||||
if isinstance(ex, vol.MultipleInvalid):
|
||||
errors = ex.errors
|
||||
else:
|
||||
errors = [ex]
|
||||
|
||||
for e in errors:
|
||||
path_ = path + e.path
|
||||
domain = result.lookup_domain(path_) or ''
|
||||
result.add_error(_format_vol_invalid(e, config, path, domain), path_)
|
||||
|
||||
skip_paths = list() # type: List[ConfigPath]
|
||||
|
||||
# Step 1: Load everything
|
||||
for domain, conf in config.iteritems():
|
||||
domain = str(domain)
|
||||
if domain == CONF_ESPHOMEYAML or domain.startswith('.'):
|
||||
continue
|
||||
if conf is None:
|
||||
conf = {}
|
||||
component = get_component(domain)
|
||||
if component is None:
|
||||
result.add_error(u"Component not found: {}".format(domain), domain, conf)
|
||||
continue
|
||||
|
||||
if not hasattr(component, 'PLATFORM_SCHEMA'):
|
||||
continue
|
||||
|
||||
for p_config in conf:
|
||||
if not isinstance(p_config, dict):
|
||||
result.add_error(u"Platform schemas must have 'platform:' key", )
|
||||
continue
|
||||
p_name = p_config.get(u'platform')
|
||||
if p_name is None:
|
||||
result.add_error(u"No platform specified for {}".format(domain))
|
||||
continue
|
||||
p_domain = u'{}.{}'.format(domain, p_name)
|
||||
platform = get_platform(domain, p_name)
|
||||
if platform is None:
|
||||
result.add_error(u"Platform not found: '{}'".format(p_domain), p_domain, p_config)
|
||||
continue
|
||||
|
||||
# Step 2: Validate configuration
|
||||
try:
|
||||
result[CONF_ESPHOMEYAML] = core_config.CONFIG_SCHEMA(config[CONF_ESPHOMEYAML])
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, CONF_ESPHOMEYAML, config[CONF_ESPHOMEYAML])
|
||||
result.add_domain([CONF_ESPHOMEYAML], CONF_ESPHOMEYAML)
|
||||
result[CONF_ESPHOMEYAML] = config[CONF_ESPHOMEYAML]
|
||||
|
||||
for domain, conf in config.iteritems():
|
||||
if domain == CONF_ESPHOMEYAML or domain.startswith('.'):
|
||||
continue
|
||||
if conf is None:
|
||||
conf = {}
|
||||
domain = str(domain)
|
||||
if domain == CONF_ESPHOMEYAML or domain.startswith(u'.'):
|
||||
skip_paths.append([domain])
|
||||
continue
|
||||
result.add_domain([domain], domain)
|
||||
result[domain] = conf
|
||||
if conf is None:
|
||||
result[domain] = conf = {}
|
||||
component = get_component(domain)
|
||||
if component is None:
|
||||
result.add_error(u"Component not found: {}".format(domain), [domain])
|
||||
skip_paths.append([domain])
|
||||
continue
|
||||
|
||||
esp_platforms = getattr(component, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
||||
if core.ESP_PLATFORM not in esp_platforms:
|
||||
result.add_error(u"Component {} doesn't support {}.".format(domain, core.ESP_PLATFORM),
|
||||
domain, conf)
|
||||
continue
|
||||
if not isinstance(conf, list) and getattr(component, 'MULTI_CONF', False):
|
||||
result[domain] = conf = [conf]
|
||||
|
||||
success = True
|
||||
dependencies = getattr(component, 'DEPENDENCIES', [])
|
||||
for dependency in dependencies:
|
||||
if dependency not in _ALL_COMPONENTS:
|
||||
if dependency not in config:
|
||||
result.add_error(u"Component {} requires component {}".format(domain, dependency),
|
||||
domain, conf)
|
||||
[domain])
|
||||
success = False
|
||||
if not success:
|
||||
skip_paths.append([domain])
|
||||
continue
|
||||
|
||||
if hasattr(component, 'CONFIG_SCHEMA'):
|
||||
try:
|
||||
validated = component.CONFIG_SCHEMA(conf)
|
||||
result[domain] = validated
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, domain, conf)
|
||||
continue
|
||||
success = True
|
||||
conflicts_with = getattr(component, 'CONFLICTS_WITH', [])
|
||||
for conflict in conflicts_with:
|
||||
if conflict not in config:
|
||||
result.add_error(u"Component {} cannot be used together with component {}"
|
||||
u"".format(domain, conflict), [domain])
|
||||
success = False
|
||||
if not success:
|
||||
skip_paths.append([domain])
|
||||
continue
|
||||
|
||||
esp_platforms = getattr(component, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
||||
if CORE.esp_platform not in esp_platforms:
|
||||
result.add_error(u"Component {} doesn't support {}.".format(domain, CORE.esp_platform),
|
||||
[domain])
|
||||
skip_paths.append([domain])
|
||||
continue
|
||||
|
||||
if not hasattr(component, 'PLATFORM_SCHEMA'):
|
||||
continue
|
||||
|
||||
platforms = []
|
||||
for p_config in conf:
|
||||
result.remove_domain([domain], domain)
|
||||
|
||||
if not isinstance(conf, list) and conf:
|
||||
result[domain] = conf = [conf]
|
||||
|
||||
for i, p_config in enumerate(conf):
|
||||
if not isinstance(p_config, dict):
|
||||
result.add_error(u"Platform schemas must have 'platform:' key", [domain, i])
|
||||
skip_paths.append([domain, i])
|
||||
continue
|
||||
p_name = p_config.get(u'platform')
|
||||
p_name = p_config.get('platform')
|
||||
if p_name is None:
|
||||
result.add_error(u"No platform specified for {}".format(domain), [domain, i])
|
||||
skip_paths.append([domain, i])
|
||||
continue
|
||||
p_domain = u'{}.{}'.format(domain, p_name)
|
||||
result.add_domain([domain, i], p_domain)
|
||||
platform = get_platform(domain, p_name)
|
||||
if platform is None:
|
||||
result.add_error(u"Platform not found: '{}'".format(p_domain), [domain, i])
|
||||
skip_paths.append([domain, i])
|
||||
continue
|
||||
|
||||
success = True
|
||||
dependencies = getattr(platform, 'DEPENDENCIES', [])
|
||||
for dependency in dependencies:
|
||||
if dependency not in _ALL_COMPONENTS:
|
||||
result.add_error(
|
||||
u"Platform {} requires component {}".format(p_domain, dependency),
|
||||
p_domain, p_config)
|
||||
if dependency not in config:
|
||||
result.add_error(u"Platform {} requires component {}"
|
||||
u"".format(p_domain, dependency), [domain, i])
|
||||
success = False
|
||||
if not success:
|
||||
skip_paths.append([domain, i])
|
||||
continue
|
||||
|
||||
success = True
|
||||
conflicts_with = getattr(platform, 'CONFLICTS_WITH', [])
|
||||
for conflict in conflicts_with:
|
||||
if conflict not in config:
|
||||
result.add_error(u"Platform {} cannot be used together with component {}"
|
||||
u"".format(p_domain, conflict), [domain, i])
|
||||
success = False
|
||||
if not success:
|
||||
skip_paths.append([domain, i])
|
||||
continue
|
||||
|
||||
esp_platforms = getattr(platform, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
||||
if core.ESP_PLATFORM not in esp_platforms:
|
||||
result.add_error(
|
||||
u"Platform {} doesn't support {}.".format(p_domain, core.ESP_PLATFORM),
|
||||
p_domain, p_config)
|
||||
if CORE.esp_platform not in esp_platforms:
|
||||
result.add_error(u"Platform {} doesn't support {}."
|
||||
u"".format(p_domain, CORE.esp_platform), [domain, i])
|
||||
skip_paths.append([domain, i])
|
||||
continue
|
||||
|
||||
if hasattr(platform, u'PLATFORM_SCHEMA'):
|
||||
# Step 2: Validate configuration
|
||||
try:
|
||||
result[CONF_ESPHOMEYAML] = core_config.CONFIG_SCHEMA(result[CONF_ESPHOMEYAML])
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, [CONF_ESPHOMEYAML])
|
||||
|
||||
for domain, conf in result.iteritems():
|
||||
domain = str(domain)
|
||||
if [domain] in skip_paths:
|
||||
continue
|
||||
component = get_component(domain)
|
||||
|
||||
if hasattr(component, 'CONFIG_SCHEMA'):
|
||||
multi_conf = getattr(component, 'MULTI_CONF', False)
|
||||
|
||||
if multi_conf:
|
||||
for i, conf_ in enumerate(conf):
|
||||
try:
|
||||
validated = component.CONFIG_SCHEMA(conf_)
|
||||
result[domain][i] = validated
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, [domain, i])
|
||||
else:
|
||||
try:
|
||||
validated = component.CONFIG_SCHEMA(conf)
|
||||
result[domain] = validated
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, [domain])
|
||||
continue
|
||||
|
||||
if not hasattr(component, 'PLATFORM_SCHEMA'):
|
||||
continue
|
||||
|
||||
for i, p_config in enumerate(conf):
|
||||
if [domain, i] in skip_paths:
|
||||
continue
|
||||
p_name = p_config['platform']
|
||||
platform = get_platform(domain, p_name)
|
||||
|
||||
if hasattr(platform, 'PLATFORM_SCHEMA'):
|
||||
try:
|
||||
p_validated = platform.PLATFORM_SCHEMA(p_config)
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, p_domain, p_config)
|
||||
_comp_error(ex, [domain, i])
|
||||
continue
|
||||
platforms.append(p_validated)
|
||||
result[domain] = platforms
|
||||
result[domain][i] = p_validated
|
||||
|
||||
do_id_pass(result)
|
||||
return result
|
||||
|
||||
|
||||
REQUIRED = ['esphomeyaml', 'wifi']
|
||||
def _nested_getitem(data, path):
|
||||
for item_index in path:
|
||||
try:
|
||||
data = data[item_index]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
return None
|
||||
return data
|
||||
|
||||
|
||||
def _format_config_error(ex, domain, config):
|
||||
message = u"Invalid config for [{}]: ".format(domain)
|
||||
def humanize_error(config, validation_error):
|
||||
offending_item_summary = _nested_getitem(config, validation_error.path)
|
||||
if isinstance(offending_item_summary, dict):
|
||||
try:
|
||||
offending_item_summary = json.dumps(offending_item_summary)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
validation_error = unicode(validation_error)
|
||||
m = re.match(r'^(.*?)\s*(?:for dictionary value )?@ data\[.*$', validation_error)
|
||||
if m is not None:
|
||||
validation_error = m.group(1)
|
||||
validation_error = validation_error.strip()
|
||||
if not validation_error.endswith(u'.'):
|
||||
validation_error += u'.'
|
||||
if offending_item_summary is None:
|
||||
return validation_error
|
||||
return u"{} Got '{}'".format(validation_error, offending_item_summary)
|
||||
|
||||
|
||||
def _format_vol_invalid(ex, config, path, domain):
|
||||
# type: (vol.Invalid, ConfigType, ConfigPath, basestring) -> unicode
|
||||
message = u''
|
||||
if u'extra keys not allowed' in ex.error_message:
|
||||
message += u'[{}] is an invalid option for [{}]. Check: {}->{}.' \
|
||||
.format(ex.path[-1], domain, domain,
|
||||
u'->'.join(str(m) for m in ex.path))
|
||||
try:
|
||||
paren = ex.path[-2]
|
||||
except IndexError:
|
||||
paren = domain
|
||||
message += u'[{}] is an invalid option for [{}].'.format(ex.path[-1], paren)
|
||||
elif u'required key not provided' in ex.error_message:
|
||||
try:
|
||||
paren = ex.path[-2]
|
||||
except IndexError:
|
||||
paren = domain
|
||||
message += u"'{}' is a required option for [{}].".format(ex.path[-1], paren)
|
||||
else:
|
||||
message += u'{}.'.format(humanize_error(config, ex))
|
||||
|
||||
if isinstance(config, list):
|
||||
return message
|
||||
|
||||
domain_config = config.get(domain, config)
|
||||
message += u" (See {}, line {}). ".format(
|
||||
getattr(domain_config, '__config_file__', '?'),
|
||||
getattr(domain_config, '__line__', '?'))
|
||||
message += humanize_error(_nested_getitem(config, path), ex)
|
||||
|
||||
return message
|
||||
|
||||
|
||||
def load_config(path):
|
||||
def load_config():
|
||||
try:
|
||||
config = yaml_util.load_yaml(path)
|
||||
config = yaml_util.load_yaml(CORE.config_path)
|
||||
except OSError:
|
||||
raise ESPHomeYAMLError(u"Could not read configuration file at {}".format(path))
|
||||
core.RAW_CONFIG = config
|
||||
raise EsphomeyamlError(u"Could not read configuration file at {}".format(CORE.config_path))
|
||||
CORE.raw_config = config
|
||||
config = substitutions.do_substitution_pass(config)
|
||||
core_config.preload_core_config(config)
|
||||
|
||||
try:
|
||||
result = validate_config(config)
|
||||
except ESPHomeYAMLError:
|
||||
except EsphomeyamlError:
|
||||
raise
|
||||
except Exception:
|
||||
_LOGGER.error(u"Unexpected exception while reading configuration:")
|
||||
@@ -304,60 +451,151 @@ def load_config(path):
|
||||
return result
|
||||
|
||||
|
||||
def line_info(obj, **kwargs):
|
||||
def line_info(obj, highlight=True):
|
||||
"""Display line config source."""
|
||||
if not highlight:
|
||||
return None
|
||||
if hasattr(obj, '__config_file__'):
|
||||
return color('cyan', "[source {}:{}]"
|
||||
.format(obj.__config_file__, obj.__line__ or '?'),
|
||||
**kwargs)
|
||||
return '?'
|
||||
.format(obj.__config_file__, obj.__line__ or '?'))
|
||||
return None
|
||||
|
||||
|
||||
def dump_dict(layer, indent_count=3, listi=False, **kwargs):
|
||||
def sort_dict_key(val):
|
||||
"""Return the dict key for sorting."""
|
||||
key = str.lower(val[0])
|
||||
return '0' if key == 'platform' else key
|
||||
|
||||
indent_str = indent_count * ' '
|
||||
if listi or isinstance(layer, list):
|
||||
indent_str = indent_str[:-1] + '-'
|
||||
if isinstance(layer, dict):
|
||||
for key, value in sorted(layer.items(), key=sort_dict_key):
|
||||
if isinstance(value, (dict, list)):
|
||||
safe_print(u"{} {}: {}".format(indent_str, key, line_info(value, **kwargs)))
|
||||
dump_dict(value, indent_count + 2)
|
||||
else:
|
||||
safe_print(u"{} {}: {}".format(indent_str, key, value))
|
||||
indent_str = indent_count * ' '
|
||||
if isinstance(layer, (list, tuple)):
|
||||
for i in layer:
|
||||
if isinstance(i, dict):
|
||||
dump_dict(i, indent_count + 2, True)
|
||||
else:
|
||||
safe_print(u" {} {}".format(indent_str, i))
|
||||
def _print_on_next_line(obj):
|
||||
if isinstance(obj, (list, tuple, dict)):
|
||||
return True
|
||||
if isinstance(obj, str):
|
||||
return len(obj) > 80
|
||||
if isinstance(obj, core.Lambda):
|
||||
return len(obj.value) > 80
|
||||
return False
|
||||
|
||||
|
||||
def read_config(path):
|
||||
def dump_dict(config, path, at_root=True):
|
||||
# type: (Config, ConfigPath, bool) -> Tuple[unicode, bool]
|
||||
conf = config.nested_item(path)
|
||||
ret = u''
|
||||
multiline = False
|
||||
|
||||
if at_root:
|
||||
error = config.get_error_for_path(path)
|
||||
if error is not None:
|
||||
ret += u'\n' + color('bold_red', error) + u'\n'
|
||||
|
||||
if isinstance(conf, (list, tuple)):
|
||||
multiline = True
|
||||
if not conf:
|
||||
ret += u'[]'
|
||||
multiline = False
|
||||
|
||||
for i in range(len(conf)):
|
||||
path_ = path + [i]
|
||||
error = config.get_error_for_path(path_)
|
||||
if error is not None:
|
||||
ret += u'\n' + color('bold_red', error) + u'\n'
|
||||
|
||||
sep = u'- '
|
||||
if config.is_in_error_path(path_):
|
||||
sep = color('red', sep)
|
||||
msg, _ = dump_dict(config, path_, at_root=False)
|
||||
msg = indent(msg)
|
||||
inf = line_info(config.nested_item(path_), highlight=config.is_in_error_path(path_))
|
||||
if inf is not None:
|
||||
msg = inf + u'\n' + msg
|
||||
elif msg:
|
||||
msg = msg[2:]
|
||||
ret += sep + msg + u'\n'
|
||||
elif isinstance(conf, dict):
|
||||
multiline = True
|
||||
if not conf:
|
||||
ret += u'{}'
|
||||
multiline = False
|
||||
|
||||
for k in conf.iterkeys():
|
||||
path_ = path + [k]
|
||||
error = config.get_error_for_path(path_)
|
||||
if error is not None:
|
||||
ret += u'\n' + color('bold_red', error) + u'\n'
|
||||
|
||||
st = u'{}: '.format(k)
|
||||
if config.is_in_error_path(path_):
|
||||
st = color('red', st)
|
||||
msg, m = dump_dict(config, path_, at_root=False)
|
||||
|
||||
inf = line_info(config.nested_item(path_), highlight=config.is_in_error_path(path_))
|
||||
if m:
|
||||
msg = u'\n' + indent(msg)
|
||||
|
||||
if inf is not None:
|
||||
if m:
|
||||
msg = u' ' + inf + msg
|
||||
else:
|
||||
msg = msg + u' ' + inf
|
||||
ret += st + msg + u'\n'
|
||||
elif isinstance(conf, str):
|
||||
if not conf:
|
||||
conf += u"''"
|
||||
|
||||
if len(conf) > 80:
|
||||
conf = u'|-\n' + indent(conf)
|
||||
error = config.get_error_for_path(path)
|
||||
col = 'bold_red' if error else 'white'
|
||||
ret += color(col, unicode(conf))
|
||||
elif isinstance(conf, core.Lambda):
|
||||
conf = u'!lambda |-\n' + indent(unicode(conf.value))
|
||||
error = config.get_error_for_path(path)
|
||||
col = 'bold_red' if error else 'white'
|
||||
ret += color(col, conf)
|
||||
elif conf is None:
|
||||
pass
|
||||
else:
|
||||
error = config.get_error_for_path(path)
|
||||
col = 'bold_red' if error else 'white'
|
||||
ret += color(col, unicode(conf))
|
||||
multiline = u'\n' in ret
|
||||
|
||||
return ret, multiline
|
||||
|
||||
|
||||
def strip_default_ids(config):
|
||||
if isinstance(config, list):
|
||||
to_remove = []
|
||||
for i, x in enumerate(config):
|
||||
x = config[i] = strip_default_ids(x)
|
||||
if isinstance(x, core.ID) and not x.is_manual:
|
||||
to_remove.append(x)
|
||||
for x in to_remove:
|
||||
config.remove(x)
|
||||
elif isinstance(config, dict):
|
||||
to_remove = []
|
||||
for k, v in config.iteritems():
|
||||
v = config[k] = strip_default_ids(v)
|
||||
if isinstance(v, core.ID) and not v.is_manual:
|
||||
to_remove.append(k)
|
||||
for k in to_remove:
|
||||
config.pop(k)
|
||||
return config
|
||||
|
||||
|
||||
def read_config(verbose):
|
||||
_LOGGER.info("Reading configuration...")
|
||||
try:
|
||||
res = load_config(path)
|
||||
except ESPHomeYAMLError as err:
|
||||
res = load_config()
|
||||
except EsphomeyamlError as err:
|
||||
_LOGGER.error(u"Error while reading config: %s", err)
|
||||
return None
|
||||
excepts = {}
|
||||
for message, domain, config in res.errors:
|
||||
domain = domain or u"General Error"
|
||||
excepts.setdefault(domain, []).append(message)
|
||||
if config is not None:
|
||||
excepts[domain].append(config)
|
||||
if res.errors:
|
||||
if not verbose:
|
||||
res = strip_default_ids(res)
|
||||
|
||||
if excepts:
|
||||
safe_print(color('bold_white', u"Failed config"))
|
||||
for domain, config in excepts.iteritems():
|
||||
safe_print(u' {} {}'.format(color('bold_red', domain + u':'),
|
||||
color('red', '', reset='red')))
|
||||
dump_dict(config, reset='red')
|
||||
safe_print(color('reset'))
|
||||
safe_print(color('bold_red', u"Failed config"))
|
||||
safe_print('')
|
||||
for path, domain in res.domains:
|
||||
if not res.is_in_error_path(path):
|
||||
continue
|
||||
|
||||
safe_print(color('bold_red', u'{}:'.format(domain)) + u' ' +
|
||||
(line_info(res.nested_item(path)) or u''))
|
||||
safe_print(indent(dump_dict(res, path)[0]))
|
||||
return None
|
||||
return OrderedDict(res)
|
||||
|
||||
@@ -9,12 +9,12 @@ import uuid as uuid_
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core, helpers
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, CONF_ID, \
|
||||
CONF_NAME, CONF_PAYLOAD_AVAILABLE, \
|
||||
CONF_PAYLOAD_NOT_AVAILABLE, CONF_PLATFORM, CONF_RETAIN, CONF_STATE_TOPIC, CONF_TOPIC, \
|
||||
ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266, CONF_INTERNAL, CONF_SETUP_PRIORITY
|
||||
from esphomeyaml.core import HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \
|
||||
CONF_INTERNAL, CONF_NAME, CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_PLATFORM, \
|
||||
CONF_RETAIN, CONF_SETUP_PRIORITY, CONF_STATE_TOPIC, CONF_TOPIC, ESP_PLATFORM_ESP32, \
|
||||
ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.core import CORE, HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \
|
||||
TimePeriodMilliseconds, TimePeriodSeconds
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -22,8 +22,9 @@ _LOGGER = logging.getLogger(__name__)
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
port = vol.All(vol.Coerce(int), vol.Range(min=1, max=65535))
|
||||
positive_float = vol.All(vol.Coerce(float), vol.Range(min=0))
|
||||
zero_to_one_float = vol.All(vol.Coerce(float), vol.Range(min=0, max=1))
|
||||
float_ = vol.Coerce(float)
|
||||
positive_float = vol.All(float_, vol.Range(min=0))
|
||||
zero_to_one_float = vol.All(float_, vol.Range(min=0, max=1))
|
||||
positive_int = vol.All(vol.Coerce(int), vol.Range(min=0))
|
||||
positive_not_null_int = vol.All(vol.Coerce(int), vol.Range(min=0, min_included=False))
|
||||
|
||||
@@ -77,8 +78,8 @@ def string_strict(value):
|
||||
"""Strictly only allow strings."""
|
||||
if isinstance(value, (str, unicode)):
|
||||
return value
|
||||
raise vol.Invalid("Must be string, did you forget putting quotes "
|
||||
"around the value?")
|
||||
raise vol.Invalid("Must be string, got {}. did you forget putting quotes "
|
||||
"around the value?".format(type(value)))
|
||||
|
||||
|
||||
def icon(value):
|
||||
@@ -155,8 +156,9 @@ def variable_id_str_(value):
|
||||
raise vol.Invalid("Dashes are not supported in IDs, please use underscores instead.")
|
||||
for char in value:
|
||||
if char != '_' and not char.isalnum():
|
||||
raise vol.Invalid(u"IDs must only consist of upper/lowercase characters and numbers."
|
||||
u"The character '{}' cannot be used".format(char))
|
||||
raise vol.Invalid(u"IDs must only consist of upper/lowercase characters, the underscore"
|
||||
u"character and numbers. The character '{}' cannot be used"
|
||||
u"".format(char))
|
||||
if value in RESERVED_IDS:
|
||||
raise vol.Invalid(u"ID {} is reserved internally and cannot be used".format(value))
|
||||
return value
|
||||
@@ -198,7 +200,7 @@ def only_on(platforms):
|
||||
platforms = [platforms]
|
||||
|
||||
def validator_(obj):
|
||||
if core.ESP_PLATFORM not in platforms:
|
||||
if CORE.esp_platform not in platforms:
|
||||
raise vol.Invalid(u"This feature is only available on {}".format(platforms))
|
||||
return obj
|
||||
|
||||
@@ -258,12 +260,12 @@ TIME_PERIOD_ERROR = "Time period {} should be format number + unit, for example
|
||||
|
||||
time_period_dict = vol.All(
|
||||
dict, vol.Schema({
|
||||
'days': vol.Coerce(float),
|
||||
'hours': vol.Coerce(float),
|
||||
'minutes': vol.Coerce(float),
|
||||
'seconds': vol.Coerce(float),
|
||||
'milliseconds': vol.Coerce(float),
|
||||
'microseconds': vol.Coerce(float),
|
||||
'days': float_,
|
||||
'hours': float_,
|
||||
'minutes': float_,
|
||||
'seconds': float_,
|
||||
'milliseconds': float_,
|
||||
'microseconds': float_,
|
||||
}),
|
||||
has_at_least_one_key('days', 'hours', 'minutes',
|
||||
'seconds', 'milliseconds', 'microseconds'),
|
||||
@@ -319,11 +321,11 @@ def time_period_str_unit(value):
|
||||
|
||||
match = re.match(r"^([-+]?[0-9]*\.?[0-9]*)\s*(\w*)$", value)
|
||||
|
||||
if match is None or match.group(2) not in unit_to_kwarg:
|
||||
if match is None:
|
||||
raise vol.Invalid(u"Expected time period with unit, "
|
||||
u"got {}".format(value))
|
||||
kwarg = unit_to_kwarg[one_of(*unit_to_kwarg)(match.group(2))]
|
||||
|
||||
kwarg = unit_to_kwarg[match.group(2)]
|
||||
return TimePeriod(**{kwarg: float(match.group(1))})
|
||||
|
||||
|
||||
@@ -597,10 +599,12 @@ def one_of(*values, **kwargs):
|
||||
upper = kwargs.get('upper', False)
|
||||
string_ = kwargs.get('string', False) or lower or upper
|
||||
to_int = kwargs.get('int', False)
|
||||
space = kwargs.get('space', ' ')
|
||||
|
||||
def validator(value):
|
||||
if string_:
|
||||
value = string(value)
|
||||
value = value.replace(' ', space)
|
||||
if to_int:
|
||||
value = int_(value)
|
||||
if lower:
|
||||
@@ -640,7 +644,7 @@ def dimensions(value):
|
||||
|
||||
def directory(value):
|
||||
value = string(value)
|
||||
path = helpers.relative_path(value)
|
||||
path = CORE.relative_path(value)
|
||||
if not os.path.exists(path):
|
||||
raise vol.Invalid(u"Could not find directory '{}'. Please make sure it exists.".format(
|
||||
path))
|
||||
@@ -651,7 +655,7 @@ def directory(value):
|
||||
|
||||
def file_(value):
|
||||
value = string(value)
|
||||
path = helpers.relative_path(value)
|
||||
path = CORE.relative_path(value)
|
||||
if not os.path.exists(path):
|
||||
raise vol.Invalid(u"Could not find file '{}'. Please make sure it exists.".format(
|
||||
path))
|
||||
@@ -706,5 +710,5 @@ MQTT_COMMAND_COMPONENT_SCHEMA = MQTT_COMPONENT_SCHEMA.extend({
|
||||
})
|
||||
|
||||
COMPONENT_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_SETUP_PRIORITY): vol.Coerce(float)
|
||||
vol.Optional(CONF_SETUP_PRIORITY): float_
|
||||
})
|
||||
|
||||
@@ -91,6 +91,7 @@ CONF_ABOVE = 'above'
|
||||
CONF_BELOW = 'below'
|
||||
CONF_ON = 'on'
|
||||
CONF_IF = 'if'
|
||||
CONF_WHILE = 'while'
|
||||
CONF_THEN = 'then'
|
||||
CONF_BINARY = 'binary'
|
||||
CONF_WHITE = 'white'
|
||||
@@ -371,7 +372,20 @@ CONF_UPDATE_ON_BOOT = 'update_on_boot'
|
||||
CONF_INITIAL_VALUE = 'initial_value'
|
||||
CONF_RESTORE_VALUE = 'restore_value'
|
||||
CONF_PINS = 'pins'
|
||||
|
||||
CONF_SENSORS = 'sensors'
|
||||
CONF_BINARY_SENSORS = 'binary_sensors'
|
||||
CONF_OUTPUTS = 'outputs'
|
||||
CONF_SWITCHES = 'switches'
|
||||
CONF_TEXT_SENSORS = 'text_sensors'
|
||||
CONF_INCLUDES = 'includes'
|
||||
CONF_LIBRARIES = 'libraries'
|
||||
CONF_PIN_A = 'pin_a'
|
||||
CONF_PIN_B = 'pin_b'
|
||||
CONF_PIN_C = 'pin_c'
|
||||
CONF_PIN_D = 'pin_d'
|
||||
CONF_SLEEP_WHEN_DONE = 'sleep_when_done'
|
||||
CONF_STEP_MODE = 'step_mode'
|
||||
CONF_COMPONENTS = 'components'
|
||||
|
||||
ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'
|
||||
ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage'
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
import math
|
||||
import re
|
||||
import collections
|
||||
from collections import OrderedDict
|
||||
import inspect
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
|
||||
from esphomeyaml.const import CONF_ARDUINO_VERSION, CONF_DOMAIN, CONF_ESPHOMELIB_VERSION, \
|
||||
CONF_ESPHOMEYAML, CONF_HOSTNAME, CONF_LOCAL, CONF_MANUAL_IP, CONF_STATIC_IP, CONF_WIFI, \
|
||||
ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.helpers import ensure_unique_string
|
||||
|
||||
# pylint: disable=unused-import, wrong-import-order
|
||||
from typing import Any, Dict, List # noqa
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ESPHomeYAMLError(Exception):
|
||||
class EsphomeyamlError(Exception):
|
||||
"""General esphomeyaml exception occurred."""
|
||||
pass
|
||||
|
||||
@@ -35,10 +49,10 @@ class MACAddress(object):
|
||||
return ':'.join('{:02X}'.format(part) for part in self.parts)
|
||||
|
||||
def as_hex(self):
|
||||
import esphomeyaml.helpers
|
||||
from esphomeyaml.cpp_generator import RawExpression
|
||||
|
||||
num = ''.join('{:02X}'.format(part) for part in self.parts)
|
||||
return esphomeyaml.helpers.RawExpression('0x{}ULL'.format(num))
|
||||
return RawExpression('0x{}ULL'.format(num))
|
||||
|
||||
|
||||
def is_approximately_integer(value):
|
||||
@@ -195,11 +209,36 @@ class TimePeriodSeconds(TimePeriod):
|
||||
pass
|
||||
|
||||
|
||||
LAMBDA_PROG = re.compile(r'id\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)(\.?)')
|
||||
|
||||
|
||||
class Lambda(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
self.parts = re.split(r'id\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)(\.?)', value)
|
||||
self.requires_ids = [ID(self.parts[i]) for i in range(1, len(self.parts), 3)]
|
||||
self._value = value
|
||||
self._parts = None
|
||||
self._requires_ids = None
|
||||
|
||||
@property
|
||||
def parts(self):
|
||||
if self._parts is None:
|
||||
self._parts = re.split(LAMBDA_PROG, self._value)
|
||||
return self._parts
|
||||
|
||||
@property
|
||||
def requires_ids(self):
|
||||
if self._requires_ids is None:
|
||||
self._requires_ids = [ID(self.parts[i]) for i in range(1, len(self.parts), 3)]
|
||||
return self._requires_ids
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = value
|
||||
self._parts = None
|
||||
self._requires_ids = None
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
@@ -208,19 +247,6 @@ class Lambda(object):
|
||||
return u'Lambda<{}>'.format(self.value)
|
||||
|
||||
|
||||
def ensure_unique_string(preferred_string, current_strings):
|
||||
test_string = preferred_string
|
||||
current_strings_set = set(current_strings)
|
||||
|
||||
tries = 1
|
||||
|
||||
while test_string in current_strings_set:
|
||||
tries += 1
|
||||
test_string = u"{}_{}".format(preferred_string, tries)
|
||||
|
||||
return test_string
|
||||
|
||||
|
||||
class ID(object):
|
||||
def __init__(self, id, is_declaration=False, type=None):
|
||||
self.id = id
|
||||
@@ -253,8 +279,147 @@ class ID(object):
|
||||
return hash(self.id)
|
||||
|
||||
|
||||
CONFIG_PATH = None
|
||||
ESP_PLATFORM = ''
|
||||
BOARD = ''
|
||||
RAW_CONFIG = None
|
||||
NAME = ''
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
class EsphomeyamlCore(object):
|
||||
def __init__(self):
|
||||
# The name of the node
|
||||
self.name = None # type: str
|
||||
# The relative path to the configuration YAML
|
||||
self.config_path = None # type: str
|
||||
# The relative path to where all build files are stored
|
||||
self.build_path = None # type: str
|
||||
# The platform (ESP8266, ESP32) of this device
|
||||
self.esp_platform = None # type: str
|
||||
# The board that's used (for example nodemcuv2)
|
||||
self.board = None # type: str
|
||||
# The full raw configuration
|
||||
self.raw_config = {} # type: ConfigType
|
||||
# The validated configuration, this is None until the config has been validated
|
||||
self.config = {} # type: ConfigType
|
||||
# The pending tasks in the task queue (mostly for C++ generation)
|
||||
self.pending_tasks = collections.deque()
|
||||
# The variable cache, for each ID this holds a MockObj of the variable obj
|
||||
self.variables = {} # type: Dict[str, MockObj]
|
||||
# The list of expressions for the C++ generation
|
||||
self.expressions = [] # type: List[Expression]
|
||||
|
||||
@property
|
||||
def address(self): # type: () -> str
|
||||
if CONF_MANUAL_IP in self.config[CONF_WIFI]:
|
||||
return str(self.config[CONF_WIFI][CONF_MANUAL_IP][CONF_STATIC_IP])
|
||||
elif CONF_HOSTNAME in self.config[CONF_WIFI]:
|
||||
hostname = self.config[CONF_WIFI][CONF_HOSTNAME]
|
||||
else:
|
||||
hostname = self.name
|
||||
return hostname + self.config[CONF_WIFI][CONF_DOMAIN]
|
||||
|
||||
@property
|
||||
def esphomelib_version(self): # type: () -> Dict[str, str]
|
||||
return self.config[CONF_ESPHOMEYAML][CONF_ESPHOMELIB_VERSION]
|
||||
|
||||
@property
|
||||
def is_local_esphomelib_copy(self):
|
||||
return CONF_LOCAL in self.esphomelib_version
|
||||
|
||||
@property
|
||||
def arduino_version(self): # type: () -> str
|
||||
return self.config[CONF_ESPHOMEYAML][CONF_ARDUINO_VERSION]
|
||||
|
||||
@property
|
||||
def config_dir(self):
|
||||
return os.path.dirname(self.config_path)
|
||||
|
||||
@property
|
||||
def config_filename(self):
|
||||
return os.path.basename(self.config_path)
|
||||
|
||||
def relative_path(self, *path):
|
||||
path_ = os.path.expanduser(os.path.join(*path))
|
||||
return os.path.join(self.config_dir, path_)
|
||||
|
||||
def relative_build_path(self, *path):
|
||||
path_ = os.path.expanduser(os.path.join(*path))
|
||||
return os.path.join(self.build_path, path_)
|
||||
|
||||
@property
|
||||
def firmware_bin(self):
|
||||
return self.relative_build_path('.pioenvs', self.name, 'firmware.bin')
|
||||
|
||||
@property
|
||||
def is_esp8266(self):
|
||||
if self.esp_platform is None:
|
||||
raise ValueError
|
||||
return self.esp_platform == ESP_PLATFORM_ESP8266
|
||||
|
||||
@property
|
||||
def is_esp32(self):
|
||||
if self.esp_platform is None:
|
||||
raise ValueError
|
||||
return self.esp_platform == ESP_PLATFORM_ESP32
|
||||
|
||||
def add_job(self, func, *args, **kwargs):
|
||||
domain = kwargs.get('domain')
|
||||
if inspect.isgeneratorfunction(func):
|
||||
def func_():
|
||||
yield
|
||||
for _ in func(*args):
|
||||
yield
|
||||
else:
|
||||
def func_():
|
||||
yield
|
||||
func(*args)
|
||||
gen = func_()
|
||||
self.pending_tasks.append((gen, domain))
|
||||
return gen
|
||||
|
||||
def flush_tasks(self):
|
||||
i = 0
|
||||
while self.pending_tasks:
|
||||
i += 1
|
||||
if i > 1000000:
|
||||
raise EsphomeyamlError("Circular dependency detected!")
|
||||
|
||||
task, domain = self.pending_tasks.popleft()
|
||||
_LOGGER.debug("Executing task for domain=%s", domain)
|
||||
try:
|
||||
task.next()
|
||||
self.pending_tasks.append((task, domain))
|
||||
except StopIteration:
|
||||
_LOGGER.debug(" -> %s finished", domain)
|
||||
|
||||
def add(self, expression, require=True):
|
||||
from esphomeyaml.cpp_generator import Expression
|
||||
|
||||
if require and isinstance(expression, Expression):
|
||||
expression.require()
|
||||
self.expressions.append(expression)
|
||||
_LOGGER.debug("Adding: %s", expression)
|
||||
return expression
|
||||
|
||||
def get_variable(self, id):
|
||||
while True:
|
||||
if id in self.variables:
|
||||
yield self.variables[id]
|
||||
return
|
||||
_LOGGER.debug("Waiting for variable %s", id)
|
||||
yield None
|
||||
|
||||
def get_variable_with_full_id(self, id):
|
||||
while True:
|
||||
if id in self.variables:
|
||||
for k, v in self.variables.iteritems():
|
||||
if k == id:
|
||||
yield (k, v)
|
||||
return
|
||||
_LOGGER.debug("Waiting for variable %s", id)
|
||||
yield None, None
|
||||
|
||||
def register_variable(self, id, obj):
|
||||
_LOGGER.debug("Registered variable %s of type %s", id.id, id.type)
|
||||
self.variables[id] = obj
|
||||
|
||||
|
||||
CORE = EsphomeyamlCore()
|
||||
|
||||
ConfigType = Dict[str, Any]
|
||||
CoreType = EsphomeyamlCore
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import automation, core, pins
|
||||
from esphomeyaml import automation, pins
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import ARDUINO_VERSION_ESP32_DEV, ARDUINO_VERSION_ESP8266_DEV, \
|
||||
CONF_ARDUINO_VERSION, CONF_BOARD, CONF_BOARD_FLASH_MODE, CONF_BRANCH, CONF_BUILD_PATH, \
|
||||
CONF_COMMIT, CONF_ESPHOMELIB_VERSION, CONF_ESPHOMEYAML, CONF_LOCAL, CONF_NAME, CONF_ON_BOOT, \
|
||||
CONF_ON_LOOP, CONF_ON_SHUTDOWN, CONF_PLATFORM, CONF_PRIORITY, CONF_REPOSITORY, CONF_TAG, \
|
||||
CONF_TRIGGER_ID, CONF_USE_CUSTOM_CODE, ESPHOMELIB_VERSION, ESP_PLATFORM_ESP32, \
|
||||
ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import App, NoArg, Pvariable, RawExpression, add, const_char_p, \
|
||||
esphomelib_ns, relative_path
|
||||
from esphomeyaml.util import safe_print
|
||||
ESP_PLATFORM_ESP8266, CONF_LIBRARIES, CONF_INCLUDES
|
||||
from esphomeyaml.core import CORE, EsphomeyamlError
|
||||
from esphomeyaml.cpp_generator import Pvariable, RawExpression, add
|
||||
from esphomeyaml.cpp_types import App, NoArg, const_char_ptr, esphomelib_ns
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
LIBRARY_URI_REPO = u'https://github.com/OttoWinter/esphomelib.git'
|
||||
GITHUB_ARCHIVE_ZIP = u'https://github.com/OttoWinter/esphomelib/archive/{}.zip'
|
||||
|
||||
BUILD_FLASH_MODES = ['qio', 'qout', 'dio', 'dout']
|
||||
StartupTrigger = esphomelib_ns.StartupTrigger
|
||||
ShutdownTrigger = esphomelib_ns.ShutdownTrigger
|
||||
LoopTrigger = esphomelib_ns.LoopTrigger
|
||||
|
||||
VERSION_REGEX = re.compile(r'^[0-9]+\.[0-9]+\.[0-9]+(?:-beta)?(?:-alpha)?$')
|
||||
VERSION_REGEX = re.compile(r'^[0-9]+\.[0-9]+\.[0-9]+(?:[ab]\d+)?$')
|
||||
|
||||
|
||||
def validate_board(value):
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
if CORE.is_esp8266:
|
||||
board_pins = pins.ESP8266_BOARD_PINS
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
elif CORE.is_esp32:
|
||||
board_pins = pins.ESP32_BOARD_PINS
|
||||
else:
|
||||
raise NotImplementedError
|
||||
@@ -68,7 +67,7 @@ def validate_simple_esphomelib_version(value):
|
||||
|
||||
def validate_local_esphomelib_version(value):
|
||||
value = cv.directory(value)
|
||||
path = relative_path(value)
|
||||
path = CORE.relative_path(value)
|
||||
library_json = os.path.join(path, 'library.json')
|
||||
if not os.path.exists(library_json):
|
||||
raise vol.Invalid(u"Could not find '{}' file. '{}' does not seem to point to an "
|
||||
@@ -116,14 +115,14 @@ PLATFORMIO_ESP8266_LUT = {
|
||||
'2.4.1': 'espressif8266@1.7.3',
|
||||
'2.4.0': 'espressif8266@1.6.0',
|
||||
'2.3.0': 'espressif8266@1.5.0',
|
||||
'RECOMMENDED': 'espressif8266@>=1.8.0',
|
||||
'RECOMMENDED': 'espressif8266@1.8.0',
|
||||
'LATEST': 'espressif8266',
|
||||
'DEV': ARDUINO_VERSION_ESP8266_DEV,
|
||||
}
|
||||
|
||||
PLATFORMIO_ESP32_LUT = {
|
||||
'1.0.0': 'espressif32@1.4.0',
|
||||
'RECOMMENDED': 'espressif32@>=1.4.0',
|
||||
'RECOMMENDED': 'espressif32@1.5.0',
|
||||
'LATEST': 'espressif32',
|
||||
'DEV': ARDUINO_VERSION_ESP32_DEV,
|
||||
}
|
||||
@@ -132,7 +131,7 @@ PLATFORMIO_ESP32_LUT = {
|
||||
def validate_arduino_version(value):
|
||||
value = cv.string_strict(value)
|
||||
value_ = value.upper()
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
if CORE.is_esp8266:
|
||||
if VERSION_REGEX.match(value) is not None and value_ not in PLATFORMIO_ESP8266_LUT:
|
||||
raise vol.Invalid("Unfortunately the arduino framework version '{}' is unsupported "
|
||||
"at this time. You can override this by manually using "
|
||||
@@ -140,7 +139,7 @@ def validate_arduino_version(value):
|
||||
if value_ in PLATFORMIO_ESP8266_LUT:
|
||||
return PLATFORMIO_ESP8266_LUT[value_]
|
||||
return value
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
elif CORE.is_esp32:
|
||||
if VERSION_REGEX.match(value) is not None and value_ not in PLATFORMIO_ESP32_LUT:
|
||||
raise vol.Invalid("Unfortunately the arduino framework version '{}' is unsupported "
|
||||
"at this time. You can override this by manually using "
|
||||
@@ -148,12 +147,11 @@ def validate_arduino_version(value):
|
||||
if value_ in PLATFORMIO_ESP32_LUT:
|
||||
return PLATFORMIO_ESP32_LUT[value_]
|
||||
return value
|
||||
else:
|
||||
raise NotImplementedError
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def default_build_path():
|
||||
return core.NAME
|
||||
return CORE.name
|
||||
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
@@ -169,7 +167,7 @@ CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_BOARD_FLASH_MODE): cv.one_of(*BUILD_FLASH_MODES, lower=True),
|
||||
vol.Optional(CONF_ON_BOOT): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(StartupTrigger),
|
||||
vol.Optional(CONF_PRIORITY): vol.Coerce(float),
|
||||
vol.Optional(CONF_PRIORITY): cv.float_,
|
||||
}),
|
||||
vol.Optional(CONF_ON_SHUTDOWN): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(ShutdownTrigger),
|
||||
@@ -177,6 +175,8 @@ CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_ON_LOOP): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(LoopTrigger),
|
||||
}),
|
||||
vol.Optional(CONF_INCLUDES): vol.All(cv.ensure_list, [cv.file_]),
|
||||
vol.Optional(CONF_LIBRARIES): vol.All(cv.ensure_list, [cv.string_strict]),
|
||||
|
||||
vol.Optional('library_uri'): cv.invalid("The library_uri option has been removed in 1.8.0 and "
|
||||
"was moved into the esphomelib_version option."),
|
||||
@@ -187,59 +187,23 @@ CONFIG_SCHEMA = vol.Schema({
|
||||
|
||||
def preload_core_config(config):
|
||||
if CONF_ESPHOMEYAML not in config:
|
||||
raise ESPHomeYAMLError(u"No esphomeyaml section in config")
|
||||
raise EsphomeyamlError(u"No esphomeyaml section in config")
|
||||
core_conf = config[CONF_ESPHOMEYAML]
|
||||
if CONF_PLATFORM not in core_conf:
|
||||
raise ESPHomeYAMLError("esphomeyaml.platform not specified.")
|
||||
raise EsphomeyamlError("esphomeyaml.platform not specified.")
|
||||
if CONF_BOARD not in core_conf:
|
||||
raise ESPHomeYAMLError("esphomeyaml.board not specified.")
|
||||
raise EsphomeyamlError("esphomeyaml.board not specified.")
|
||||
if CONF_NAME not in core_conf:
|
||||
raise ESPHomeYAMLError("esphomeyaml.name not specified.")
|
||||
raise EsphomeyamlError("esphomeyaml.name not specified.")
|
||||
|
||||
try:
|
||||
core.ESP_PLATFORM = validate_platform(core_conf[CONF_PLATFORM])
|
||||
core.BOARD = validate_board(core_conf[CONF_BOARD])
|
||||
core.NAME = cv.valid_name(core_conf[CONF_NAME])
|
||||
CORE.esp_platform = validate_platform(core_conf[CONF_PLATFORM])
|
||||
CORE.board = validate_board(core_conf[CONF_BOARD])
|
||||
CORE.name = cv.valid_name(core_conf[CONF_NAME])
|
||||
CORE.build_path = CORE.relative_path(
|
||||
cv.string(core_conf.get(CONF_BUILD_PATH, default_build_path())))
|
||||
except vol.Invalid as e:
|
||||
raise ESPHomeYAMLError(unicode(e))
|
||||
|
||||
|
||||
def run_command(*args):
|
||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
rc = p.returncode
|
||||
return rc, stdout, stderr
|
||||
|
||||
|
||||
def update_esphomelib_repo(config):
|
||||
esphomelib_version = config[CONF_ESPHOMELIB_VERSION]
|
||||
if CONF_REPOSITORY not in esphomelib_version:
|
||||
return
|
||||
|
||||
build_path = relative_path(config[CONF_BUILD_PATH])
|
||||
esphomelib_path = os.path.join(build_path, '.piolibdeps', 'esphomelib')
|
||||
is_default_branch = all(x not in esphomelib_version
|
||||
for x in (CONF_BRANCH, CONF_TAG, CONF_COMMIT))
|
||||
if not (CONF_BRANCH in esphomelib_version or is_default_branch):
|
||||
# Git commit hash or tag cannot be updated
|
||||
return
|
||||
|
||||
rc, _, _ = run_command('git', '-C', esphomelib_path, '--help')
|
||||
if rc != 0:
|
||||
# git not installed or repo not downloaded yet
|
||||
return
|
||||
rc, _, _ = run_command('git', '-C', esphomelib_path, 'diff-index', '--quiet', 'HEAD', '--')
|
||||
if rc != 0:
|
||||
# local changes, cannot update
|
||||
_LOGGER.warn("Local changes in esphomelib copy from git. Will not auto-update.")
|
||||
return
|
||||
_LOGGER.info("Updating esphomelib copy from git (%s)", esphomelib_path)
|
||||
rc, stdout, _ = run_command('git', '-c', 'color.ui=always', '-C', esphomelib_path,
|
||||
'pull', '--stat')
|
||||
if rc != 0:
|
||||
_LOGGER.warn("Couldn't auto-update local git copy of esphomelib.")
|
||||
return
|
||||
safe_print(stdout.strip())
|
||||
raise EsphomeyamlError(unicode(e))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
@@ -252,13 +216,24 @@ def to_code(config):
|
||||
|
||||
for conf in config.get(CONF_ON_SHUTDOWN, []):
|
||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], ShutdownTrigger.new())
|
||||
automation.build_automation(trigger, const_char_p, conf)
|
||||
automation.build_automation(trigger, const_char_ptr, conf)
|
||||
|
||||
for conf in config.get(CONF_ON_LOOP, []):
|
||||
rhs = App.register_component(LoopTrigger.new())
|
||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||
automation.build_automation(trigger, NoArg, conf)
|
||||
|
||||
update_esphomelib_repo(config)
|
||||
|
||||
add(App.set_compilation_datetime(RawExpression('__DATE__ ", " __TIME__')))
|
||||
|
||||
|
||||
def lib_deps(config):
|
||||
return set(config.get(CONF_LIBRARIES, []))
|
||||
|
||||
|
||||
def includes(config):
|
||||
ret = []
|
||||
for include in config.get(CONF_INCLUDES, []):
|
||||
path = CORE.relative_path(include)
|
||||
res = os.path.relpath(path, CORE.relative_build_path('src', 'main.cpp'))
|
||||
ret.append(u'#include "{}"'.format(res))
|
||||
return ret
|
||||
|
||||
539
esphomeyaml/cpp_generator.py
Normal file
539
esphomeyaml/cpp_generator.py
Normal file
@@ -0,0 +1,539 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from esphomeyaml.core import CORE, HexInt, Lambda, TimePeriod, TimePeriodMicroseconds, \
|
||||
TimePeriodMilliseconds, TimePeriodSeconds
|
||||
from esphomeyaml.helpers import cpp_string_escape, indent_all_but_first_and_last
|
||||
|
||||
# pylint: disable=unused-import, wrong-import-order
|
||||
from typing import Any, Generator, List, Optional, Tuple, Union # noqa
|
||||
from esphomeyaml.core import ID # noqa
|
||||
|
||||
|
||||
class Expression(object):
|
||||
def __init__(self):
|
||||
self.requires = []
|
||||
self.required = False
|
||||
|
||||
def __str__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def require(self):
|
||||
self.required = True
|
||||
for require in self.requires:
|
||||
if require.required:
|
||||
continue
|
||||
require.require()
|
||||
|
||||
def has_side_effects(self):
|
||||
return self.required
|
||||
|
||||
|
||||
SafeExpType = Union[Expression, bool, str, unicode, int, long, float, TimePeriod]
|
||||
|
||||
|
||||
class RawExpression(Expression):
|
||||
def __init__(self, text): # type: (Union[str, unicode]) -> None
|
||||
super(RawExpression, self).__init__()
|
||||
self.text = text
|
||||
|
||||
def __str__(self):
|
||||
return str(self.text)
|
||||
|
||||
|
||||
# pylint: disable=redefined-builtin
|
||||
class AssignmentExpression(Expression):
|
||||
def __init__(self, type, modifier, name, rhs, obj):
|
||||
super(AssignmentExpression, self).__init__()
|
||||
self.type = type
|
||||
self.modifier = modifier
|
||||
self.name = name
|
||||
self.rhs = safe_exp(rhs)
|
||||
self.requires.append(self.rhs)
|
||||
self.obj = obj
|
||||
|
||||
def __str__(self):
|
||||
type_ = self.type
|
||||
return u"{} {}{} = {}".format(type_, self.modifier, self.name, self.rhs)
|
||||
|
||||
def has_side_effects(self):
|
||||
return self.rhs.has_side_effects()
|
||||
|
||||
|
||||
class ExpressionList(Expression):
|
||||
def __init__(self, *args):
|
||||
super(ExpressionList, self).__init__()
|
||||
# Remove every None on end
|
||||
args = list(args)
|
||||
while args and args[-1] is None:
|
||||
args.pop()
|
||||
self.args = []
|
||||
for arg in args:
|
||||
exp = safe_exp(arg)
|
||||
self.requires.append(exp)
|
||||
self.args.append(exp)
|
||||
|
||||
def __str__(self):
|
||||
text = u", ".join(unicode(x) for x in self.args)
|
||||
return indent_all_but_first_and_last(text)
|
||||
|
||||
|
||||
class TemplateArguments(Expression):
|
||||
def __init__(self, *args): # type: (*SafeExpType) -> None
|
||||
super(TemplateArguments, self).__init__()
|
||||
self.args = ExpressionList(*args)
|
||||
self.requires.append(self.args)
|
||||
|
||||
def __str__(self):
|
||||
return u'<{}>'.format(self.args)
|
||||
|
||||
|
||||
class CallExpression(Expression):
|
||||
def __init__(self, base, *args): # type: (Expression, *SafeExpType) -> None
|
||||
super(CallExpression, self).__init__()
|
||||
self.base = base
|
||||
if args and isinstance(args[0], TemplateArguments):
|
||||
self.template_args = args[0]
|
||||
self.requires.append(self.template_args)
|
||||
args = args[1:]
|
||||
else:
|
||||
self.template_args = None
|
||||
self.args = ExpressionList(*args)
|
||||
self.requires.append(self.args)
|
||||
|
||||
def __str__(self):
|
||||
if self.template_args is not None:
|
||||
return u'{}{}({})'.format(self.base, self.template_args, self.args)
|
||||
return u'{}({})'.format(self.base, self.args)
|
||||
|
||||
|
||||
class StructInitializer(Expression):
|
||||
def __init__(self, base, *args): # type: (Expression, *Tuple[str, SafeExpType]) -> None
|
||||
super(StructInitializer, self).__init__()
|
||||
self.base = base
|
||||
if isinstance(base, Expression):
|
||||
self.requires.append(base)
|
||||
if not isinstance(args, OrderedDict):
|
||||
args = OrderedDict(args)
|
||||
self.args = OrderedDict()
|
||||
for key, value in args.iteritems():
|
||||
if value is None:
|
||||
continue
|
||||
exp = safe_exp(value)
|
||||
self.args[key] = exp
|
||||
self.requires.append(exp)
|
||||
|
||||
def __str__(self):
|
||||
cpp = u'{}{{\n'.format(self.base)
|
||||
for key, value in self.args.iteritems():
|
||||
cpp += u' .{} = {},\n'.format(key, value)
|
||||
cpp += u'}'
|
||||
return cpp
|
||||
|
||||
|
||||
class ArrayInitializer(Expression):
|
||||
def __init__(self, *args, **kwargs): # type: (*Any, **Any) -> None
|
||||
super(ArrayInitializer, self).__init__()
|
||||
self.multiline = kwargs.get('multiline', True)
|
||||
self.args = []
|
||||
for arg in args:
|
||||
if arg is None:
|
||||
continue
|
||||
exp = safe_exp(arg)
|
||||
self.args.append(exp)
|
||||
self.requires.append(exp)
|
||||
|
||||
def __str__(self):
|
||||
if not self.args:
|
||||
return u'{}'
|
||||
if self.multiline:
|
||||
cpp = u'{\n'
|
||||
for arg in self.args:
|
||||
cpp += u' {},\n'.format(arg)
|
||||
cpp += u'}'
|
||||
else:
|
||||
cpp = u'{' + u', '.join(str(arg) for arg in self.args) + u'}'
|
||||
return cpp
|
||||
|
||||
|
||||
class ParameterExpression(Expression):
|
||||
def __init__(self, type, id):
|
||||
super(ParameterExpression, self).__init__()
|
||||
self.type = type
|
||||
self.id = id
|
||||
|
||||
def __str__(self):
|
||||
return u"{} {}".format(self.type, self.id)
|
||||
|
||||
|
||||
class ParameterListExpression(Expression):
|
||||
def __init__(self, *parameters):
|
||||
super(ParameterListExpression, self).__init__()
|
||||
self.parameters = []
|
||||
for parameter in parameters:
|
||||
if not isinstance(parameter, ParameterExpression):
|
||||
parameter = ParameterExpression(*parameter)
|
||||
self.parameters.append(parameter)
|
||||
self.requires.append(parameter)
|
||||
|
||||
def __str__(self):
|
||||
return u", ".join(unicode(x) for x in self.parameters)
|
||||
|
||||
|
||||
class LambdaExpression(Expression):
|
||||
def __init__(self, parts, parameters, capture='=', return_type=None):
|
||||
super(LambdaExpression, self).__init__()
|
||||
self.parts = parts
|
||||
if not isinstance(parameters, ParameterListExpression):
|
||||
parameters = ParameterListExpression(*parameters)
|
||||
self.parameters = parameters
|
||||
self.requires.append(self.parameters)
|
||||
self.capture = capture
|
||||
self.return_type = return_type
|
||||
if return_type is not None:
|
||||
self.requires.append(return_type)
|
||||
for i in range(1, len(parts), 3):
|
||||
self.requires.append(parts[i])
|
||||
|
||||
def __str__(self):
|
||||
cpp = u'[{}]({})'.format(self.capture, self.parameters)
|
||||
if self.return_type is not None:
|
||||
cpp += u' -> {}'.format(self.return_type)
|
||||
cpp += u' {{\n{}\n}}'.format(self.content)
|
||||
return indent_all_but_first_and_last(cpp)
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
return u''.join(unicode(part) for part in self.parts)
|
||||
|
||||
|
||||
class Literal(Expression):
|
||||
def __str__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class StringLiteral(Literal):
|
||||
def __init__(self, string): # type: (Union[str, unicode]) -> None
|
||||
super(StringLiteral, self).__init__()
|
||||
self.string = string
|
||||
|
||||
def __str__(self):
|
||||
return u'{}'.format(cpp_string_escape(self.string))
|
||||
|
||||
|
||||
class IntLiteral(Literal):
|
||||
def __init__(self, i): # type: (Union[int, long]) -> None
|
||||
super(IntLiteral, self).__init__()
|
||||
self.i = i
|
||||
|
||||
def __str__(self):
|
||||
if self.i > 4294967295:
|
||||
return u'{}ULL'.format(self.i)
|
||||
if self.i > 2147483647:
|
||||
return u'{}UL'.format(self.i)
|
||||
if self.i < -2147483648:
|
||||
return u'{}LL'.format(self.i)
|
||||
return unicode(self.i)
|
||||
|
||||
|
||||
class BoolLiteral(Literal):
|
||||
def __init__(self, binary): # type: (bool) -> None
|
||||
super(BoolLiteral, self).__init__()
|
||||
self.binary = binary
|
||||
|
||||
def __str__(self):
|
||||
return u"true" if self.binary else u"false"
|
||||
|
||||
|
||||
class HexIntLiteral(Literal):
|
||||
def __init__(self, i): # type: (int) -> None
|
||||
super(HexIntLiteral, self).__init__()
|
||||
self.i = HexInt(i)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.i)
|
||||
|
||||
|
||||
class FloatLiteral(Literal):
|
||||
def __init__(self, value): # type: (float) -> None
|
||||
super(FloatLiteral, self).__init__()
|
||||
self.float_ = value
|
||||
|
||||
def __str__(self):
|
||||
return u"{:f}f".format(self.float_)
|
||||
|
||||
|
||||
# pylint: disable=bad-continuation
|
||||
def safe_exp(obj # type: Union[Expression, bool, str, unicode, int, long, float, TimePeriod]
|
||||
):
|
||||
# type: (...) -> Expression
|
||||
if isinstance(obj, Expression):
|
||||
return obj
|
||||
elif isinstance(obj, bool):
|
||||
return BoolLiteral(obj)
|
||||
elif isinstance(obj, (str, unicode)):
|
||||
return StringLiteral(obj)
|
||||
elif isinstance(obj, HexInt):
|
||||
return HexIntLiteral(obj)
|
||||
elif isinstance(obj, (int, long)):
|
||||
return IntLiteral(obj)
|
||||
elif isinstance(obj, float):
|
||||
return FloatLiteral(obj)
|
||||
elif isinstance(obj, TimePeriodMicroseconds):
|
||||
return IntLiteral(int(obj.total_microseconds))
|
||||
elif isinstance(obj, TimePeriodMilliseconds):
|
||||
return IntLiteral(int(obj.total_milliseconds))
|
||||
elif isinstance(obj, TimePeriodSeconds):
|
||||
return IntLiteral(int(obj.total_seconds))
|
||||
raise ValueError(u"Object is not an expression", obj)
|
||||
|
||||
|
||||
class Statement(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class RawStatement(Statement):
|
||||
def __init__(self, text):
|
||||
super(RawStatement, self).__init__()
|
||||
self.text = text
|
||||
|
||||
def __str__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
class ExpressionStatement(Statement):
|
||||
def __init__(self, expression):
|
||||
super(ExpressionStatement, self).__init__()
|
||||
self.expression = safe_exp(expression)
|
||||
|
||||
def __str__(self):
|
||||
return u"{};".format(self.expression)
|
||||
|
||||
|
||||
def statement(expression): # type: (Union[Expression, Statement]) -> Statement
|
||||
if isinstance(expression, Statement):
|
||||
return expression
|
||||
return ExpressionStatement(expression)
|
||||
|
||||
|
||||
def variable(id, # type: ID
|
||||
rhs, # type: Expression
|
||||
type=None # type: MockObj
|
||||
):
|
||||
# type: (...) -> MockObj
|
||||
rhs = safe_exp(rhs)
|
||||
obj = MockObj(id, u'.')
|
||||
id.type = type or id.type
|
||||
assignment = AssignmentExpression(id.type, '', id, rhs, obj)
|
||||
CORE.add(assignment)
|
||||
CORE.register_variable(id, obj)
|
||||
obj.requires.append(assignment)
|
||||
return obj
|
||||
|
||||
|
||||
def Pvariable(id, # type: ID
|
||||
rhs, # type: Expression
|
||||
has_side_effects=True, # type: bool
|
||||
type=None # type: MockObj
|
||||
):
|
||||
# type: (...) -> MockObj
|
||||
rhs = safe_exp(rhs)
|
||||
if not has_side_effects and hasattr(rhs, '_has_side_effects'):
|
||||
# pylint: disable=attribute-defined-outside-init, protected-access
|
||||
rhs._has_side_effects = False
|
||||
obj = MockObj(id, u'->', has_side_effects=has_side_effects)
|
||||
id.type = type or id.type
|
||||
assignment = AssignmentExpression(id.type, '*', id, rhs, obj)
|
||||
CORE.add(assignment)
|
||||
CORE.register_variable(id, obj)
|
||||
obj.requires.append(assignment)
|
||||
return obj
|
||||
|
||||
|
||||
def add(expression, # type: Union[Expression, Statement]
|
||||
require=True # type: bool
|
||||
):
|
||||
# type: (...) -> None
|
||||
CORE.add(expression, require=require)
|
||||
|
||||
|
||||
def get_variable(id): # type: (ID) -> Generator[MockObj]
|
||||
for var in CORE.get_variable(id):
|
||||
yield None
|
||||
yield var
|
||||
|
||||
|
||||
def process_lambda(value, # type: Lambda
|
||||
parameters, # type: List[Tuple[Expression, str]]
|
||||
capture='=', # type: str
|
||||
return_type=None # type: Optional[Expression]
|
||||
):
|
||||
# type: (...) -> Generator[LambdaExpression]
|
||||
from esphomeyaml.components.globals import GlobalVariableComponent
|
||||
|
||||
if value is None:
|
||||
yield
|
||||
return
|
||||
parts = value.parts[:]
|
||||
for i, id in enumerate(value.requires_ids):
|
||||
for full_id, var in CORE.get_variable_with_full_id(id):
|
||||
yield
|
||||
if full_id is not None and isinstance(full_id.type, MockObjClass) and \
|
||||
full_id.type.inherits_from(GlobalVariableComponent):
|
||||
parts[i * 3 + 1] = var.value()
|
||||
continue
|
||||
|
||||
if parts[i * 3 + 2] == '.':
|
||||
parts[i * 3 + 1] = var._
|
||||
else:
|
||||
parts[i * 3 + 1] = var
|
||||
parts[i * 3 + 2] = ''
|
||||
yield LambdaExpression(parts, parameters, capture, return_type)
|
||||
|
||||
|
||||
def templatable(value, # type: Any
|
||||
input_type, # type: Expression
|
||||
output_type # type: Optional[Expression]
|
||||
):
|
||||
if isinstance(value, Lambda):
|
||||
lambda_ = None
|
||||
for lambda_ in process_lambda(value, [(input_type, 'x')], return_type=output_type):
|
||||
yield None
|
||||
yield lambda_
|
||||
else:
|
||||
yield value
|
||||
|
||||
|
||||
class MockObj(Expression):
|
||||
def __init__(self, base, op=u'.', has_side_effects=True):
|
||||
self.base = base
|
||||
self.op = op
|
||||
self._has_side_effects = has_side_effects
|
||||
super(MockObj, self).__init__()
|
||||
|
||||
def __getattr__(self, attr): # type: (str) -> MockObj
|
||||
if attr == u'_':
|
||||
obj = MockObj(u'{}{}'.format(self.base, self.op))
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
if attr == u'new':
|
||||
obj = MockObj(u'new {}'.format(self.base), u'->')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
next_op = u'.'
|
||||
if attr.startswith(u'P') and self.op not in ['::', '']:
|
||||
attr = attr[1:]
|
||||
next_op = u'->'
|
||||
if attr.startswith(u'_'):
|
||||
attr = attr[1:]
|
||||
obj = MockObj(u'{}{}{}'.format(self.base, self.op, attr), next_op)
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
|
||||
def __call__(self, *args, **kwargs): # type: (*Any, **Any) -> MockObj
|
||||
call = CallExpression(self.base, *args)
|
||||
obj = MockObj(call, self.op)
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(call)
|
||||
return obj
|
||||
|
||||
def __str__(self): # type: () -> unicode
|
||||
return unicode(self.base)
|
||||
|
||||
def require(self): # type: () -> None
|
||||
self.required = True
|
||||
for require in self.requires:
|
||||
if require.required:
|
||||
continue
|
||||
require.require()
|
||||
|
||||
def template(self, args): # type: (Union[TemplateArguments, Expression]) -> MockObj
|
||||
if not isinstance(args, TemplateArguments):
|
||||
args = TemplateArguments(args)
|
||||
obj = MockObj(u'{}{}'.format(self.base, args))
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(args)
|
||||
return obj
|
||||
|
||||
def namespace(self, name): # type: (str) -> MockObj
|
||||
obj = MockObj(u'{}{}{}'.format(self.base, self.op, name), u'::')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
|
||||
def class_(self, name, *parents): # type: (str, *MockObjClass) -> MockObjClass
|
||||
op = '' if self.op == '' else '::'
|
||||
obj = MockObjClass(u'{}{}{}'.format(self.base, op, name), u'.', parents=parents)
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
|
||||
def struct(self, name): # type: (str) -> MockObjClass
|
||||
return self.class_(name)
|
||||
|
||||
def enum(self, name, is_class=False): # type: (str, bool) -> MockObj
|
||||
if is_class:
|
||||
return self.namespace(name)
|
||||
|
||||
return self
|
||||
|
||||
def operator(self, name): # type: (str) -> MockObj
|
||||
if name == 'ref':
|
||||
obj = MockObj(u'{} &'.format(self.base), u'')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
if name == 'ptr':
|
||||
obj = MockObj(u'{} *'.format(self.base), u'')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
if name == "const":
|
||||
obj = MockObj(u'const {}'.format(self.base), u'')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
raise NotImplementedError
|
||||
|
||||
def has_side_effects(self): # type: () -> bool
|
||||
return self._has_side_effects
|
||||
|
||||
def __getitem__(self, item): # type: (Union[str, Expression]) -> MockObj
|
||||
next_op = u'.'
|
||||
if isinstance(item, str) and item.startswith(u'P'):
|
||||
item = item[1:]
|
||||
next_op = u'->'
|
||||
obj = MockObj(u'{}[{}]'.format(self.base, item), next_op)
|
||||
obj.requires.append(self)
|
||||
if isinstance(item, Expression):
|
||||
obj.requires.append(item)
|
||||
return obj
|
||||
|
||||
|
||||
class MockObjClass(MockObj):
|
||||
def __init__(self, *args, **kwargs):
|
||||
parens = kwargs.pop('parents')
|
||||
MockObj.__init__(self, *args, **kwargs)
|
||||
self._parents = []
|
||||
for paren in parens:
|
||||
if not isinstance(paren, MockObjClass):
|
||||
raise ValueError
|
||||
self._parents.append(paren)
|
||||
# pylint: disable=protected-access
|
||||
self._parents += paren._parents
|
||||
|
||||
def inherits_from(self, other): # type: (MockObjClass) -> bool
|
||||
if self == other:
|
||||
return True
|
||||
for parent in self._parents:
|
||||
if parent == other:
|
||||
return True
|
||||
return False
|
||||
|
||||
def template(self, args): # type: (Union[TemplateArguments, Expression]) -> MockObjClass
|
||||
if not isinstance(args, TemplateArguments):
|
||||
args = TemplateArguments(args)
|
||||
new_parents = self._parents[:]
|
||||
new_parents.append(self)
|
||||
obj = MockObjClass(u'{}{}'.format(self.base, args), parents=new_parents)
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(args)
|
||||
return obj
|
||||
49
esphomeyaml/cpp_helpers.py
Normal file
49
esphomeyaml/cpp_helpers.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from esphomeyaml.const import CONF_INVERTED, CONF_MODE, CONF_NUMBER, CONF_PCF8574, \
|
||||
CONF_SETUP_PRIORITY
|
||||
from esphomeyaml.core import CORE, EsphomeyamlError
|
||||
from esphomeyaml.cpp_generator import IntLiteral, RawExpression
|
||||
from esphomeyaml.cpp_types import GPIOInputPin, GPIOOutputPin
|
||||
|
||||
|
||||
def generic_gpio_pin_expression_(conf, mock_obj, default_mode):
|
||||
if conf is None:
|
||||
return
|
||||
number = conf[CONF_NUMBER]
|
||||
inverted = conf.get(CONF_INVERTED)
|
||||
if CONF_PCF8574 in conf:
|
||||
from esphomeyaml.components import pcf8574
|
||||
|
||||
for hub in CORE.get_variable(conf[CONF_PCF8574]):
|
||||
yield None
|
||||
|
||||
if default_mode == u'INPUT':
|
||||
mode = pcf8574.PCF8675_GPIO_MODES[conf.get(CONF_MODE, u'INPUT')]
|
||||
yield hub.make_input_pin(number, mode, inverted)
|
||||
return
|
||||
elif default_mode == u'OUTPUT':
|
||||
yield hub.make_output_pin(number, inverted)
|
||||
return
|
||||
else:
|
||||
raise EsphomeyamlError(u"Unknown default mode {}".format(default_mode))
|
||||
if len(conf) == 1:
|
||||
yield IntLiteral(number)
|
||||
return
|
||||
mode = RawExpression(conf.get(CONF_MODE, default_mode))
|
||||
yield mock_obj(number, mode, inverted)
|
||||
|
||||
|
||||
def gpio_output_pin_expression(conf):
|
||||
for exp in generic_gpio_pin_expression_(conf, GPIOOutputPin, 'OUTPUT'):
|
||||
yield None
|
||||
yield exp
|
||||
|
||||
|
||||
def gpio_input_pin_expression(conf):
|
||||
for exp in generic_gpio_pin_expression_(conf, GPIOInputPin, 'INPUT'):
|
||||
yield None
|
||||
yield exp
|
||||
|
||||
|
||||
def setup_component(obj, config):
|
||||
if CONF_SETUP_PRIORITY in config:
|
||||
CORE.add(obj.set_setup_priority(config[CONF_SETUP_PRIORITY]))
|
||||
36
esphomeyaml/cpp_types.py
Normal file
36
esphomeyaml/cpp_types.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from esphomeyaml.cpp_generator import MockObj
|
||||
|
||||
global_ns = MockObj('', '')
|
||||
float_ = global_ns.namespace('float')
|
||||
bool_ = global_ns.namespace('bool')
|
||||
std_ns = global_ns.namespace('std')
|
||||
std_string = std_ns.class_('string')
|
||||
std_vector = std_ns.class_('vector')
|
||||
uint8 = global_ns.namespace('uint8_t')
|
||||
uint16 = global_ns.namespace('uint16_t')
|
||||
uint32 = global_ns.namespace('uint32_t')
|
||||
int32 = global_ns.namespace('int32_t')
|
||||
const_char_ptr = global_ns.namespace('const char *')
|
||||
NAN = global_ns.namespace('NAN')
|
||||
esphomelib_ns = global_ns # using namespace esphomelib;
|
||||
NoArg = esphomelib_ns.class_('NoArg')
|
||||
App = esphomelib_ns.App
|
||||
io_ns = esphomelib_ns.namespace('io')
|
||||
Nameable = esphomelib_ns.class_('Nameable')
|
||||
Trigger = esphomelib_ns.class_('Trigger')
|
||||
Action = esphomelib_ns.class_('Action')
|
||||
Component = esphomelib_ns.class_('Component')
|
||||
ComponentPtr = Component.operator('ptr')
|
||||
PollingComponent = esphomelib_ns.class_('PollingComponent', Component)
|
||||
Application = esphomelib_ns.class_('Application')
|
||||
optional = esphomelib_ns.class_('optional')
|
||||
arduino_json_ns = global_ns.namespace('ArduinoJson')
|
||||
JsonObject = arduino_json_ns.class_('JsonObject')
|
||||
JsonObjectRef = JsonObject.operator('ref')
|
||||
JsonObjectConstRef = JsonObjectRef.operator('const')
|
||||
Controller = esphomelib_ns.class_('Controller')
|
||||
StoringController = esphomelib_ns.class_('StoringController', Controller)
|
||||
|
||||
GPIOPin = esphomelib_ns.class_('GPIOPin')
|
||||
GPIOOutputPin = esphomelib_ns.class_('GPIOOutputPin', GPIOPin)
|
||||
GPIOInputPin = esphomelib_ns.class_('GPIOInputPin', GPIOPin)
|
||||
@@ -2,41 +2,52 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import codecs
|
||||
import collections
|
||||
import hmac
|
||||
import json
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
from esphomeyaml.const import CONF_ESPHOMEYAML, CONF_BUILD_PATH
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml import const, core, __main__
|
||||
import tornado
|
||||
import tornado.concurrent
|
||||
import tornado.gen
|
||||
import tornado.ioloop
|
||||
import tornado.iostream
|
||||
from tornado.log import access_log
|
||||
import tornado.process
|
||||
import tornado.web
|
||||
import tornado.websocket
|
||||
|
||||
from esphomeyaml import const
|
||||
from esphomeyaml.__main__ import get_serial_ports
|
||||
from esphomeyaml.helpers import relative_path
|
||||
from esphomeyaml.helpers import mkdir_p, run_system_command
|
||||
from esphomeyaml.storage_json import EsphomeyamlStorageJSON, StorageJSON, \
|
||||
esphomeyaml_storage_path, ext_storage_path
|
||||
from esphomeyaml.util import shlex_quote
|
||||
|
||||
try:
|
||||
import tornado
|
||||
import tornado.gen
|
||||
import tornado.ioloop
|
||||
import tornado.iostream
|
||||
import tornado.process
|
||||
import tornado.web
|
||||
import tornado.websocket
|
||||
import tornado.concurrent
|
||||
except ImportError as err:
|
||||
tornado = None
|
||||
# pylint: disable=unused-import, wrong-import-order
|
||||
from typing import Optional # noqa
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
CONFIG_DIR = ''
|
||||
PASSWORD = ''
|
||||
PASSWORD_DIGEST = ''
|
||||
COOKIE_SECRET = None
|
||||
USING_PASSWORD = False
|
||||
ON_HASSIO = False
|
||||
USING_HASSIO_AUTH = True
|
||||
HASSIO_MQTT_CONFIG = None
|
||||
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
class BaseHandler(tornado.web.RequestHandler):
|
||||
def is_authenticated(self):
|
||||
return not PASSWORD or self.get_secure_cookie('authenticated') == 'yes'
|
||||
if USING_HASSIO_AUTH or USING_PASSWORD:
|
||||
return self.get_secure_cookie('authenticated') == 'yes'
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# pylint: disable=abstract-method, arguments-differ
|
||||
@@ -47,12 +58,13 @@ class EsphomeyamlCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||
self.closed = False
|
||||
|
||||
def on_message(self, message):
|
||||
if PASSWORD and self.get_secure_cookie('authenticated') != 'yes':
|
||||
return
|
||||
if USING_HASSIO_AUTH or USING_PASSWORD:
|
||||
if self.get_secure_cookie('authenticated') != 'yes':
|
||||
return
|
||||
if self.proc is not None:
|
||||
return
|
||||
command = self.build_command(message)
|
||||
_LOGGER.debug(u"WebSocket opened for command %s", [shlex_quote(x) for x in command])
|
||||
_LOGGER.info(u"Running command '%s'", ' '.join(shlex_quote(x) for x in command))
|
||||
self.proc = tornado.process.Subprocess(command,
|
||||
stdout=tornado.process.Subprocess.STREAM,
|
||||
stderr=subprocess.STDOUT)
|
||||
@@ -66,13 +78,11 @@ class EsphomeyamlCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||
data = yield self.proc.stdout.read_until_regex('[\n\r]')
|
||||
except tornado.iostream.StreamClosedError:
|
||||
break
|
||||
if data.endswith('\r') and random.randrange(100) < 90:
|
||||
continue
|
||||
try:
|
||||
data = data.replace('\033', '\\033')
|
||||
self.write_message({'event': 'line', 'data': data})
|
||||
except UnicodeDecodeError:
|
||||
data = data.encode('ascii', 'backslashreplace')
|
||||
self.write_message({'event': 'line', 'data': data})
|
||||
data = codecs.decode(data, 'utf8', 'replace')
|
||||
self.write_message({'event': 'line', 'data': data})
|
||||
|
||||
def proc_on_exit(self, returncode):
|
||||
if not self.closed:
|
||||
@@ -93,15 +103,14 @@ class EsphomeyamlLogsHandler(EsphomeyamlCommandWebSocket):
|
||||
def build_command(self, message):
|
||||
js = json.loads(message)
|
||||
config_file = CONFIG_DIR + '/' + js['configuration']
|
||||
return ["esphomeyaml", config_file, "logs", '--serial-port', js["port"], '--escape']
|
||||
return ["esphomeyaml", config_file, "logs", '--serial-port', js["port"]]
|
||||
|
||||
|
||||
class EsphomeyamlRunHandler(EsphomeyamlCommandWebSocket):
|
||||
def build_command(self, message):
|
||||
js = json.loads(message)
|
||||
config_file = os.path.join(CONFIG_DIR, js['configuration'])
|
||||
return ["esphomeyaml", config_file, "run", '--upload-port', js["port"],
|
||||
'--escape', '--use-esptoolpy']
|
||||
return ["esphomeyaml", config_file, "run", '--upload-port', js["port"]]
|
||||
|
||||
|
||||
class EsphomeyamlCompileHandler(EsphomeyamlCommandWebSocket):
|
||||
@@ -166,11 +175,8 @@ class WizardRequestHandler(BaseHandler):
|
||||
self.redirect('/login')
|
||||
return
|
||||
kwargs = {k: ''.join(v) for k, v in self.request.arguments.iteritems()}
|
||||
config = wizard.wizard_file(**kwargs)
|
||||
destination = os.path.join(CONFIG_DIR, kwargs['name'] + '.yaml')
|
||||
with codecs.open(destination, 'w') as f_handle:
|
||||
f_handle.write(config)
|
||||
|
||||
wizard.wizard_write(path=destination, **kwargs)
|
||||
self.redirect('/?begin=True')
|
||||
|
||||
|
||||
@@ -181,13 +187,16 @@ class DownloadBinaryRequestHandler(BaseHandler):
|
||||
return
|
||||
|
||||
configuration = self.get_argument('configuration')
|
||||
config_file = os.path.join(CONFIG_DIR, configuration)
|
||||
core.CONFIG_PATH = config_file
|
||||
config = __main__.read_config(core.CONFIG_PATH)
|
||||
build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])
|
||||
path = os.path.join(build_path, '.pioenvs', core.NAME, 'firmware.bin')
|
||||
storage_path = ext_storage_path(CONFIG_DIR, configuration)
|
||||
storage_json = StorageJSON.load(storage_path)
|
||||
if storage_json is None:
|
||||
self.send_error()
|
||||
return
|
||||
|
||||
path = storage_json.firmware_bin_path
|
||||
self.set_header('Content-Type', 'application/octet-stream')
|
||||
self.set_header("Content-Disposition", 'attachment; filename="{}.bin"'.format(core.NAME))
|
||||
filename = '{}.bin'.format(storage_json.name)
|
||||
self.set_header("Content-Disposition", 'attachment; filename="{}"'.format(filename))
|
||||
with open(path, 'rb') as f:
|
||||
while 1:
|
||||
data = f.read(16384) # or some other nice-sized chunk
|
||||
@@ -197,6 +206,83 @@ class DownloadBinaryRequestHandler(BaseHandler):
|
||||
self.finish()
|
||||
|
||||
|
||||
def _list_yaml_files():
|
||||
files = []
|
||||
for file in os.listdir(CONFIG_DIR):
|
||||
if not file.endswith('.yaml'):
|
||||
continue
|
||||
if file.startswith('.'):
|
||||
continue
|
||||
if file == 'secrets.yaml':
|
||||
continue
|
||||
files.append(file)
|
||||
files.sort()
|
||||
return files
|
||||
|
||||
|
||||
def _list_dashboard_entries():
|
||||
files = _list_yaml_files()
|
||||
return [DashboardEntry(file) for file in files]
|
||||
|
||||
|
||||
class DashboardEntry(object):
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
self._storage = None
|
||||
self._loaded_storage = False
|
||||
|
||||
@property
|
||||
def full_path(self): # type: () -> str
|
||||
return os.path.join(CONFIG_DIR, self.filename)
|
||||
|
||||
@property
|
||||
def storage(self): # type: () -> Optional[StorageJSON]
|
||||
if not self._loaded_storage:
|
||||
self._storage = StorageJSON.load(ext_storage_path(CONFIG_DIR, self.filename))
|
||||
self._loaded_storage = True
|
||||
return self._storage
|
||||
|
||||
@property
|
||||
def address(self):
|
||||
if self.storage is None:
|
||||
return None
|
||||
return self.storage.address
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if self.storage is None:
|
||||
return self.filename[:-len('.yaml')]
|
||||
return self.storage.name
|
||||
|
||||
@property
|
||||
def esp_platform(self):
|
||||
if self.storage is None:
|
||||
return None
|
||||
return self.storage.esp_platform
|
||||
|
||||
@property
|
||||
def board(self):
|
||||
if self.storage is None:
|
||||
return None
|
||||
return self.storage.board
|
||||
|
||||
@property
|
||||
def update_available(self):
|
||||
if self.storage is None:
|
||||
return True
|
||||
return self.update_old != self.update_new
|
||||
|
||||
@property
|
||||
def update_old(self):
|
||||
if self.storage is None:
|
||||
return ''
|
||||
return self.storage.esphomeyaml_version or ''
|
||||
|
||||
@property
|
||||
def update_new(self):
|
||||
return const.__version__
|
||||
|
||||
|
||||
class MainRequestHandler(BaseHandler):
|
||||
def get(self):
|
||||
if not self.is_authenticated():
|
||||
@@ -204,31 +290,194 @@ class MainRequestHandler(BaseHandler):
|
||||
return
|
||||
|
||||
begin = bool(self.get_argument('begin', False))
|
||||
files = sorted([f for f in os.listdir(CONFIG_DIR) if f.endswith('.yaml') and
|
||||
not f.startswith('.')])
|
||||
full_path_files = [os.path.join(CONFIG_DIR, f) for f in files]
|
||||
self.render("templates/index.html", files=files, full_path_files=full_path_files,
|
||||
version=const.__version__, begin=begin)
|
||||
entries = _list_dashboard_entries()
|
||||
version = const.__version__
|
||||
docs_link = 'https://beta.esphomelib.com/esphomeyaml/' if 'b' in version else \
|
||||
'https://esphomelib.com/esphomeyaml/'
|
||||
mqtt_config = get_mqtt_config_lazy()
|
||||
|
||||
self.render("templates/index.html", entries=entries,
|
||||
version=version, begin=begin, docs_link=docs_link, mqtt_config=mqtt_config)
|
||||
|
||||
|
||||
def _ping_func(filename, address):
|
||||
if os.name == 'nt':
|
||||
command = ['ping', '-n', '1', address]
|
||||
else:
|
||||
command = ['ping', '-c', '1', address]
|
||||
rc, _, _ = run_system_command(*command)
|
||||
return filename, rc == 0
|
||||
|
||||
|
||||
class PingThread(threading.Thread):
|
||||
def run(self):
|
||||
pool = multiprocessing.Pool(processes=8)
|
||||
|
||||
while not STOP_EVENT.is_set():
|
||||
# Only do pings if somebody has the dashboard open
|
||||
PING_REQUEST.wait()
|
||||
PING_REQUEST.clear()
|
||||
|
||||
def callback(ret):
|
||||
PING_RESULT[ret[0]] = ret[1]
|
||||
|
||||
entries = _list_dashboard_entries()
|
||||
queue = collections.deque()
|
||||
for entry in entries:
|
||||
if entry.address is None:
|
||||
PING_RESULT[entry.filename] = None
|
||||
continue
|
||||
|
||||
result = pool.apply_async(_ping_func, (entry.filename, entry.address),
|
||||
callback=callback)
|
||||
queue.append(result)
|
||||
|
||||
while queue:
|
||||
item = queue[0]
|
||||
if item.ready():
|
||||
queue.popleft()
|
||||
continue
|
||||
|
||||
try:
|
||||
item.get(0.1)
|
||||
except OSError:
|
||||
# ping not installed
|
||||
pass
|
||||
except multiprocessing.TimeoutError:
|
||||
pass
|
||||
|
||||
if STOP_EVENT.is_set():
|
||||
pool.terminate()
|
||||
return
|
||||
|
||||
|
||||
class PingRequestHandler(BaseHandler):
|
||||
def get(self):
|
||||
if not self.is_authenticated():
|
||||
self.redirect('/login')
|
||||
return
|
||||
|
||||
PING_REQUEST.set()
|
||||
self.write(json.dumps(PING_RESULT))
|
||||
|
||||
|
||||
def is_allowed(configuration):
|
||||
return os.path.sep not in configuration
|
||||
|
||||
|
||||
class EditRequestHandler(BaseHandler):
|
||||
def get(self):
|
||||
if not self.is_authenticated():
|
||||
self.redirect('/login')
|
||||
return
|
||||
configuration = self.get_argument('configuration')
|
||||
if not is_allowed(configuration):
|
||||
self.set_status(401)
|
||||
return
|
||||
|
||||
with open(os.path.join(CONFIG_DIR, configuration), 'r') as f:
|
||||
content = f.read()
|
||||
self.write(content)
|
||||
|
||||
def post(self):
|
||||
if not self.is_authenticated():
|
||||
self.redirect('/login')
|
||||
return
|
||||
configuration = self.get_argument('configuration')
|
||||
if not is_allowed(configuration):
|
||||
self.set_status(401)
|
||||
return
|
||||
|
||||
with open(os.path.join(CONFIG_DIR, configuration), 'w') as f:
|
||||
f.write(self.request.body)
|
||||
self.set_status(200)
|
||||
return
|
||||
|
||||
|
||||
PING_RESULT = {} # type: dict
|
||||
STOP_EVENT = threading.Event()
|
||||
PING_REQUEST = threading.Event()
|
||||
|
||||
|
||||
class LoginHandler(BaseHandler):
|
||||
def get(self):
|
||||
if USING_HASSIO_AUTH:
|
||||
self.render_hassio_login()
|
||||
return
|
||||
self.write('<html><body><form action="/login" method="post">'
|
||||
'Password: <input type="password" name="password">'
|
||||
'<input type="submit" value="Sign in">'
|
||||
'</form></body></html>')
|
||||
|
||||
def render_hassio_login(self, error=None):
|
||||
version = const.__version__
|
||||
docs_link = 'https://beta.esphomelib.com/esphomeyaml/' if 'b' in version else \
|
||||
'https://esphomelib.com/esphomeyaml/'
|
||||
|
||||
self.render("templates/login.html", version=version, docs_link=docs_link, error=error)
|
||||
|
||||
def post_hassio_login(self):
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
'X-HASSIO-KEY': os.getenv('HASSIO_TOKEN'),
|
||||
}
|
||||
data = {
|
||||
'username': str(self.get_argument('username', '')),
|
||||
'password': str(self.get_argument('password', ''))
|
||||
}
|
||||
try:
|
||||
req = requests.post('http://hassio/auth', headers=headers, data=data)
|
||||
if req.status_code == 200:
|
||||
self.set_secure_cookie("authenticated", "yes")
|
||||
self.redirect('/')
|
||||
return
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.warn("Error during Hass.io auth request: %s", err)
|
||||
self.set_status(500)
|
||||
self.render_hassio_login(error="Internal server error")
|
||||
return
|
||||
self.set_status(401)
|
||||
self.render_hassio_login(error="Invalid username or password")
|
||||
|
||||
def post(self):
|
||||
if USING_HASSIO_AUTH:
|
||||
self.post_hassio_login()
|
||||
return
|
||||
|
||||
password = str(self.get_argument("password", ''))
|
||||
password = hmac.new(password).digest()
|
||||
if hmac.compare_digest(PASSWORD, password):
|
||||
if hmac.compare_digest(PASSWORD_DIGEST, password):
|
||||
self.set_secure_cookie("authenticated", "yes")
|
||||
self.redirect("/")
|
||||
|
||||
|
||||
def make_app(debug=False):
|
||||
def log_function(handler):
|
||||
if handler.get_status() < 400:
|
||||
log_method = access_log.info
|
||||
|
||||
if isinstance(handler, SerialPortRequestHandler) and not debug:
|
||||
return
|
||||
if isinstance(handler, PingRequestHandler) and not debug:
|
||||
return
|
||||
elif handler.get_status() < 500:
|
||||
log_method = access_log.warning
|
||||
else:
|
||||
log_method = access_log.error
|
||||
|
||||
request_time = 1000.0 * handler.request.request_time()
|
||||
# pylint: disable=protected-access
|
||||
log_method("%d %s %.2fms", handler.get_status(),
|
||||
handler._request_summary(), request_time)
|
||||
|
||||
class StaticFileHandler(tornado.web.StaticFileHandler):
|
||||
def set_extra_headers(self, path):
|
||||
if debug:
|
||||
self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
|
||||
static_path = os.path.join(os.path.dirname(__file__), 'static')
|
||||
return tornado.web.Application([
|
||||
app = tornado.web.Application([
|
||||
(r"/", MainRequestHandler),
|
||||
(r"/login", LoginHandler),
|
||||
(r"/logs", EsphomeyamlLogsHandler),
|
||||
@@ -238,39 +487,83 @@ def make_app(debug=False):
|
||||
(r"/clean-mqtt", EsphomeyamlCleanMqttHandler),
|
||||
(r"/clean", EsphomeyamlCleanHandler),
|
||||
(r"/hass-config", EsphomeyamlHassConfigHandler),
|
||||
(r"/edit", EditRequestHandler),
|
||||
(r"/download.bin", DownloadBinaryRequestHandler),
|
||||
(r"/serial-ports", SerialPortRequestHandler),
|
||||
(r"/ping", PingRequestHandler),
|
||||
(r"/wizard.html", WizardRequestHandler),
|
||||
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path}),
|
||||
], debug=debug, cookie_secret=PASSWORD)
|
||||
(r'/static/(.*)', StaticFileHandler, {'path': static_path}),
|
||||
], debug=debug, cookie_secret=COOKIE_SECRET, log_function=log_function)
|
||||
return app
|
||||
|
||||
|
||||
def _get_mqtt_config_impl():
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
'X-HASSIO-KEY': os.getenv('HASSIO_TOKEN'),
|
||||
}
|
||||
|
||||
mqtt_config = requests.get('http://hassio/services/mqtt', headers=headers).json()['data']
|
||||
info = requests.get('http://hassio/host/info', headers=headers).json()['data']
|
||||
host = '{}.local'.format(info['hostname'])
|
||||
port = mqtt_config['port']
|
||||
if port != 1883:
|
||||
host = '{}:{}'.format(host, port)
|
||||
|
||||
return {
|
||||
'ssl': mqtt_config['ssl'],
|
||||
'host': host,
|
||||
'username': mqtt_config.get('username', ''),
|
||||
'password': mqtt_config.get('password', '')
|
||||
}
|
||||
|
||||
|
||||
def get_mqtt_config_lazy():
|
||||
global HASSIO_MQTT_CONFIG
|
||||
|
||||
if not ON_HASSIO:
|
||||
return None
|
||||
|
||||
if HASSIO_MQTT_CONFIG is None:
|
||||
try:
|
||||
HASSIO_MQTT_CONFIG = _get_mqtt_config_impl()
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
|
||||
return HASSIO_MQTT_CONFIG
|
||||
|
||||
|
||||
def start_web_server(args):
|
||||
global CONFIG_DIR
|
||||
global PASSWORD
|
||||
|
||||
if tornado is None:
|
||||
raise ESPHomeYAMLError("Attempted to load dashboard, but tornado is not installed! "
|
||||
"Please run \"pip2 install tornado esptool\" in your terminal.")
|
||||
global PASSWORD_DIGEST
|
||||
global USING_PASSWORD
|
||||
global ON_HASSIO
|
||||
global USING_HASSIO_AUTH
|
||||
global COOKIE_SECRET
|
||||
|
||||
CONFIG_DIR = args.configuration
|
||||
if not os.path.exists(CONFIG_DIR):
|
||||
os.makedirs(CONFIG_DIR)
|
||||
mkdir_p(CONFIG_DIR)
|
||||
mkdir_p(os.path.join(CONFIG_DIR, ".esphomeyaml"))
|
||||
|
||||
# HassIO options storage
|
||||
PASSWORD = args.password
|
||||
if os.path.isfile('/data/options.json'):
|
||||
with open('/data/options.json') as f:
|
||||
js = json.load(f)
|
||||
PASSWORD = js.get('password') or PASSWORD
|
||||
ON_HASSIO = args.hassio
|
||||
if ON_HASSIO:
|
||||
USING_HASSIO_AUTH = not bool(os.getenv('DISABLE_HA_AUTHENTICATION'))
|
||||
USING_PASSWORD = False
|
||||
else:
|
||||
USING_HASSIO_AUTH = False
|
||||
USING_PASSWORD = args.password
|
||||
|
||||
if PASSWORD:
|
||||
PASSWORD = hmac.new(str(PASSWORD)).digest()
|
||||
# Use the digest of the password as our cookie secret. This makes sure the cookie
|
||||
# isn't too short. It, of course, enables local hash brute forcing (because the cookie
|
||||
# secret can be brute forced without making requests). But the hashing algorithm used
|
||||
# by tornado is apparently strong enough to make brute forcing even a short string pretty
|
||||
# hard.
|
||||
if USING_PASSWORD:
|
||||
PASSWORD_DIGEST = hmac.new(args.password).digest()
|
||||
|
||||
if USING_HASSIO_AUTH or USING_PASSWORD:
|
||||
path = esphomeyaml_storage_path(CONFIG_DIR)
|
||||
storage = EsphomeyamlStorageJSON.load(path)
|
||||
if storage is None:
|
||||
storage = EsphomeyamlStorageJSON.get_default()
|
||||
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)
|
||||
@@ -282,7 +575,12 @@ def start_web_server(args):
|
||||
|
||||
webbrowser.open('localhost:{}'.format(args.port))
|
||||
|
||||
ping_thread = PingThread()
|
||||
ping_thread.start()
|
||||
try:
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
except KeyboardInterrupt:
|
||||
_LOGGER.info("Shutting down...")
|
||||
STOP_EVENT.set()
|
||||
PING_REQUEST.set()
|
||||
ping_thread.join()
|
||||
|
||||
17
esphomeyaml/dashboard/static/ace.js
Normal file
17
esphomeyaml/dashboard/static/ace.js
Normal file
File diff suppressed because one or more lines are too long
218
esphomeyaml/dashboard/static/esphomeyaml.css
Normal file
218
esphomeyaml/dashboard/static/esphomeyaml.css
Normal file
@@ -0,0 +1,218 @@
|
||||
nav .brand-logo {
|
||||
margin-left: 48px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
main .container {
|
||||
margin-top: -12vh;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ribbon {
|
||||
width: 100%;
|
||||
height: 17vh;
|
||||
background-color: #3F51B5;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ribbon-fab:not(.tap-target-origin) {
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
top: calc(17vh + 34px);
|
||||
}
|
||||
|
||||
i.very-large {
|
||||
font-size: 8rem;
|
||||
padding-top: 2px;
|
||||
color: #424242;
|
||||
}
|
||||
|
||||
.card .card-content {
|
||||
padding-left: 18px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.card-action a, .card-dropdown-action a {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.inlinecode {
|
||||
box-sizing: border-box;
|
||||
padding: 0.2em 0.4em;
|
||||
margin: 0;
|
||||
font-size: 85%;
|
||||
background-color: rgba(27,31,35,0.05);
|
||||
border-radius: 3px;
|
||||
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;
|
||||
}
|
||||
|
||||
.autoscroll {
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
flex-basis: auto;
|
||||
}
|
||||
|
||||
.autoscroll div {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
.log {
|
||||
background-color: #1c1c1c;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
font-size: 12px;
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
line-height: 1.45;
|
||||
border-radius: 3px;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: break-word;
|
||||
color: #DDD;
|
||||
}
|
||||
|
||||
.log-bold { font-weight: bold; }
|
||||
.log-italic { font-style: italic; }
|
||||
.log-underline { text-decoration: underline; }
|
||||
.log-strikethrough { text-decoration: line-through; }
|
||||
.log-underline.log-strikethrough { text-decoration: underline line-through; }
|
||||
.log-fg-black { color: rgb(128,128,128); }
|
||||
.log-fg-red { color: rgb(255,0,0); }
|
||||
.log-fg-green { color: rgb(0,255,0); }
|
||||
.log-fg-yellow { color: rgb(255,255,0); }
|
||||
.log-fg-blue { color: rgb(0,0,255); }
|
||||
.log-fg-magenta { color: rgb(255,0,255); }
|
||||
.log-fg-cyan { color: rgb(0,255,255); }
|
||||
.log-fg-white { color: rgb(187,187,187); }
|
||||
.log-bg-black { background-color: rgb(0,0,0); }
|
||||
.log-bg-red { background-color: rgb(255,0,0); }
|
||||
.log-bg-green { background-color: rgb(0,255,0); }
|
||||
.log-bg-yellow { background-color: rgb(255,255,0); }
|
||||
.log-bg-blue { background-color: rgb(0,0,255); }
|
||||
.log-bg-magenta { background-color: rgb(255,0,255); }
|
||||
.log-bg-cyan { background-color: rgb(0,255,255); }
|
||||
.log-bg-white { background-color: rgb(255,255,255); }
|
||||
|
||||
.modal {
|
||||
width: 95%;
|
||||
max-height: 90%;
|
||||
height: 85% !important;
|
||||
}
|
||||
|
||||
.page-footer {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1 0 auto;
|
||||
}
|
||||
|
||||
ul.browser-default {
|
||||
padding-left: 30px;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
ul.browser-default li {
|
||||
list-style-type: initial;
|
||||
}
|
||||
|
||||
ul.stepper:not(.horizontal) .step.active::before, ul.stepper:not(.horizontal) .step.done::before, ul.stepper.horizontal .step.active .step-title::before, ul.stepper.horizontal .step.done .step-title::before {
|
||||
background-color: #3f51b5 !important;
|
||||
}
|
||||
|
||||
.select-port-container {
|
||||
margin-top: 8px;
|
||||
margin-right: 24px;
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
.dropdown-trigger {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* https://github.com/tnhu/status-indicator/blob/master/styles.css */
|
||||
.status-indicator .status-indicator-icon {
|
||||
display: inline-block;
|
||||
border-radius: 50%;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
.status-indicator.unknown .status-indicator-icon {
|
||||
background-color: rgb(216, 226, 233);
|
||||
}
|
||||
|
||||
.status-indicator.unknown .status-indicator-text::after {
|
||||
content: "Unknown status";
|
||||
}
|
||||
|
||||
.status-indicator.offline .status-indicator-icon {
|
||||
background-color: rgb(255, 77, 77);
|
||||
}
|
||||
|
||||
.status-indicator.offline .status-indicator-text::after {
|
||||
content: "Offline";
|
||||
}
|
||||
|
||||
.status-indicator.not-responding .status-indicator-icon {
|
||||
background-color: rgb(255, 170, 0);
|
||||
}
|
||||
|
||||
.status-indicator.not-responding .status-indicator-text::after {
|
||||
content: "Not Responding";
|
||||
}
|
||||
|
||||
@keyframes status-indicator-pulse-online {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(75, 210, 143, .5);
|
||||
}
|
||||
25% {
|
||||
box-shadow: 0 0 0 10px rgba(75, 210, 143, 0);
|
||||
}
|
||||
30% {
|
||||
box-shadow: 0 0 0 0 rgba(75, 210, 143, 0);
|
||||
}
|
||||
}
|
||||
|
||||
.status-indicator.online .status-indicator-icon {
|
||||
background-color: rgb(75, 210, 143);
|
||||
animation-duration: 5s;
|
||||
animation-timing-function: ease-in-out;
|
||||
animation-iteration-count: infinite;
|
||||
animation-direction: normal;
|
||||
animation-delay: 0s;
|
||||
animation-fill-mode: none;
|
||||
animation-name: status-indicator-pulse-online;
|
||||
}
|
||||
|
||||
.status-indicator.online .status-indicator-text::after {
|
||||
content: "Online";
|
||||
}
|
||||
|
||||
#editor {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
padding: 16px;
|
||||
border-radius: 3px;
|
||||
height: 100%
|
||||
}
|
||||
|
||||
.update-available i {
|
||||
vertical-align: bottom;
|
||||
font-size: 20px !important;
|
||||
color: #3F51B5 !important;
|
||||
margin-right: -4.5px;
|
||||
margin-left: -5.5px;
|
||||
}
|
||||
|
||||
.flash-using-esphomeflasher {
|
||||
vertical-align: middle;
|
||||
color: #666 !important;
|
||||
}
|
||||
683
esphomeyaml/dashboard/static/esphomeyaml.js
Normal file
683
esphomeyaml/dashboard/static/esphomeyaml.js
Normal file
@@ -0,0 +1,683 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
M.AutoInit(document.body);
|
||||
});
|
||||
|
||||
const initializeColorState = () => {
|
||||
return {
|
||||
bold: false,
|
||||
italic: false,
|
||||
underline: false,
|
||||
strikethrough: false,
|
||||
foregroundColor: false,
|
||||
backgroundColor: false,
|
||||
carriageReturn: false,
|
||||
};
|
||||
};
|
||||
|
||||
const colorReplace = (pre, state, text) => {
|
||||
const re = /\033(?:\[(.*?)[@-~]|\].*?(?:\007|\033\\))/g;
|
||||
let i = 0;
|
||||
|
||||
if (state.carriageReturn) {
|
||||
if (text !== "\n") {
|
||||
// don't remove if \r\n
|
||||
pre.removeChild(pre.lastChild);
|
||||
}
|
||||
state.carriageReturn = false;
|
||||
}
|
||||
|
||||
if (text.includes("\r")) {
|
||||
state.carriageReturn = true;
|
||||
}
|
||||
|
||||
const lineSpan = document.createElement("span");
|
||||
lineSpan.classList.add("line");
|
||||
pre.appendChild(lineSpan);
|
||||
|
||||
const addSpan = (content) => {
|
||||
if (content === "")
|
||||
return;
|
||||
|
||||
const span = document.createElement("span");
|
||||
if (state.bold) span.classList.add("log-bold");
|
||||
if (state.italic) span.classList.add("log-italic");
|
||||
if (state.underline) span.classList.add("log-underline");
|
||||
if (state.strikethrough) span.classList.add("log-strikethrough");
|
||||
if (state.foregroundColor !== null) span.classList.add(`log-fg-${state.foregroundColor}`);
|
||||
if (state.backgroundColor !== null) span.classList.add(`log-bg-${state.backgroundColor}`);
|
||||
span.appendChild(document.createTextNode(content));
|
||||
lineSpan.appendChild(span);
|
||||
};
|
||||
|
||||
|
||||
while (true) {
|
||||
const match = re.exec(text);
|
||||
if (match === null)
|
||||
break;
|
||||
|
||||
const j = match.index;
|
||||
addSpan(text.substring(i, j));
|
||||
i = j + match[0].length;
|
||||
|
||||
if (match[1] === undefined) continue;
|
||||
|
||||
for (const colorCode of match[1].split(";")) {
|
||||
switch (parseInt(colorCode)) {
|
||||
case 0:
|
||||
// reset
|
||||
state.bold = false;
|
||||
state.italic = false;
|
||||
state.underline = false;
|
||||
state.strikethrough = false;
|
||||
state.foregroundColor = null;
|
||||
state.backgroundColor = null;
|
||||
break;
|
||||
case 1:
|
||||
state.bold = true;
|
||||
break;
|
||||
case 3:
|
||||
state.italic = true;
|
||||
break;
|
||||
case 4:
|
||||
state.underline = true;
|
||||
break;
|
||||
case 9:
|
||||
state.strikethrough = true;
|
||||
break;
|
||||
case 22:
|
||||
state.bold = false;
|
||||
break;
|
||||
case 23:
|
||||
state.italic = false;
|
||||
break;
|
||||
case 24:
|
||||
state.underline = false;
|
||||
break;
|
||||
case 29:
|
||||
state.strikethrough = false;
|
||||
break;
|
||||
case 30:
|
||||
state.foregroundColor = "black";
|
||||
break;
|
||||
case 31:
|
||||
state.foregroundColor = "red";
|
||||
break;
|
||||
case 32:
|
||||
state.foregroundColor = "green";
|
||||
break;
|
||||
case 33:
|
||||
state.foregroundColor = "yellow";
|
||||
break;
|
||||
case 34:
|
||||
state.foregroundColor = "blue";
|
||||
break;
|
||||
case 35:
|
||||
state.foregroundColor = "magenta";
|
||||
break;
|
||||
case 36:
|
||||
state.foregroundColor = "cyan";
|
||||
break;
|
||||
case 37:
|
||||
state.foregroundColor = "white";
|
||||
break;
|
||||
case 39:
|
||||
state.foregroundColor = null;
|
||||
break;
|
||||
case 41:
|
||||
state.backgroundColor = "red";
|
||||
break;
|
||||
case 42:
|
||||
state.backgroundColor = "green";
|
||||
break;
|
||||
case 43:
|
||||
state.backgroundColor = "yellow";
|
||||
break;
|
||||
case 44:
|
||||
state.backgroundColor = "blue";
|
||||
break;
|
||||
case 45:
|
||||
state.backgroundColor = "magenta";
|
||||
break;
|
||||
case 46:
|
||||
state.backgroundColor = "cyan";
|
||||
break;
|
||||
case 47:
|
||||
state.backgroundColor = "white";
|
||||
break;
|
||||
case 40:
|
||||
case 49:
|
||||
state.backgroundColor = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
addSpan(text.substring(i));
|
||||
};
|
||||
|
||||
const removeUpdateAvailable = (filename) => {
|
||||
const p = document.querySelector(`.update-available[data-node="${filename}"]`);
|
||||
if (p === undefined)
|
||||
return;
|
||||
p.remove();
|
||||
};
|
||||
|
||||
let configuration = "";
|
||||
let wsProtocol = "ws:";
|
||||
if (window.location.protocol === "https:") {
|
||||
wsProtocol = 'wss:';
|
||||
}
|
||||
const wsUrl = wsProtocol + '//' + window.location.hostname + ':' + window.location.port;
|
||||
|
||||
let isFetchingPing = false;
|
||||
const fetchPing = () => {
|
||||
if (isFetchingPing)
|
||||
return;
|
||||
isFetchingPing = true;
|
||||
|
||||
fetch('/ping', {credentials: "same-origin"}).then(res => res.json())
|
||||
.then(response => {
|
||||
for (let filename in response) {
|
||||
let node = document.querySelector(`.status-indicator[data-node="${filename}"]`);
|
||||
if (node === null)
|
||||
continue;
|
||||
|
||||
let status = response[filename];
|
||||
let klass;
|
||||
if (status === null) {
|
||||
klass = 'unknown';
|
||||
} else if (status === true) {
|
||||
klass = 'online';
|
||||
node.setAttribute('data-last-connected', Date.now().toString());
|
||||
} else if (node.hasAttribute('data-last-connected')) {
|
||||
const attr = parseInt(node.getAttribute('data-last-connected'));
|
||||
if (Date.now() - attr <= 5000) {
|
||||
klass = 'not-responding';
|
||||
} else {
|
||||
klass = 'offline';
|
||||
}
|
||||
} else {
|
||||
klass = 'offline';
|
||||
}
|
||||
|
||||
if (node.classList.contains(klass))
|
||||
continue;
|
||||
|
||||
node.classList.remove('unknown', 'online', 'offline', 'not-responding');
|
||||
node.classList.add(klass);
|
||||
}
|
||||
|
||||
isFetchingPing = false;
|
||||
});
|
||||
};
|
||||
setInterval(fetchPing, 2000);
|
||||
fetchPing();
|
||||
|
||||
const portSelect = document.querySelector('.nav-wrapper select');
|
||||
let ports = [];
|
||||
|
||||
const fetchSerialPorts = (begin=false) => {
|
||||
fetch('/serial-ports', {credentials: "same-origin"}).then(res => res.json())
|
||||
.then(response => {
|
||||
if (ports.length === response.length) {
|
||||
let allEqual = true;
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
if (ports[i].port !== response[i].port) {
|
||||
allEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allEqual)
|
||||
return;
|
||||
}
|
||||
const hasNewPort = response.length >= ports.length;
|
||||
|
||||
ports = response;
|
||||
|
||||
const inst = M.FormSelect.getInstance(portSelect);
|
||||
if (inst !== undefined) {
|
||||
inst.destroy();
|
||||
}
|
||||
|
||||
portSelect.innerHTML = "";
|
||||
const prevSelected = getUploadPort();
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
const val = response[i];
|
||||
if (val.port === prevSelected) {
|
||||
portSelect.innerHTML += `<option value="${val.port}" selected>${val.port} (${val.desc})</option>`;
|
||||
} else {
|
||||
portSelect.innerHTML += `<option value="${val.port}">${val.port} (${val.desc})</option>`;
|
||||
}
|
||||
}
|
||||
|
||||
M.FormSelect.init(portSelect, {});
|
||||
if (!begin && hasNewPort)
|
||||
M.toast({html: "Discovered new serial port."});
|
||||
});
|
||||
};
|
||||
|
||||
const getUploadPort = () => {
|
||||
const inst = M.FormSelect.getInstance(portSelect);
|
||||
if (inst === undefined) {
|
||||
return "OTA";
|
||||
}
|
||||
|
||||
inst._setSelectedStates();
|
||||
return inst.getSelectedValues()[0];
|
||||
};
|
||||
setInterval(fetchSerialPorts, 5000);
|
||||
fetchSerialPorts(true);
|
||||
|
||||
const logsModalElem = document.getElementById("modal-logs");
|
||||
|
||||
document.querySelectorAll(".action-show-logs").forEach((showLogs) => {
|
||||
showLogs.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(logsModalElem);
|
||||
const log = logsModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = logsModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = logsModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/logs");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration, port: getUploadPort()});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const uploadModalElem = document.getElementById("modal-upload");
|
||||
|
||||
document.querySelectorAll(".action-upload").forEach((upload) => {
|
||||
upload.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(uploadModalElem);
|
||||
const log = uploadModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = uploadModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = uploadModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/run");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
removeUpdateAvailable(configuration);
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration, port: getUploadPort()});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const validateModalElem = document.getElementById("modal-validate");
|
||||
|
||||
document.querySelectorAll(".action-validate").forEach((upload) => {
|
||||
upload.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(validateModalElem);
|
||||
const log = validateModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = validateModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = validateModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/validate");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({
|
||||
html: `<code class="inlinecode">${configuration}</code> is valid 👍`,
|
||||
displayLength: 5000,
|
||||
});
|
||||
} else {
|
||||
M.toast({
|
||||
html: `<code class="inlinecode">${configuration}</code> is invalid 😕`,
|
||||
displayLength: 5000,
|
||||
});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const compileModalElem = document.getElementById("modal-compile");
|
||||
const downloadButton = compileModalElem.querySelector('.download-binary');
|
||||
|
||||
document.querySelectorAll(".action-compile").forEach((upload) => {
|
||||
upload.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(compileModalElem);
|
||||
const log = compileModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = compileModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
downloadButton.classList.add('disabled');
|
||||
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = compileModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/compile");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
downloadButton.classList.remove('disabled');
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
downloadButton.addEventListener('click', () => {
|
||||
const link = document.createElement("a");
|
||||
link.download = name;
|
||||
link.href = '/download.bin?configuration=' + encodeURIComponent(configuration);
|
||||
link.click();
|
||||
});
|
||||
|
||||
const cleanMqttModalElem = document.getElementById("modal-clean-mqtt");
|
||||
|
||||
document.querySelectorAll(".action-clean-mqtt").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(cleanMqttModalElem);
|
||||
const log = cleanMqttModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = cleanMqttModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = cleanMqttModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/clean-mqtt");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const cleanModalElem = document.getElementById("modal-clean");
|
||||
|
||||
document.querySelectorAll(".action-clean").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(cleanModalElem);
|
||||
const log = cleanModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = cleanModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = cleanModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/clean");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
downloadButton.classList.remove('disabled');
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const hassConfigModalElem = document.getElementById("modal-hass-config");
|
||||
|
||||
document.querySelectorAll(".action-hass-config").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(hassConfigModalElem);
|
||||
const log = hassConfigModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const colorState = initializeColorState();
|
||||
const stopLogsButton = hassConfigModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = hassConfigModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/hass-config");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
colorReplace(log, colorState, data.data);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
downloadButton.classList.remove('disabled');
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const editModalElem = document.getElementById("modal-editor");
|
||||
const editorElem = editModalElem.querySelector("#editor");
|
||||
const editor = ace.edit(editorElem);
|
||||
editor.setTheme("ace/theme/dreamweaver");
|
||||
editor.session.setMode("ace/mode/yaml");
|
||||
editor.session.setOption('useSoftTabs', true);
|
||||
editor.session.setOption('tabSize', 2);
|
||||
|
||||
const saveButton = editModalElem.querySelector(".save-button");
|
||||
const saveEditor = () => {
|
||||
fetch(`/edit?configuration=${configuration}`, {
|
||||
credentials: "same-origin",
|
||||
method: "POST",
|
||||
body: editor.getValue()
|
||||
}).then(res => res.text()).then(() => {
|
||||
M.toast({
|
||||
html: `Saved <code class="inlinecode">${configuration}</code>`
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
editor.commands.addCommand({
|
||||
name: 'saveCommand',
|
||||
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
|
||||
exec: saveEditor,
|
||||
readOnly: false
|
||||
});
|
||||
|
||||
saveButton.addEventListener('click', saveEditor);
|
||||
|
||||
document.querySelectorAll(".action-edit").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(editModalElem);
|
||||
const filenameField = editModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
fetch(`/edit?configuration=${configuration}`, {credentials: "same-origin"})
|
||||
.then(res => res.text()).then(response => {
|
||||
editor.setValue(response, -1);
|
||||
});
|
||||
|
||||
modalInstance.open();
|
||||
});
|
||||
});
|
||||
|
||||
const modalSetupElem = document.getElementById("modal-wizard");
|
||||
const setupWizardStart = document.getElementById('setup-wizard-start');
|
||||
const startWizard = () => {
|
||||
const modalInstance = M.Modal.getInstance(modalSetupElem);
|
||||
modalInstance.open();
|
||||
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
|
||||
};
|
||||
|
||||
$('.stepper').activateStepper({
|
||||
linearStepsNavigation: false,
|
||||
autoFocusInput: true,
|
||||
autoFormCreation: true,
|
||||
showFeedbackLoader: true,
|
||||
parallel: false
|
||||
});
|
||||
};
|
||||
|
||||
setupWizardStart.addEventListener('click', startWizard);
|
||||
BIN
esphomeyaml/dashboard/static/favicon.ico
Normal file
BIN
esphomeyaml/dashboard/static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
401
esphomeyaml/dashboard/static/jquery-ui.min.js
vendored
Normal file
401
esphomeyaml/dashboard/static/jquery-ui.min.js
vendored
Normal file
@@ -0,0 +1,401 @@
|
||||
/*!
|
||||
* jQuery UI 1.8.5
|
||||
*
|
||||
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://docs.jquery.com/UI
|
||||
*/
|
||||
(function(c,j){function k(a){return!c(a).parents().andSelf().filter(function(){return c.curCSS(this,"visibility")==="hidden"||c.expr.filters.hidden(this)}).length}c.ui=c.ui||{};if(!c.ui.version){c.extend(c.ui,{version:"1.8.5",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,
|
||||
NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});c.fn.extend({_focus:c.fn.focus,focus:function(a,b){return typeof a==="number"?this.each(function(){var d=this;setTimeout(function(){c(d).focus();b&&b.call(d)},a)}):this._focus.apply(this,arguments)},scrollParent:function(){var a;a=c.browser.msie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(c.curCSS(this,
|
||||
"position",1))&&/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0);return/fixed/.test(this.css("position"))||!a.length?c(document):a},zIndex:function(a){if(a!==j)return this.css("zIndex",a);if(this.length){a=c(this[0]);for(var b;a.length&&a[0]!==document;){b=a.css("position");
|
||||
if(b==="absolute"||b==="relative"||b==="fixed"){b=parseInt(a.css("zIndex"));if(!isNaN(b)&&b!=0)return b}a=a.parent()}}return 0},disableSelection:function(){return this.bind("mousedown.ui-disableSelection selectstart.ui-disableSelection",function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});c.each(["Width","Height"],function(a,b){function d(f,g,l,m){c.each(e,function(){g-=parseFloat(c.curCSS(f,"padding"+this,true))||0;if(l)g-=parseFloat(c.curCSS(f,
|
||||
"border"+this+"Width",true))||0;if(m)g-=parseFloat(c.curCSS(f,"margin"+this,true))||0});return g}var e=b==="Width"?["Left","Right"]:["Top","Bottom"],h=b.toLowerCase(),i={innerWidth:c.fn.innerWidth,innerHeight:c.fn.innerHeight,outerWidth:c.fn.outerWidth,outerHeight:c.fn.outerHeight};c.fn["inner"+b]=function(f){if(f===j)return i["inner"+b].call(this);return this.each(function(){c.style(this,h,d(this,f)+"px")})};c.fn["outer"+b]=function(f,g){if(typeof f!=="number")return i["outer"+b].call(this,f);return this.each(function(){c.style(this,
|
||||
h,d(this,f,true,g)+"px")})}});c.extend(c.expr[":"],{data:function(a,b,d){return!!c.data(a,d[3])},focusable:function(a){var b=a.nodeName.toLowerCase(),d=c.attr(a,"tabindex");if("area"===b){b=a.parentNode;d=b.name;if(!a.href||!d||b.nodeName.toLowerCase()!=="map")return false;a=c("img[usemap=#"+d+"]")[0];return!!a&&k(a)}return(/input|select|textarea|button|object/.test(b)?!a.disabled:"a"==b?a.href||!isNaN(d):!isNaN(d))&&k(a)},tabbable:function(a){var b=c.attr(a,"tabindex");return(isNaN(b)||b>=0)&&c(a).is(":focusable")}});
|
||||
c(function(){var a=document.createElement("div"),b=document.body;c.extend(a.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});c.support.minHeight=b.appendChild(a).offsetHeight===100;b.removeChild(a).style.display="none"});c.extend(c.ui,{plugin:{add:function(a,b,d){a=c.ui[a].prototype;for(var e in d){a.plugins[e]=a.plugins[e]||[];a.plugins[e].push([b,d[e]])}},call:function(a,b,d){if((b=a.plugins[b])&&a.element[0].parentNode)for(var e=0;e<b.length;e++)a.options[b[e][0]]&&b[e][1].apply(a.element,
|
||||
d)}},contains:function(a,b){return document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(a,b){if(c(a).css("overflow")==="hidden")return false;b=b&&b==="left"?"scrollLeft":"scrollTop";var d=false;if(a[b]>0)return true;a[b]=1;d=a[b]>0;a[b]=0;return d},isOverAxis:function(a,b,d){return a>b&&a<b+d},isOver:function(a,b,d,e,h,i){return c.ui.isOverAxis(a,d,h)&&c.ui.isOverAxis(b,e,i)}})}})(jQuery);
|
||||
(function(b,j){if(b.cleanData){var k=b.cleanData;b.cleanData=function(a){for(var c=0,d;(d=a[c])!=null;c++)b(d).triggerHandler("remove");k(a)}}else{var l=b.fn.remove;b.fn.remove=function(a,c){return this.each(function(){if(!c)if(!a||b.filter(a,[this]).length)b("*",this).add([this]).each(function(){b(this).triggerHandler("remove")});return l.call(b(this),a,c)})}}b.widget=function(a,c,d){var e=a.split(".")[0],f;a=a.split(".")[1];f=e+"-"+a;if(!d){d=c;c=b.Widget}b.expr[":"][f]=function(h){return!!b.data(h,
|
||||
a)};b[e]=b[e]||{};b[e][a]=function(h,g){arguments.length&&this._createWidget(h,g)};c=new c;c.options=b.extend(true,{},c.options);b[e][a].prototype=b.extend(true,c,{namespace:e,widgetName:a,widgetEventPrefix:b[e][a].prototype.widgetEventPrefix||a,widgetBaseClass:f},d);b.widget.bridge(a,b[e][a])};b.widget.bridge=function(a,c){b.fn[a]=function(d){var e=typeof d==="string",f=Array.prototype.slice.call(arguments,1),h=this;d=!e&&f.length?b.extend.apply(null,[true,d].concat(f)):d;if(e&&d.substring(0,1)===
|
||||
"_")return h;e?this.each(function(){var g=b.data(this,a);if(!g)throw"cannot call methods on "+a+" prior to initialization; attempted to call method '"+d+"'";if(!b.isFunction(g[d]))throw"no such method '"+d+"' for "+a+" widget instance";var i=g[d].apply(g,f);if(i!==g&&i!==j){h=i;return false}}):this.each(function(){var g=b.data(this,a);g?g.option(d||{})._init():b.data(this,a,new c(d,this))});return h}};b.Widget=function(a,c){arguments.length&&this._createWidget(a,c)};b.Widget.prototype={widgetName:"widget",
|
||||
widgetEventPrefix:"",options:{disabled:false},_createWidget:function(a,c){b.data(c,this.widgetName,this);this.element=b(c);this.options=b.extend(true,{},this.options,b.metadata&&b.metadata.get(c)[this.widgetName],a);var d=this;this.element.bind("remove."+this.widgetName,function(){d.destroy()});this._create();this._init()},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+
|
||||
"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(a,c){var d=a,e=this;if(arguments.length===0)return b.extend({},e.options);if(typeof a==="string"){if(c===j)return this.options[a];d={};d[a]=c}b.each(d,function(f,h){e._setOption(f,h)});return e},_setOption:function(a,c){this.options[a]=c;if(a==="disabled")this.widget()[c?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",c);return this},enable:function(){return this._setOption("disabled",
|
||||
false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(a,c,d){var e=this.options[a];c=b.Event(c);c.type=(a===this.widgetEventPrefix?a:this.widgetEventPrefix+a).toLowerCase();d=d||{};if(c.originalEvent){a=b.event.props.length;for(var f;a;){f=b.event.props[--a];c[f]=c.originalEvent[f]}}this.element.trigger(c,d);return!(b.isFunction(e)&&e.call(this.element[0],c,d)===false||c.isDefaultPrevented())}}})(jQuery);
|
||||
(function(c){c.widget("ui.mouse",{options:{cancel:":input,option",distance:1,delay:0},_mouseInit:function(){var a=this;this.element.bind("mousedown."+this.widgetName,function(b){return a._mouseDown(b)}).bind("click."+this.widgetName,function(b){if(a._preventClickEvent){a._preventClickEvent=false;b.stopImmediatePropagation();return false}});this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName)},_mouseDown:function(a){a.originalEvent=a.originalEvent||{};if(!a.originalEvent.mouseHandled){this._mouseStarted&&
|
||||
this._mouseUp(a);this._mouseDownEvent=a;var b=this,e=a.which==1,f=typeof this.options.cancel=="string"?c(a.target).parents().add(a.target).filter(this.options.cancel).length:false;if(!e||f||!this._mouseCapture(a))return true;this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet)this._mouseDelayTimer=setTimeout(function(){b.mouseDelayMet=true},this.options.delay);if(this._mouseDistanceMet(a)&&this._mouseDelayMet(a)){this._mouseStarted=this._mouseStart(a)!==false;if(!this._mouseStarted){a.preventDefault();
|
||||
return true}}this._mouseMoveDelegate=function(d){return b._mouseMove(d)};this._mouseUpDelegate=function(d){return b._mouseUp(d)};c(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);c.browser.safari||a.preventDefault();return a.originalEvent.mouseHandled=true}},_mouseMove:function(a){if(c.browser.msie&&!a.button)return this._mouseUp(a);if(this._mouseStarted){this._mouseDrag(a);return a.preventDefault()}if(this._mouseDistanceMet(a)&&
|
||||
this._mouseDelayMet(a))(this._mouseStarted=this._mouseStart(this._mouseDownEvent,a)!==false)?this._mouseDrag(a):this._mouseUp(a);return!this._mouseStarted},_mouseUp:function(a){c(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;this._preventClickEvent=a.target==this._mouseDownEvent.target;this._mouseStop(a)}return false},_mouseDistanceMet:function(a){return Math.max(Math.abs(this._mouseDownEvent.pageX-
|
||||
a.pageX),Math.abs(this._mouseDownEvent.pageY-a.pageY))>=this.options.distance},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return true}})})(jQuery);
|
||||
(function(d){d.widget("ui.draggable",d.ui.mouse,{widgetEventPrefix:"drag",options:{addClasses:true,appendTo:"parent",axis:false,connectToSortable:false,containment:false,cursor:"auto",cursorAt:false,grid:false,handle:false,helper:"original",iframeFix:false,opacity:false,refreshPositions:false,revert:false,revertDuration:500,scope:"default",scroll:true,scrollSensitivity:20,scrollSpeed:20,snap:false,snapMode:"both",snapTolerance:20,stack:false,zIndex:false},_create:function(){if(this.options.helper==
|
||||
"original"&&!/^(?:r|a|f)/.test(this.element.css("position")))this.element[0].style.position="relative";this.options.addClasses&&this.element.addClass("ui-draggable");this.options.disabled&&this.element.addClass("ui-draggable-disabled");this._mouseInit()},destroy:function(){if(this.element.data("draggable")){this.element.removeData("draggable").unbind(".draggable").removeClass("ui-draggable ui-draggable-dragging ui-draggable-disabled");this._mouseDestroy();return this}},_mouseCapture:function(a){var b=
|
||||
this.options;if(this.helper||b.disabled||d(a.target).is(".ui-resizable-handle"))return false;this.handle=this._getHandle(a);if(!this.handle)return false;return true},_mouseStart:function(a){var b=this.options;this.helper=this._createHelper(a);this._cacheHelperProportions();if(d.ui.ddmanager)d.ui.ddmanager.current=this;this._cacheMargins();this.cssPosition=this.helper.css("position");this.scrollParent=this.helper.scrollParent();this.offset=this.positionAbs=this.element.offset();this.offset={top:this.offset.top-
|
||||
this.margins.top,left:this.offset.left-this.margins.left};d.extend(this.offset,{click:{left:a.pageX-this.offset.left,top:a.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.originalPosition=this.position=this._generatePosition(a);this.originalPageX=a.pageX;this.originalPageY=a.pageY;b.cursorAt&&this._adjustOffsetFromHelper(b.cursorAt);b.containment&&this._setContainment();if(this._trigger("start",a)===false){this._clear();return false}this._cacheHelperProportions();
|
||||
d.ui.ddmanager&&!b.dropBehaviour&&d.ui.ddmanager.prepareOffsets(this,a);this.helper.addClass("ui-draggable-dragging");this._mouseDrag(a,true);return true},_mouseDrag:function(a,b){this.position=this._generatePosition(a);this.positionAbs=this._convertPositionTo("absolute");if(!b){b=this._uiHash();if(this._trigger("drag",a,b)===false){this._mouseUp({});return false}this.position=b.position}if(!this.options.axis||this.options.axis!="y")this.helper[0].style.left=this.position.left+"px";if(!this.options.axis||
|
||||
this.options.axis!="x")this.helper[0].style.top=this.position.top+"px";d.ui.ddmanager&&d.ui.ddmanager.drag(this,a);return false},_mouseStop:function(a){var b=false;if(d.ui.ddmanager&&!this.options.dropBehaviour)b=d.ui.ddmanager.drop(this,a);if(this.dropped){b=this.dropped;this.dropped=false}if(!this.element[0]||!this.element[0].parentNode)return false;if(this.options.revert=="invalid"&&!b||this.options.revert=="valid"&&b||this.options.revert===true||d.isFunction(this.options.revert)&&this.options.revert.call(this.element,
|
||||
b)){var c=this;d(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){c._trigger("stop",a)!==false&&c._clear()})}else this._trigger("stop",a)!==false&&this._clear();return false},cancel:function(){this.helper.is(".ui-draggable-dragging")?this._mouseUp({}):this._clear();return this},_getHandle:function(a){var b=!this.options.handle||!d(this.options.handle,this.element).length?true:false;d(this.options.handle,this.element).find("*").andSelf().each(function(){if(this==
|
||||
a.target)b=true});return b},_createHelper:function(a){var b=this.options;a=d.isFunction(b.helper)?d(b.helper.apply(this.element[0],[a])):b.helper=="clone"?this.element.clone():this.element;a.parents("body").length||a.appendTo(b.appendTo=="parent"?this.element[0].parentNode:b.appendTo);a[0]!=this.element[0]&&!/(fixed|absolute)/.test(a.css("position"))&&a.css("position","absolute");return a},_adjustOffsetFromHelper:function(a){if(typeof a=="string")a=a.split(" ");if(d.isArray(a))a={left:+a[0],top:+a[1]||
|
||||
0};if("left"in a)this.offset.click.left=a.left+this.margins.left;if("right"in a)this.offset.click.left=this.helperProportions.width-a.right+this.margins.left;if("top"in a)this.offset.click.top=a.top+this.margins.top;if("bottom"in a)this.offset.click.top=this.helperProportions.height-a.bottom+this.margins.top},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var a=this.offsetParent.offset();if(this.cssPosition=="absolute"&&this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],
|
||||
this.offsetParent[0])){a.left+=this.scrollParent.scrollLeft();a.top+=this.scrollParent.scrollTop()}if(this.offsetParent[0]==document.body||this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()=="html"&&d.browser.msie)a={top:0,left:0};return{top:a.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:a.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition=="relative"){var a=this.element.position();return{top:a.top-
|
||||
(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:a.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}else return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.element.css("marginLeft"),10)||0,top:parseInt(this.element.css("marginTop"),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var a=this.options;if(a.containment==
|
||||
"parent")a.containment=this.helper[0].parentNode;if(a.containment=="document"||a.containment=="window")this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,d(a.containment=="document"?document:window).width()-this.helperProportions.width-this.margins.left,(d(a.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];if(!/^(document|window|parent)$/.test(a.containment)&&
|
||||
a.containment.constructor!=Array){var b=d(a.containment)[0];if(b){a=d(a.containment).offset();var c=d(b).css("overflow")!="hidden";this.containment=[a.left+(parseInt(d(b).css("borderLeftWidth"),10)||0)+(parseInt(d(b).css("paddingLeft"),10)||0)-this.margins.left,a.top+(parseInt(d(b).css("borderTopWidth"),10)||0)+(parseInt(d(b).css("paddingTop"),10)||0)-this.margins.top,a.left+(c?Math.max(b.scrollWidth,b.offsetWidth):b.offsetWidth)-(parseInt(d(b).css("borderLeftWidth"),10)||0)-(parseInt(d(b).css("paddingRight"),
|
||||
10)||0)-this.helperProportions.width-this.margins.left,a.top+(c?Math.max(b.scrollHeight,b.offsetHeight):b.offsetHeight)-(parseInt(d(b).css("borderTopWidth"),10)||0)-(parseInt(d(b).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}}else if(a.containment.constructor==Array)this.containment=a.containment},_convertPositionTo:function(a,b){if(!b)b=this.position;a=a=="absolute"?1:-1;var c=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],
|
||||
this.offsetParent[0]))?this.offsetParent:this.scrollParent,f=/(html|body)/i.test(c[0].tagName);return{top:b.top+this.offset.relative.top*a+this.offset.parent.top*a-(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollTop():f?0:c.scrollTop())*a),left:b.left+this.offset.relative.left*a+this.offset.parent.left*a-(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():
|
||||
f?0:c.scrollLeft())*a)}},_generatePosition:function(a){var b=this.options,c=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,f=/(html|body)/i.test(c[0].tagName),e=a.pageX,g=a.pageY;if(this.originalPosition){if(this.containment){if(a.pageX-this.offset.click.left<this.containment[0])e=this.containment[0]+this.offset.click.left;if(a.pageY-this.offset.click.top<this.containment[1])g=this.containment[1]+
|
||||
this.offset.click.top;if(a.pageX-this.offset.click.left>this.containment[2])e=this.containment[2]+this.offset.click.left;if(a.pageY-this.offset.click.top>this.containment[3])g=this.containment[3]+this.offset.click.top}if(b.grid){g=this.originalPageY+Math.round((g-this.originalPageY)/b.grid[1])*b.grid[1];g=this.containment?!(g-this.offset.click.top<this.containment[1]||g-this.offset.click.top>this.containment[3])?g:!(g-this.offset.click.top<this.containment[1])?g-b.grid[1]:g+b.grid[1]:g;e=this.originalPageX+
|
||||
Math.round((e-this.originalPageX)/b.grid[0])*b.grid[0];e=this.containment?!(e-this.offset.click.left<this.containment[0]||e-this.offset.click.left>this.containment[2])?e:!(e-this.offset.click.left<this.containment[0])?e-b.grid[0]:e+b.grid[0]:e}}return{top:g-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:this.cssPosition=="fixed"?-this.scrollParent.scrollTop():f?0:c.scrollTop()),left:e-this.offset.click.left-
|
||||
this.offset.relative.left-this.offset.parent.left+(d.browser.safari&&d.browser.version<526&&this.cssPosition=="fixed"?0:this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():f?0:c.scrollLeft())}},_clear:function(){this.helper.removeClass("ui-draggable-dragging");this.helper[0]!=this.element[0]&&!this.cancelHelperRemoval&&this.helper.remove();this.helper=null;this.cancelHelperRemoval=false},_trigger:function(a,b,c){c=c||this._uiHash();d.ui.plugin.call(this,a,[b,c]);if(a=="drag")this.positionAbs=
|
||||
this._convertPositionTo("absolute");return d.Widget.prototype._trigger.call(this,a,b,c)},plugins:{},_uiHash:function(){return{helper:this.helper,position:this.position,originalPosition:this.originalPosition,offset:this.positionAbs}}});d.extend(d.ui.draggable,{version:"1.8.5"});d.ui.plugin.add("draggable","connectToSortable",{start:function(a,b){var c=d(this).data("draggable"),f=c.options,e=d.extend({},b,{item:c.element});c.sortables=[];d(f.connectToSortable).each(function(){var g=d.data(this,"sortable");
|
||||
if(g&&!g.options.disabled){c.sortables.push({instance:g,shouldRevert:g.options.revert});g._refreshItems();g._trigger("activate",a,e)}})},stop:function(a,b){var c=d(this).data("draggable"),f=d.extend({},b,{item:c.element});d.each(c.sortables,function(){if(this.instance.isOver){this.instance.isOver=0;c.cancelHelperRemoval=true;this.instance.cancelHelperRemoval=false;if(this.shouldRevert)this.instance.options.revert=true;this.instance._mouseStop(a);this.instance.options.helper=this.instance.options._helper;
|
||||
c.options.helper=="original"&&this.instance.currentItem.css({top:"auto",left:"auto"})}else{this.instance.cancelHelperRemoval=false;this.instance._trigger("deactivate",a,f)}})},drag:function(a,b){var c=d(this).data("draggable"),f=this;d.each(c.sortables,function(){this.instance.positionAbs=c.positionAbs;this.instance.helperProportions=c.helperProportions;this.instance.offset.click=c.offset.click;if(this.instance._intersectsWith(this.instance.containerCache)){if(!this.instance.isOver){this.instance.isOver=
|
||||
1;this.instance.currentItem=d(f).clone().appendTo(this.instance.element).data("sortable-item",true);this.instance.options._helper=this.instance.options.helper;this.instance.options.helper=function(){return b.helper[0]};a.target=this.instance.currentItem[0];this.instance._mouseCapture(a,true);this.instance._mouseStart(a,true,true);this.instance.offset.click.top=c.offset.click.top;this.instance.offset.click.left=c.offset.click.left;this.instance.offset.parent.left-=c.offset.parent.left-this.instance.offset.parent.left;
|
||||
this.instance.offset.parent.top-=c.offset.parent.top-this.instance.offset.parent.top;c._trigger("toSortable",a);c.dropped=this.instance.element;c.currentItem=c.element;this.instance.fromOutside=c}this.instance.currentItem&&this.instance._mouseDrag(a)}else if(this.instance.isOver){this.instance.isOver=0;this.instance.cancelHelperRemoval=true;this.instance.options.revert=false;this.instance._trigger("out",a,this.instance._uiHash(this.instance));this.instance._mouseStop(a,true);this.instance.options.helper=
|
||||
this.instance.options._helper;this.instance.currentItem.remove();this.instance.placeholder&&this.instance.placeholder.remove();c._trigger("fromSortable",a);c.dropped=false}})}});d.ui.plugin.add("draggable","cursor",{start:function(){var a=d("body"),b=d(this).data("draggable").options;if(a.css("cursor"))b._cursor=a.css("cursor");a.css("cursor",b.cursor)},stop:function(){var a=d(this).data("draggable").options;a._cursor&&d("body").css("cursor",a._cursor)}});d.ui.plugin.add("draggable","iframeFix",{start:function(){var a=
|
||||
d(this).data("draggable").options;d(a.iframeFix===true?"iframe":a.iframeFix).each(function(){d('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>').css({width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1E3}).css(d(this).offset()).appendTo("body")})},stop:function(){d("div.ui-draggable-iframeFix").each(function(){this.parentNode.removeChild(this)})}});d.ui.plugin.add("draggable","opacity",{start:function(a,b){a=d(b.helper);b=d(this).data("draggable").options;
|
||||
if(a.css("opacity"))b._opacity=a.css("opacity");a.css("opacity",b.opacity)},stop:function(a,b){a=d(this).data("draggable").options;a._opacity&&d(b.helper).css("opacity",a._opacity)}});d.ui.plugin.add("draggable","scroll",{start:function(){var a=d(this).data("draggable");if(a.scrollParent[0]!=document&&a.scrollParent[0].tagName!="HTML")a.overflowOffset=a.scrollParent.offset()},drag:function(a){var b=d(this).data("draggable"),c=b.options,f=false;if(b.scrollParent[0]!=document&&b.scrollParent[0].tagName!=
|
||||
"HTML"){if(!c.axis||c.axis!="x")if(b.overflowOffset.top+b.scrollParent[0].offsetHeight-a.pageY<c.scrollSensitivity)b.scrollParent[0].scrollTop=f=b.scrollParent[0].scrollTop+c.scrollSpeed;else if(a.pageY-b.overflowOffset.top<c.scrollSensitivity)b.scrollParent[0].scrollTop=f=b.scrollParent[0].scrollTop-c.scrollSpeed;if(!c.axis||c.axis!="y")if(b.overflowOffset.left+b.scrollParent[0].offsetWidth-a.pageX<c.scrollSensitivity)b.scrollParent[0].scrollLeft=f=b.scrollParent[0].scrollLeft+c.scrollSpeed;else if(a.pageX-
|
||||
b.overflowOffset.left<c.scrollSensitivity)b.scrollParent[0].scrollLeft=f=b.scrollParent[0].scrollLeft-c.scrollSpeed}else{if(!c.axis||c.axis!="x")if(a.pageY-d(document).scrollTop()<c.scrollSensitivity)f=d(document).scrollTop(d(document).scrollTop()-c.scrollSpeed);else if(d(window).height()-(a.pageY-d(document).scrollTop())<c.scrollSensitivity)f=d(document).scrollTop(d(document).scrollTop()+c.scrollSpeed);if(!c.axis||c.axis!="y")if(a.pageX-d(document).scrollLeft()<c.scrollSensitivity)f=d(document).scrollLeft(d(document).scrollLeft()-
|
||||
c.scrollSpeed);else if(d(window).width()-(a.pageX-d(document).scrollLeft())<c.scrollSensitivity)f=d(document).scrollLeft(d(document).scrollLeft()+c.scrollSpeed)}f!==false&&d.ui.ddmanager&&!c.dropBehaviour&&d.ui.ddmanager.prepareOffsets(b,a)}});d.ui.plugin.add("draggable","snap",{start:function(){var a=d(this).data("draggable"),b=a.options;a.snapElements=[];d(b.snap.constructor!=String?b.snap.items||":data(draggable)":b.snap).each(function(){var c=d(this),f=c.offset();this!=a.element[0]&&a.snapElements.push({item:this,
|
||||
width:c.outerWidth(),height:c.outerHeight(),top:f.top,left:f.left})})},drag:function(a,b){for(var c=d(this).data("draggable"),f=c.options,e=f.snapTolerance,g=b.offset.left,n=g+c.helperProportions.width,m=b.offset.top,o=m+c.helperProportions.height,h=c.snapElements.length-1;h>=0;h--){var i=c.snapElements[h].left,k=i+c.snapElements[h].width,j=c.snapElements[h].top,l=j+c.snapElements[h].height;if(i-e<g&&g<k+e&&j-e<m&&m<l+e||i-e<g&&g<k+e&&j-e<o&&o<l+e||i-e<n&&n<k+e&&j-e<m&&m<l+e||i-e<n&&n<k+e&&j-e<o&&
|
||||
o<l+e){if(f.snapMode!="inner"){var p=Math.abs(j-o)<=e,q=Math.abs(l-m)<=e,r=Math.abs(i-n)<=e,s=Math.abs(k-g)<=e;if(p)b.position.top=c._convertPositionTo("relative",{top:j-c.helperProportions.height,left:0}).top-c.margins.top;if(q)b.position.top=c._convertPositionTo("relative",{top:l,left:0}).top-c.margins.top;if(r)b.position.left=c._convertPositionTo("relative",{top:0,left:i-c.helperProportions.width}).left-c.margins.left;if(s)b.position.left=c._convertPositionTo("relative",{top:0,left:k}).left-c.margins.left}var t=
|
||||
p||q||r||s;if(f.snapMode!="outer"){p=Math.abs(j-m)<=e;q=Math.abs(l-o)<=e;r=Math.abs(i-g)<=e;s=Math.abs(k-n)<=e;if(p)b.position.top=c._convertPositionTo("relative",{top:j,left:0}).top-c.margins.top;if(q)b.position.top=c._convertPositionTo("relative",{top:l-c.helperProportions.height,left:0}).top-c.margins.top;if(r)b.position.left=c._convertPositionTo("relative",{top:0,left:i}).left-c.margins.left;if(s)b.position.left=c._convertPositionTo("relative",{top:0,left:k-c.helperProportions.width}).left-c.margins.left}if(!c.snapElements[h].snapping&&
|
||||
(p||q||r||s||t))c.options.snap.snap&&c.options.snap.snap.call(c.element,a,d.extend(c._uiHash(),{snapItem:c.snapElements[h].item}));c.snapElements[h].snapping=p||q||r||s||t}else{c.snapElements[h].snapping&&c.options.snap.release&&c.options.snap.release.call(c.element,a,d.extend(c._uiHash(),{snapItem:c.snapElements[h].item}));c.snapElements[h].snapping=false}}}});d.ui.plugin.add("draggable","stack",{start:function(){var a=d(this).data("draggable").options;a=d.makeArray(d(a.stack)).sort(function(c,f){return(parseInt(d(c).css("zIndex"),
|
||||
10)||0)-(parseInt(d(f).css("zIndex"),10)||0)});if(a.length){var b=parseInt(a[0].style.zIndex)||0;d(a).each(function(c){this.style.zIndex=b+c});this[0].style.zIndex=b+a.length}}});d.ui.plugin.add("draggable","zIndex",{start:function(a,b){a=d(b.helper);b=d(this).data("draggable").options;if(a.css("zIndex"))b._zIndex=a.css("zIndex");a.css("zIndex",b.zIndex)},stop:function(a,b){a=d(this).data("draggable").options;a._zIndex&&d(b.helper).css("zIndex",a._zIndex)}})})(jQuery);
|
||||
(function(d){d.widget("ui.droppable",{widgetEventPrefix:"drop",options:{accept:"*",activeClass:false,addClasses:true,greedy:false,hoverClass:false,scope:"default",tolerance:"intersect"},_create:function(){var a=this.options,b=a.accept;this.isover=0;this.isout=1;this.accept=d.isFunction(b)?b:function(c){return c.is(b)};this.proportions={width:this.element[0].offsetWidth,height:this.element[0].offsetHeight};d.ui.ddmanager.droppables[a.scope]=d.ui.ddmanager.droppables[a.scope]||[];d.ui.ddmanager.droppables[a.scope].push(this);
|
||||
a.addClasses&&this.element.addClass("ui-droppable")},destroy:function(){for(var a=d.ui.ddmanager.droppables[this.options.scope],b=0;b<a.length;b++)a[b]==this&&a.splice(b,1);this.element.removeClass("ui-droppable ui-droppable-disabled").removeData("droppable").unbind(".droppable");return this},_setOption:function(a,b){if(a=="accept")this.accept=d.isFunction(b)?b:function(c){return c.is(b)};d.Widget.prototype._setOption.apply(this,arguments)},_activate:function(a){var b=d.ui.ddmanager.current;this.options.activeClass&&
|
||||
this.element.addClass(this.options.activeClass);b&&this._trigger("activate",a,this.ui(b))},_deactivate:function(a){var b=d.ui.ddmanager.current;this.options.activeClass&&this.element.removeClass(this.options.activeClass);b&&this._trigger("deactivate",a,this.ui(b))},_over:function(a){var b=d.ui.ddmanager.current;if(!(!b||(b.currentItem||b.element)[0]==this.element[0]))if(this.accept.call(this.element[0],b.currentItem||b.element)){this.options.hoverClass&&this.element.addClass(this.options.hoverClass);
|
||||
this._trigger("over",a,this.ui(b))}},_out:function(a){var b=d.ui.ddmanager.current;if(!(!b||(b.currentItem||b.element)[0]==this.element[0]))if(this.accept.call(this.element[0],b.currentItem||b.element)){this.options.hoverClass&&this.element.removeClass(this.options.hoverClass);this._trigger("out",a,this.ui(b))}},_drop:function(a,b){var c=b||d.ui.ddmanager.current;if(!c||(c.currentItem||c.element)[0]==this.element[0])return false;var e=false;this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function(){var g=
|
||||
d.data(this,"droppable");if(g.options.greedy&&!g.options.disabled&&g.options.scope==c.options.scope&&g.accept.call(g.element[0],c.currentItem||c.element)&&d.ui.intersect(c,d.extend(g,{offset:g.element.offset()}),g.options.tolerance)){e=true;return false}});if(e)return false;if(this.accept.call(this.element[0],c.currentItem||c.element)){this.options.activeClass&&this.element.removeClass(this.options.activeClass);this.options.hoverClass&&this.element.removeClass(this.options.hoverClass);this._trigger("drop",
|
||||
a,this.ui(c));return this.element}return false},ui:function(a){return{draggable:a.currentItem||a.element,helper:a.helper,position:a.position,offset:a.positionAbs}}});d.extend(d.ui.droppable,{version:"1.8.5"});d.ui.intersect=function(a,b,c){if(!b.offset)return false;var e=(a.positionAbs||a.position.absolute).left,g=e+a.helperProportions.width,f=(a.positionAbs||a.position.absolute).top,h=f+a.helperProportions.height,i=b.offset.left,k=i+b.proportions.width,j=b.offset.top,l=j+b.proportions.height;
|
||||
switch(c){case "fit":return i<=e&&g<=k&&j<=f&&h<=l;case "intersect":return i<e+a.helperProportions.width/2&&g-a.helperProportions.width/2<k&&j<f+a.helperProportions.height/2&&h-a.helperProportions.height/2<l;case "pointer":return d.ui.isOver((a.positionAbs||a.position.absolute).top+(a.clickOffset||a.offset.click).top,(a.positionAbs||a.position.absolute).left+(a.clickOffset||a.offset.click).left,j,i,b.proportions.height,b.proportions.width);case "touch":return(f>=j&&f<=l||h>=j&&h<=l||f<j&&h>l)&&(e>=
|
||||
i&&e<=k||g>=i&&g<=k||e<i&&g>k);default:return false}};d.ui.ddmanager={current:null,droppables:{"default":[]},prepareOffsets:function(a,b){var c=d.ui.ddmanager.droppables[a.options.scope]||[],e=b?b.type:null,g=(a.currentItem||a.element).find(":data(droppable)").andSelf(),f=0;a:for(;f<c.length;f++)if(!(c[f].options.disabled||a&&!c[f].accept.call(c[f].element[0],a.currentItem||a.element))){for(var h=0;h<g.length;h++)if(g[h]==c[f].element[0]){c[f].proportions.height=0;continue a}c[f].visible=c[f].element.css("display")!=
|
||||
"none";if(c[f].visible){c[f].offset=c[f].element.offset();c[f].proportions={width:c[f].element[0].offsetWidth,height:c[f].element[0].offsetHeight};e=="mousedown"&&c[f]._activate.call(c[f],b)}}},drop:function(a,b){var c=false;d.each(d.ui.ddmanager.droppables[a.options.scope]||[],function(){if(this.options){if(!this.options.disabled&&this.visible&&d.ui.intersect(a,this,this.options.tolerance))c=c||this._drop.call(this,b);if(!this.options.disabled&&this.visible&&this.accept.call(this.element[0],a.currentItem||
|
||||
a.element)){this.isout=1;this.isover=0;this._deactivate.call(this,b)}}});return c},drag:function(a,b){a.options.refreshPositions&&d.ui.ddmanager.prepareOffsets(a,b);d.each(d.ui.ddmanager.droppables[a.options.scope]||[],function(){if(!(this.options.disabled||this.greedyChild||!this.visible)){var c=d.ui.intersect(a,this,this.options.tolerance);if(c=!c&&this.isover==1?"isout":c&&this.isover==0?"isover":null){var e;if(this.options.greedy){var g=this.element.parents(":data(droppable):eq(0)");if(g.length){e=
|
||||
d.data(g[0],"droppable");e.greedyChild=c=="isover"?1:0}}if(e&&c=="isover"){e.isover=0;e.isout=1;e._out.call(e,b)}this[c]=1;this[c=="isout"?"isover":"isout"]=0;this[c=="isover"?"_over":"_out"].call(this,b);if(e&&c=="isout"){e.isout=0;e.isover=1;e._over.call(e,b)}}}})}}})(jQuery);
|
||||
(function(e){e.widget("ui.resizable",e.ui.mouse,{widgetEventPrefix:"resize",options:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,containment:false,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1E3},_create:function(){var b=this,a=this.options;this.element.addClass("ui-resizable");e.extend(this,{_aspectRatio:!!a.aspectRatio,aspectRatio:a.aspectRatio,originalElement:this.element,
|
||||
_proportionallyResizeElements:[],_helper:a.helper||a.ghost||a.animate?a.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){/relative/.test(this.element.css("position"))&&e.browser.opera&&this.element.css({position:"relative",top:"auto",left:"auto"});this.element.wrap(e('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),
|
||||
top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=
|
||||
this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=a.handles||(!e(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",
|
||||
nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all")this.handles="n,e,s,w,se,sw,ne,nw";var c=this.handles.split(",");this.handles={};for(var d=0;d<c.length;d++){var f=e.trim(c[d]),g=e('<div class="ui-resizable-handle '+("ui-resizable-"+f)+'"></div>');/sw|se|ne|nw/.test(f)&&g.css({zIndex:++a.zIndex});"se"==f&&g.addClass("ui-icon ui-icon-gripsmall-diagonal-se");this.handles[f]=".ui-resizable-"+f;this.element.append(g)}}this._renderAxis=function(h){h=h||this.element;for(var i in this.handles){if(this.handles[i].constructor==
|
||||
String)this.handles[i]=e(this.handles[i],this.element).show();if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var j=e(this.handles[i],this.element),k=0;k=/sw|ne|nw|se|n|s/.test(i)?j.outerHeight():j.outerWidth();j=["padding",/ne|nw|n/.test(i)?"Top":/se|sw|s/.test(i)?"Bottom":/^e$/.test(i)?"Right":"Left"].join("");h.css(j,k);this._proportionallyResize()}e(this.handles[i])}};this._renderAxis(this.element);this._handles=e(".ui-resizable-handle",this.element).disableSelection();
|
||||
this._handles.mouseover(function(){if(!b.resizing){if(this.className)var h=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);b.axis=h&&h[1]?h[1]:"se"}});if(a.autoHide){this._handles.hide();e(this.element).addClass("ui-resizable-autohide").hover(function(){e(this).removeClass("ui-resizable-autohide");b._handles.show()},function(){if(!b.resizing){e(this).addClass("ui-resizable-autohide");b._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var b=function(c){e(c).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};
|
||||
if(this.elementIsWrapper){b(this.element);var a=this.element;a.after(this.originalElement.css({position:a.css("position"),width:a.outerWidth(),height:a.outerHeight(),top:a.css("top"),left:a.css("left")})).remove()}this.originalElement.css("resize",this.originalResizeStyle);b(this.originalElement);return this},_mouseCapture:function(b){var a=false;for(var c in this.handles)if(e(this.handles[c])[0]==b.target)a=true;return!this.options.disabled&&a},_mouseStart:function(b){var a=this.options,c=this.element.position(),
|
||||
d=this.element;this.resizing=true;this.documentScroll={top:e(document).scrollTop(),left:e(document).scrollLeft()};if(d.is(".ui-draggable")||/absolute/.test(d.css("position")))d.css({position:"absolute",top:c.top,left:c.left});e.browser.opera&&/relative/.test(d.css("position"))&&d.css({position:"relative",top:"auto",left:"auto"});this._renderProxy();c=m(this.helper.css("left"));var f=m(this.helper.css("top"));if(a.containment){c+=e(a.containment).scrollLeft()||0;f+=e(a.containment).scrollTop()||0}this.offset=
|
||||
this.helper.offset();this.position={left:c,top:f};this.size=this._helper?{width:d.outerWidth(),height:d.outerHeight()}:{width:d.width(),height:d.height()};this.originalSize=this._helper?{width:d.outerWidth(),height:d.outerHeight()}:{width:d.width(),height:d.height()};this.originalPosition={left:c,top:f};this.sizeDiff={width:d.outerWidth()-d.width(),height:d.outerHeight()-d.height()};this.originalMousePosition={left:b.pageX,top:b.pageY};this.aspectRatio=typeof a.aspectRatio=="number"?a.aspectRatio:
|
||||
this.originalSize.width/this.originalSize.height||1;a=e(".ui-resizable-"+this.axis).css("cursor");e("body").css("cursor",a=="auto"?this.axis+"-resize":a);d.addClass("ui-resizable-resizing");this._propagate("start",b);return true},_mouseDrag:function(b){var a=this.helper,c=this.originalMousePosition,d=this._change[this.axis];if(!d)return false;c=d.apply(this,[b,b.pageX-c.left||0,b.pageY-c.top||0]);if(this._aspectRatio||b.shiftKey)c=this._updateRatio(c,b);c=this._respectSize(c,b);this._propagate("resize",
|
||||
b);a.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});!this._helper&&this._proportionallyResizeElements.length&&this._proportionallyResize();this._updateCache(c);this._trigger("resize",b,this.ui());return false},_mouseStop:function(b){this.resizing=false;var a=this.options,c=this;if(this._helper){var d=this._proportionallyResizeElements,f=d.length&&/textarea/i.test(d[0].nodeName);d=f&&e.ui.hasScroll(d[0],"left")?0:c.sizeDiff.height;
|
||||
f={width:c.size.width-(f?0:c.sizeDiff.width),height:c.size.height-d};d=parseInt(c.element.css("left"),10)+(c.position.left-c.originalPosition.left)||null;var g=parseInt(c.element.css("top"),10)+(c.position.top-c.originalPosition.top)||null;a.animate||this.element.css(e.extend(f,{top:g,left:d}));c.helper.height(c.size.height);c.helper.width(c.size.width);this._helper&&!a.animate&&this._proportionallyResize()}e("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",
|
||||
b);this._helper&&this.helper.remove();return false},_updateCache:function(b){this.offset=this.helper.offset();if(l(b.left))this.position.left=b.left;if(l(b.top))this.position.top=b.top;if(l(b.height))this.size.height=b.height;if(l(b.width))this.size.width=b.width},_updateRatio:function(b){var a=this.position,c=this.size,d=this.axis;if(b.height)b.width=c.height*this.aspectRatio;else if(b.width)b.height=c.width/this.aspectRatio;if(d=="sw"){b.left=a.left+(c.width-b.width);b.top=null}if(d=="nw"){b.top=
|
||||
a.top+(c.height-b.height);b.left=a.left+(c.width-b.width)}return b},_respectSize:function(b){var a=this.options,c=this.axis,d=l(b.width)&&a.maxWidth&&a.maxWidth<b.width,f=l(b.height)&&a.maxHeight&&a.maxHeight<b.height,g=l(b.width)&&a.minWidth&&a.minWidth>b.width,h=l(b.height)&&a.minHeight&&a.minHeight>b.height;if(g)b.width=a.minWidth;if(h)b.height=a.minHeight;if(d)b.width=a.maxWidth;if(f)b.height=a.maxHeight;var i=this.originalPosition.left+this.originalSize.width,j=this.position.top+this.size.height,
|
||||
k=/sw|nw|w/.test(c);c=/nw|ne|n/.test(c);if(g&&k)b.left=i-a.minWidth;if(d&&k)b.left=i-a.maxWidth;if(h&&c)b.top=j-a.minHeight;if(f&&c)b.top=j-a.maxHeight;if((a=!b.width&&!b.height)&&!b.left&&b.top)b.top=null;else if(a&&!b.top&&b.left)b.left=null;return b},_proportionallyResize:function(){if(this._proportionallyResizeElements.length)for(var b=this.helper||this.element,a=0;a<this._proportionallyResizeElements.length;a++){var c=this._proportionallyResizeElements[a];if(!this.borderDif){var d=[c.css("borderTopWidth"),
|
||||
c.css("borderRightWidth"),c.css("borderBottomWidth"),c.css("borderLeftWidth")],f=[c.css("paddingTop"),c.css("paddingRight"),c.css("paddingBottom"),c.css("paddingLeft")];this.borderDif=e.map(d,function(g,h){g=parseInt(g,10)||0;h=parseInt(f[h],10)||0;return g+h})}e.browser.msie&&(e(b).is(":hidden")||e(b).parents(":hidden").length)||c.css({height:b.height()-this.borderDif[0]-this.borderDif[2]||0,width:b.width()-this.borderDif[1]-this.borderDif[3]||0})}},_renderProxy:function(){var b=this.options;this.elementOffset=
|
||||
this.element.offset();if(this._helper){this.helper=this.helper||e('<div style="overflow:hidden;"></div>');var a=e.browser.msie&&e.browser.version<7,c=a?1:0;a=a?2:-1;this.helper.addClass(this._helper).css({width:this.element.outerWidth()+a,height:this.element.outerHeight()+a,position:"absolute",left:this.elementOffset.left-c+"px",top:this.elementOffset.top-c+"px",zIndex:++b.zIndex});this.helper.appendTo("body").disableSelection()}else this.helper=this.element},_change:{e:function(b,a){return{width:this.originalSize.width+
|
||||
a}},w:function(b,a){return{left:this.originalPosition.left+a,width:this.originalSize.width-a}},n:function(b,a,c){return{top:this.originalPosition.top+c,height:this.originalSize.height-c}},s:function(b,a,c){return{height:this.originalSize.height+c}},se:function(b,a,c){return e.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[b,a,c]))},sw:function(b,a,c){return e.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[b,a,c]))},ne:function(b,a,c){return e.extend(this._change.n.apply(this,
|
||||
arguments),this._change.e.apply(this,[b,a,c]))},nw:function(b,a,c){return e.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[b,a,c]))}},_propagate:function(b,a){e.ui.plugin.call(this,b,[a,this.ui()]);b!="resize"&&this._trigger(b,a,this.ui())},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}});e.extend(e.ui.resizable,
|
||||
{version:"1.8.5"});e.ui.plugin.add("resizable","alsoResize",{start:function(){var b=e(this).data("resizable").options,a=function(c){e(c).each(function(){var d=e(this);d.data("resizable-alsoresize",{width:parseInt(d.width(),10),height:parseInt(d.height(),10),left:parseInt(d.css("left"),10),top:parseInt(d.css("top"),10),position:d.css("position")})})};if(typeof b.alsoResize=="object"&&!b.alsoResize.parentNode)if(b.alsoResize.length){b.alsoResize=b.alsoResize[0];a(b.alsoResize)}else e.each(b.alsoResize,
|
||||
function(c){a(c)});else a(b.alsoResize)},resize:function(b,a){var c=e(this).data("resizable");b=c.options;var d=c.originalSize,f=c.originalPosition,g={height:c.size.height-d.height||0,width:c.size.width-d.width||0,top:c.position.top-f.top||0,left:c.position.left-f.left||0},h=function(i,j){e(i).each(function(){var k=e(this),q=e(this).data("resizable-alsoresize"),p={},r=j&&j.length?j:k.parents(a.originalElement[0]).length?["width","height"]:["width","height","top","left"];e.each(r,function(n,o){if((n=
|
||||
(q[o]||0)+(g[o]||0))&&n>=0)p[o]=n||null});if(e.browser.opera&&/relative/.test(k.css("position"))){c._revertToRelativePosition=true;k.css({position:"absolute",top:"auto",left:"auto"})}k.css(p)})};typeof b.alsoResize=="object"&&!b.alsoResize.nodeType?e.each(b.alsoResize,function(i,j){h(i,j)}):h(b.alsoResize)},stop:function(){var b=e(this).data("resizable"),a=b.options,c=function(d){e(d).each(function(){var f=e(this);f.css({position:f.data("resizable-alsoresize").position})})};if(b._revertToRelativePosition){b._revertToRelativePosition=
|
||||
false;typeof a.alsoResize=="object"&&!a.alsoResize.nodeType?e.each(a.alsoResize,function(d){c(d)}):c(a.alsoResize)}e(this).removeData("resizable-alsoresize")}});e.ui.plugin.add("resizable","animate",{stop:function(b){var a=e(this).data("resizable"),c=a.options,d=a._proportionallyResizeElements,f=d.length&&/textarea/i.test(d[0].nodeName),g=f&&e.ui.hasScroll(d[0],"left")?0:a.sizeDiff.height;f={width:a.size.width-(f?0:a.sizeDiff.width),height:a.size.height-g};g=parseInt(a.element.css("left"),10)+(a.position.left-
|
||||
a.originalPosition.left)||null;var h=parseInt(a.element.css("top"),10)+(a.position.top-a.originalPosition.top)||null;a.element.animate(e.extend(f,h&&g?{top:h,left:g}:{}),{duration:c.animateDuration,easing:c.animateEasing,step:function(){var i={width:parseInt(a.element.css("width"),10),height:parseInt(a.element.css("height"),10),top:parseInt(a.element.css("top"),10),left:parseInt(a.element.css("left"),10)};d&&d.length&&e(d[0]).css({width:i.width,height:i.height});a._updateCache(i);a._propagate("resize",
|
||||
b)}})}});e.ui.plugin.add("resizable","containment",{start:function(){var b=e(this).data("resizable"),a=b.element,c=b.options.containment;if(a=c instanceof e?c.get(0):/parent/.test(c)?a.parent().get(0):c){b.containerElement=e(a);if(/document/.test(c)||c==document){b.containerOffset={left:0,top:0};b.containerPosition={left:0,top:0};b.parentData={element:e(document),left:0,top:0,width:e(document).width(),height:e(document).height()||document.body.parentNode.scrollHeight}}else{var d=e(a),f=[];e(["Top",
|
||||
"Right","Left","Bottom"]).each(function(i,j){f[i]=m(d.css("padding"+j))});b.containerOffset=d.offset();b.containerPosition=d.position();b.containerSize={height:d.innerHeight()-f[3],width:d.innerWidth()-f[1]};c=b.containerOffset;var g=b.containerSize.height,h=b.containerSize.width;h=e.ui.hasScroll(a,"left")?a.scrollWidth:h;g=e.ui.hasScroll(a)?a.scrollHeight:g;b.parentData={element:a,left:c.left,top:c.top,width:h,height:g}}}},resize:function(b){var a=e(this).data("resizable"),c=a.options,d=a.containerOffset,
|
||||
f=a.position;b=a._aspectRatio||b.shiftKey;var g={top:0,left:0},h=a.containerElement;if(h[0]!=document&&/static/.test(h.css("position")))g=d;if(f.left<(a._helper?d.left:0)){a.size.width+=a._helper?a.position.left-d.left:a.position.left-g.left;if(b)a.size.height=a.size.width/c.aspectRatio;a.position.left=c.helper?d.left:0}if(f.top<(a._helper?d.top:0)){a.size.height+=a._helper?a.position.top-d.top:a.position.top;if(b)a.size.width=a.size.height*c.aspectRatio;a.position.top=a._helper?d.top:0}a.offset.left=
|
||||
a.parentData.left+a.position.left;a.offset.top=a.parentData.top+a.position.top;c=Math.abs((a._helper?a.offset.left-g.left:a.offset.left-g.left)+a.sizeDiff.width);d=Math.abs((a._helper?a.offset.top-g.top:a.offset.top-d.top)+a.sizeDiff.height);f=a.containerElement.get(0)==a.element.parent().get(0);g=/relative|absolute/.test(a.containerElement.css("position"));if(f&&g)c-=a.parentData.left;if(c+a.size.width>=a.parentData.width){a.size.width=a.parentData.width-c;if(b)a.size.height=a.size.width/a.aspectRatio}if(d+
|
||||
a.size.height>=a.parentData.height){a.size.height=a.parentData.height-d;if(b)a.size.width=a.size.height*a.aspectRatio}},stop:function(){var b=e(this).data("resizable"),a=b.options,c=b.containerOffset,d=b.containerPosition,f=b.containerElement,g=e(b.helper),h=g.offset(),i=g.outerWidth()-b.sizeDiff.width;g=g.outerHeight()-b.sizeDiff.height;b._helper&&!a.animate&&/relative/.test(f.css("position"))&&e(this).css({left:h.left-d.left-c.left,width:i,height:g});b._helper&&!a.animate&&/static/.test(f.css("position"))&&
|
||||
e(this).css({left:h.left-d.left-c.left,width:i,height:g})}});e.ui.plugin.add("resizable","ghost",{start:function(){var b=e(this).data("resizable"),a=b.options,c=b.size;b.ghost=b.originalElement.clone();b.ghost.css({opacity:0.25,display:"block",position:"relative",height:c.height,width:c.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof a.ghost=="string"?a.ghost:"");b.ghost.appendTo(b.helper)},resize:function(){var b=e(this).data("resizable");b.ghost&&b.ghost.css({position:"relative",
|
||||
height:b.size.height,width:b.size.width})},stop:function(){var b=e(this).data("resizable");b.ghost&&b.helper&&b.helper.get(0).removeChild(b.ghost.get(0))}});e.ui.plugin.add("resizable","grid",{resize:function(){var b=e(this).data("resizable"),a=b.options,c=b.size,d=b.originalSize,f=b.originalPosition,g=b.axis;a.grid=typeof a.grid=="number"?[a.grid,a.grid]:a.grid;var h=Math.round((c.width-d.width)/(a.grid[0]||1))*(a.grid[0]||1);a=Math.round((c.height-d.height)/(a.grid[1]||1))*(a.grid[1]||1);if(/^(se|s|e)$/.test(g)){b.size.width=
|
||||
d.width+h;b.size.height=d.height+a}else if(/^(ne)$/.test(g)){b.size.width=d.width+h;b.size.height=d.height+a;b.position.top=f.top-a}else{if(/^(sw)$/.test(g)){b.size.width=d.width+h;b.size.height=d.height+a}else{b.size.width=d.width+h;b.size.height=d.height+a;b.position.top=f.top-a}b.position.left=f.left-h}}});var m=function(b){return parseInt(b,10)||0},l=function(b){return!isNaN(parseInt(b,10))}})(jQuery);
|
||||
(function(e){e.widget("ui.selectable",e.ui.mouse,{options:{appendTo:"body",autoRefresh:true,distance:0,filter:"*",tolerance:"touch"},_create:function(){var c=this;this.element.addClass("ui-selectable");this.dragged=false;var f;this.refresh=function(){f=e(c.options.filter,c.element[0]);f.each(function(){var d=e(this),b=d.offset();e.data(this,"selectable-item",{element:this,$element:d,left:b.left,top:b.top,right:b.left+d.outerWidth(),bottom:b.top+d.outerHeight(),startselected:false,selected:d.hasClass("ui-selected"),
|
||||
selecting:d.hasClass("ui-selecting"),unselecting:d.hasClass("ui-unselecting")})})};this.refresh();this.selectees=f.addClass("ui-selectee");this._mouseInit();this.helper=e("<div class='ui-selectable-helper'></div>")},destroy:function(){this.selectees.removeClass("ui-selectee").removeData("selectable-item");this.element.removeClass("ui-selectable ui-selectable-disabled").removeData("selectable").unbind(".selectable");this._mouseDestroy();return this},_mouseStart:function(c){var f=this;this.opos=[c.pageX,
|
||||
c.pageY];if(!this.options.disabled){var d=this.options;this.selectees=e(d.filter,this.element[0]);this._trigger("start",c);e(d.appendTo).append(this.helper);this.helper.css({left:c.clientX,top:c.clientY,width:0,height:0});d.autoRefresh&&this.refresh();this.selectees.filter(".ui-selected").each(function(){var b=e.data(this,"selectable-item");b.startselected=true;if(!c.metaKey){b.$element.removeClass("ui-selected");b.selected=false;b.$element.addClass("ui-unselecting");b.unselecting=true;f._trigger("unselecting",
|
||||
c,{unselecting:b.element})}});e(c.target).parents().andSelf().each(function(){var b=e.data(this,"selectable-item");if(b){var g=!c.metaKey||!b.$element.hasClass("ui-selected");b.$element.removeClass(g?"ui-unselecting":"ui-selected").addClass(g?"ui-selecting":"ui-unselecting");b.unselecting=!g;b.selecting=g;(b.selected=g)?f._trigger("selecting",c,{selecting:b.element}):f._trigger("unselecting",c,{unselecting:b.element});return false}})}},_mouseDrag:function(c){var f=this;this.dragged=true;if(!this.options.disabled){var d=
|
||||
this.options,b=this.opos[0],g=this.opos[1],h=c.pageX,i=c.pageY;if(b>h){var j=h;h=b;b=j}if(g>i){j=i;i=g;g=j}this.helper.css({left:b,top:g,width:h-b,height:i-g});this.selectees.each(function(){var a=e.data(this,"selectable-item");if(!(!a||a.element==f.element[0])){var k=false;if(d.tolerance=="touch")k=!(a.left>h||a.right<b||a.top>i||a.bottom<g);else if(d.tolerance=="fit")k=a.left>b&&a.right<h&&a.top>g&&a.bottom<i;if(k){if(a.selected){a.$element.removeClass("ui-selected");a.selected=false}if(a.unselecting){a.$element.removeClass("ui-unselecting");
|
||||
a.unselecting=false}if(!a.selecting){a.$element.addClass("ui-selecting");a.selecting=true;f._trigger("selecting",c,{selecting:a.element})}}else{if(a.selecting)if(c.metaKey&&a.startselected){a.$element.removeClass("ui-selecting");a.selecting=false;a.$element.addClass("ui-selected");a.selected=true}else{a.$element.removeClass("ui-selecting");a.selecting=false;if(a.startselected){a.$element.addClass("ui-unselecting");a.unselecting=true}f._trigger("unselecting",c,{unselecting:a.element})}if(a.selected)if(!c.metaKey&&
|
||||
!a.startselected){a.$element.removeClass("ui-selected");a.selected=false;a.$element.addClass("ui-unselecting");a.unselecting=true;f._trigger("unselecting",c,{unselecting:a.element})}}}});return false}},_mouseStop:function(c){var f=this;this.dragged=false;e(".ui-unselecting",this.element[0]).each(function(){var d=e.data(this,"selectable-item");d.$element.removeClass("ui-unselecting");d.unselecting=false;d.startselected=false;f._trigger("unselected",c,{unselected:d.element})});e(".ui-selecting",this.element[0]).each(function(){var d=
|
||||
e.data(this,"selectable-item");d.$element.removeClass("ui-selecting").addClass("ui-selected");d.selecting=false;d.selected=true;d.startselected=true;f._trigger("selected",c,{selected:d.element})});this._trigger("stop",c);this.helper.remove();return false}});e.extend(e.ui.selectable,{version:"1.8.5"})})(jQuery);
|
||||
(function(d){d.widget("ui.sortable",d.ui.mouse,{widgetEventPrefix:"sort",options:{appendTo:"parent",axis:false,connectWith:false,containment:false,cursor:"auto",cursorAt:false,dropOnEmpty:true,forcePlaceholderSize:false,forceHelperSize:false,grid:false,handle:false,helper:"original",items:"> *",opacity:false,placeholder:false,revert:false,scroll:true,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1E3},_create:function(){this.containerCache={};this.element.addClass("ui-sortable");
|
||||
this.refresh();this.floating=this.items.length?/left|right/.test(this.items[0].item.css("float")):false;this.offset=this.element.offset();this._mouseInit()},destroy:function(){this.element.removeClass("ui-sortable ui-sortable-disabled").removeData("sortable").unbind(".sortable");this._mouseDestroy();for(var a=this.items.length-1;a>=0;a--)this.items[a].item.removeData("sortable-item");return this},_setOption:function(a,b){if(a==="disabled"){this.options[a]=b;this.widget()[b?"addClass":"removeClass"]("ui-sortable-disabled")}else d.Widget.prototype._setOption.apply(this,
|
||||
arguments)},_mouseCapture:function(a,b){if(this.reverting)return false;if(this.options.disabled||this.options.type=="static")return false;this._refreshItems(a);var c=null,e=this;d(a.target).parents().each(function(){if(d.data(this,"sortable-item")==e){c=d(this);return false}});if(d.data(a.target,"sortable-item")==e)c=d(a.target);if(!c)return false;if(this.options.handle&&!b){var f=false;d(this.options.handle,c).find("*").andSelf().each(function(){if(this==a.target)f=true});if(!f)return false}this.currentItem=
|
||||
c;this._removeCurrentsFromItems();return true},_mouseStart:function(a,b,c){b=this.options;var e=this;this.currentContainer=this;this.refreshPositions();this.helper=this._createHelper(a);this._cacheHelperProportions();this._cacheMargins();this.scrollParent=this.helper.scrollParent();this.offset=this.currentItem.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};this.helper.css("position","absolute");this.cssPosition=this.helper.css("position");d.extend(this.offset,
|
||||
{click:{left:a.pageX-this.offset.left,top:a.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()});this.originalPosition=this._generatePosition(a);this.originalPageX=a.pageX;this.originalPageY=a.pageY;b.cursorAt&&this._adjustOffsetFromHelper(b.cursorAt);this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]};this.helper[0]!=this.currentItem[0]&&this.currentItem.hide();this._createPlaceholder();b.containment&&this._setContainment();
|
||||
if(b.cursor){if(d("body").css("cursor"))this._storedCursor=d("body").css("cursor");d("body").css("cursor",b.cursor)}if(b.opacity){if(this.helper.css("opacity"))this._storedOpacity=this.helper.css("opacity");this.helper.css("opacity",b.opacity)}if(b.zIndex){if(this.helper.css("zIndex"))this._storedZIndex=this.helper.css("zIndex");this.helper.css("zIndex",b.zIndex)}if(this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML")this.overflowOffset=this.scrollParent.offset();this._trigger("start",
|
||||
a,this._uiHash());this._preserveHelperProportions||this._cacheHelperProportions();if(!c)for(c=this.containers.length-1;c>=0;c--)this.containers[c]._trigger("activate",a,e._uiHash(this));if(d.ui.ddmanager)d.ui.ddmanager.current=this;d.ui.ddmanager&&!b.dropBehaviour&&d.ui.ddmanager.prepareOffsets(this,a);this.dragging=true;this.helper.addClass("ui-sortable-helper");this._mouseDrag(a);return true},_mouseDrag:function(a){this.position=this._generatePosition(a);this.positionAbs=this._convertPositionTo("absolute");
|
||||
if(!this.lastPositionAbs)this.lastPositionAbs=this.positionAbs;if(this.options.scroll){var b=this.options,c=false;if(this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"){if(this.overflowOffset.top+this.scrollParent[0].offsetHeight-a.pageY<b.scrollSensitivity)this.scrollParent[0].scrollTop=c=this.scrollParent[0].scrollTop+b.scrollSpeed;else if(a.pageY-this.overflowOffset.top<b.scrollSensitivity)this.scrollParent[0].scrollTop=c=this.scrollParent[0].scrollTop-b.scrollSpeed;if(this.overflowOffset.left+
|
||||
this.scrollParent[0].offsetWidth-a.pageX<b.scrollSensitivity)this.scrollParent[0].scrollLeft=c=this.scrollParent[0].scrollLeft+b.scrollSpeed;else if(a.pageX-this.overflowOffset.left<b.scrollSensitivity)this.scrollParent[0].scrollLeft=c=this.scrollParent[0].scrollLeft-b.scrollSpeed}else{if(a.pageY-d(document).scrollTop()<b.scrollSensitivity)c=d(document).scrollTop(d(document).scrollTop()-b.scrollSpeed);else if(d(window).height()-(a.pageY-d(document).scrollTop())<b.scrollSensitivity)c=d(document).scrollTop(d(document).scrollTop()+
|
||||
b.scrollSpeed);if(a.pageX-d(document).scrollLeft()<b.scrollSensitivity)c=d(document).scrollLeft(d(document).scrollLeft()-b.scrollSpeed);else if(d(window).width()-(a.pageX-d(document).scrollLeft())<b.scrollSensitivity)c=d(document).scrollLeft(d(document).scrollLeft()+b.scrollSpeed)}c!==false&&d.ui.ddmanager&&!b.dropBehaviour&&d.ui.ddmanager.prepareOffsets(this,a)}this.positionAbs=this._convertPositionTo("absolute");if(!this.options.axis||this.options.axis!="y")this.helper[0].style.left=this.position.left+
|
||||
"px";if(!this.options.axis||this.options.axis!="x")this.helper[0].style.top=this.position.top+"px";for(b=this.items.length-1;b>=0;b--){c=this.items[b];var e=c.item[0],f=this._intersectsWithPointer(c);if(f)if(e!=this.currentItem[0]&&this.placeholder[f==1?"next":"prev"]()[0]!=e&&!d.ui.contains(this.placeholder[0],e)&&(this.options.type=="semi-dynamic"?!d.ui.contains(this.element[0],e):true)){this.direction=f==1?"down":"up";if(this.options.tolerance=="pointer"||this._intersectsWithSides(c))this._rearrange(a,
|
||||
c);else break;this._trigger("change",a,this._uiHash());break}}this._contactContainers(a);d.ui.ddmanager&&d.ui.ddmanager.drag(this,a);this._trigger("sort",a,this._uiHash());this.lastPositionAbs=this.positionAbs;return false},_mouseStop:function(a,b){if(a){d.ui.ddmanager&&!this.options.dropBehaviour&&d.ui.ddmanager.drop(this,a);if(this.options.revert){var c=this;b=c.placeholder.offset();c.reverting=true;d(this.helper).animate({left:b.left-this.offset.parent.left-c.margins.left+(this.offsetParent[0]==
|
||||
document.body?0:this.offsetParent[0].scrollLeft),top:b.top-this.offset.parent.top-c.margins.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)},parseInt(this.options.revert,10)||500,function(){c._clear(a)})}else this._clear(a,b);return false}},cancel:function(){var a=this;if(this.dragging){this._mouseUp();this.options.helper=="original"?this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"):this.currentItem.show();for(var b=this.containers.length-1;b>=0;b--){this.containers[b]._trigger("deactivate",
|
||||
null,a._uiHash(this));if(this.containers[b].containerCache.over){this.containers[b]._trigger("out",null,a._uiHash(this));this.containers[b].containerCache.over=0}}}this.placeholder[0].parentNode&&this.placeholder[0].parentNode.removeChild(this.placeholder[0]);this.options.helper!="original"&&this.helper&&this.helper[0].parentNode&&this.helper.remove();d.extend(this,{helper:null,dragging:false,reverting:false,_noFinalSort:null});this.domPosition.prev?d(this.domPosition.prev).after(this.currentItem):
|
||||
d(this.domPosition.parent).prepend(this.currentItem);return this},serialize:function(a){var b=this._getItemsAsjQuery(a&&a.connected),c=[];a=a||{};d(b).each(function(){var e=(d(a.item||this).attr(a.attribute||"id")||"").match(a.expression||/(.+)[-=_](.+)/);if(e)c.push((a.key||e[1]+"[]")+"="+(a.key&&a.expression?e[1]:e[2]))});!c.length&&a.key&&c.push(a.key+"=");return c.join("&")},toArray:function(a){var b=this._getItemsAsjQuery(a&&a.connected),c=[];a=a||{};b.each(function(){c.push(d(a.item||this).attr(a.attribute||
|
||||
"id")||"")});return c},_intersectsWith:function(a){var b=this.positionAbs.left,c=b+this.helperProportions.width,e=this.positionAbs.top,f=e+this.helperProportions.height,g=a.left,h=g+a.width,i=a.top,k=i+a.height,j=this.offset.click.top,l=this.offset.click.left;j=e+j>i&&e+j<k&&b+l>g&&b+l<h;return this.options.tolerance=="pointer"||this.options.forcePointerForContainers||this.options.tolerance!="pointer"&&this.helperProportions[this.floating?"width":"height"]>a[this.floating?"width":"height"]?j:g<b+
|
||||
this.helperProportions.width/2&&c-this.helperProportions.width/2<h&&i<e+this.helperProportions.height/2&&f-this.helperProportions.height/2<k},_intersectsWithPointer:function(a){var b=d.ui.isOverAxis(this.positionAbs.top+this.offset.click.top,a.top,a.height);a=d.ui.isOverAxis(this.positionAbs.left+this.offset.click.left,a.left,a.width);b=b&&a;a=this._getDragVerticalDirection();var c=this._getDragHorizontalDirection();if(!b)return false;return this.floating?c&&c=="right"||a=="down"?2:1:a&&(a=="down"?
|
||||
2:1)},_intersectsWithSides:function(a){var b=d.ui.isOverAxis(this.positionAbs.top+this.offset.click.top,a.top+a.height/2,a.height);a=d.ui.isOverAxis(this.positionAbs.left+this.offset.click.left,a.left+a.width/2,a.width);var c=this._getDragVerticalDirection(),e=this._getDragHorizontalDirection();return this.floating&&e?e=="right"&&a||e=="left"&&!a:c&&(c=="down"&&b||c=="up"&&!b)},_getDragVerticalDirection:function(){var a=this.positionAbs.top-this.lastPositionAbs.top;return a!=0&&(a>0?"down":"up")},
|
||||
_getDragHorizontalDirection:function(){var a=this.positionAbs.left-this.lastPositionAbs.left;return a!=0&&(a>0?"right":"left")},refresh:function(a){this._refreshItems(a);this.refreshPositions();return this},_connectWith:function(){var a=this.options;return a.connectWith.constructor==String?[a.connectWith]:a.connectWith},_getItemsAsjQuery:function(a){var b=[],c=[],e=this._connectWith();if(e&&a)for(a=e.length-1;a>=0;a--)for(var f=d(e[a]),g=f.length-1;g>=0;g--){var h=d.data(f[g],"sortable");if(h&&h!=
|
||||
this&&!h.options.disabled)c.push([d.isFunction(h.options.items)?h.options.items.call(h.element):d(h.options.items,h.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),h])}c.push([d.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):d(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]);for(a=c.length-1;a>=0;a--)c[a][0].each(function(){b.push(this)});return d(b)},_removeCurrentsFromItems:function(){for(var a=
|
||||
this.currentItem.find(":data(sortable-item)"),b=0;b<this.items.length;b++)for(var c=0;c<a.length;c++)a[c]==this.items[b].item[0]&&this.items.splice(b,1)},_refreshItems:function(a){this.items=[];this.containers=[this];var b=this.items,c=[[d.isFunction(this.options.items)?this.options.items.call(this.element[0],a,{item:this.currentItem}):d(this.options.items,this.element),this]],e=this._connectWith();if(e)for(var f=e.length-1;f>=0;f--)for(var g=d(e[f]),h=g.length-1;h>=0;h--){var i=d.data(g[h],"sortable");
|
||||
if(i&&i!=this&&!i.options.disabled){c.push([d.isFunction(i.options.items)?i.options.items.call(i.element[0],a,{item:this.currentItem}):d(i.options.items,i.element),i]);this.containers.push(i)}}for(f=c.length-1;f>=0;f--){a=c[f][1];e=c[f][0];h=0;for(g=e.length;h<g;h++){i=d(e[h]);i.data("sortable-item",a);b.push({item:i,instance:a,width:0,height:0,left:0,top:0})}}},refreshPositions:function(a){if(this.offsetParent&&this.helper)this.offset.parent=this._getParentOffset();for(var b=this.items.length-1;b>=
|
||||
0;b--){var c=this.items[b],e=this.options.toleranceElement?d(this.options.toleranceElement,c.item):c.item;if(!a){c.width=e.outerWidth();c.height=e.outerHeight()}e=e.offset();c.left=e.left;c.top=e.top}if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);else for(b=this.containers.length-1;b>=0;b--){e=this.containers[b].element.offset();this.containers[b].containerCache.left=e.left;this.containers[b].containerCache.top=e.top;this.containers[b].containerCache.width=
|
||||
this.containers[b].element.outerWidth();this.containers[b].containerCache.height=this.containers[b].element.outerHeight()}return this},_createPlaceholder:function(a){var b=a||this,c=b.options;if(!c.placeholder||c.placeholder.constructor==String){var e=c.placeholder;c.placeholder={element:function(){var f=d(document.createElement(b.currentItem[0].nodeName)).addClass(e||b.currentItem[0].className+" ui-sortable-placeholder").removeClass("ui-sortable-helper")[0];if(!e)f.style.visibility="hidden";return f},
|
||||
update:function(f,g){if(!(e&&!c.forcePlaceholderSize)){g.height()||g.height(b.currentItem.innerHeight()-parseInt(b.currentItem.css("paddingTop")||0,10)-parseInt(b.currentItem.css("paddingBottom")||0,10));g.width()||g.width(b.currentItem.innerWidth()-parseInt(b.currentItem.css("paddingLeft")||0,10)-parseInt(b.currentItem.css("paddingRight")||0,10))}}}}b.placeholder=d(c.placeholder.element.call(b.element,b.currentItem));b.currentItem.after(b.placeholder);c.placeholder.update(b,b.placeholder)},_contactContainers:function(a){for(var b=
|
||||
null,c=null,e=this.containers.length-1;e>=0;e--)if(!d.ui.contains(this.currentItem[0],this.containers[e].element[0]))if(this._intersectsWith(this.containers[e].containerCache)){if(!(b&&d.ui.contains(this.containers[e].element[0],b.element[0]))){b=this.containers[e];c=e}}else if(this.containers[e].containerCache.over){this.containers[e]._trigger("out",a,this._uiHash(this));this.containers[e].containerCache.over=0}if(b)if(this.containers.length===1){this.containers[c]._trigger("over",a,this._uiHash(this));
|
||||
this.containers[c].containerCache.over=1}else if(this.currentContainer!=this.containers[c]){b=1E4;e=null;for(var f=this.positionAbs[this.containers[c].floating?"left":"top"],g=this.items.length-1;g>=0;g--)if(d.ui.contains(this.containers[c].element[0],this.items[g].item[0])){var h=this.items[g][this.containers[c].floating?"left":"top"];if(Math.abs(h-f)<b){b=Math.abs(h-f);e=this.items[g]}}if(e||this.options.dropOnEmpty){this.currentContainer=this.containers[c];e?this._rearrange(a,e,null,true):this._rearrange(a,
|
||||
null,this.containers[c].element,true);this._trigger("change",a,this._uiHash());this.containers[c]._trigger("change",a,this._uiHash(this));this.options.placeholder.update(this.currentContainer,this.placeholder);this.containers[c]._trigger("over",a,this._uiHash(this));this.containers[c].containerCache.over=1}}},_createHelper:function(a){var b=this.options;a=d.isFunction(b.helper)?d(b.helper.apply(this.element[0],[a,this.currentItem])):b.helper=="clone"?this.currentItem.clone():this.currentItem;a.parents("body").length||
|
||||
d(b.appendTo!="parent"?b.appendTo:this.currentItem[0].parentNode)[0].appendChild(a[0]);if(a[0]==this.currentItem[0])this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css("position"),top:this.currentItem.css("top"),left:this.currentItem.css("left")};if(a[0].style.width==""||b.forceHelperSize)a.width(this.currentItem.width());if(a[0].style.height==""||b.forceHelperSize)a.height(this.currentItem.height());return a},_adjustOffsetFromHelper:function(a){if(typeof a==
|
||||
"string")a=a.split(" ");if(d.isArray(a))a={left:+a[0],top:+a[1]||0};if("left"in a)this.offset.click.left=a.left+this.margins.left;if("right"in a)this.offset.click.left=this.helperProportions.width-a.right+this.margins.left;if("top"in a)this.offset.click.top=a.top+this.margins.top;if("bottom"in a)this.offset.click.top=this.helperProportions.height-a.bottom+this.margins.top},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var a=this.offsetParent.offset();if(this.cssPosition==
|
||||
"absolute"&&this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],this.offsetParent[0])){a.left+=this.scrollParent.scrollLeft();a.top+=this.scrollParent.scrollTop()}if(this.offsetParent[0]==document.body||this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()=="html"&&d.browser.msie)a={top:0,left:0};return{top:a.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:a.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition==
|
||||
"relative"){var a=this.currentItem.position();return{top:a.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:a.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}else return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.currentItem.css("marginLeft"),10)||0,top:parseInt(this.currentItem.css("marginTop"),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},
|
||||
_setContainment:function(){var a=this.options;if(a.containment=="parent")a.containment=this.helper[0].parentNode;if(a.containment=="document"||a.containment=="window")this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,d(a.containment=="document"?document:window).width()-this.helperProportions.width-this.margins.left,(d(a.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-
|
||||
this.margins.top];if(!/^(document|window|parent)$/.test(a.containment)){var b=d(a.containment)[0];a=d(a.containment).offset();var c=d(b).css("overflow")!="hidden";this.containment=[a.left+(parseInt(d(b).css("borderLeftWidth"),10)||0)+(parseInt(d(b).css("paddingLeft"),10)||0)-this.margins.left,a.top+(parseInt(d(b).css("borderTopWidth"),10)||0)+(parseInt(d(b).css("paddingTop"),10)||0)-this.margins.top,a.left+(c?Math.max(b.scrollWidth,b.offsetWidth):b.offsetWidth)-(parseInt(d(b).css("borderLeftWidth"),
|
||||
10)||0)-(parseInt(d(b).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,a.top+(c?Math.max(b.scrollHeight,b.offsetHeight):b.offsetHeight)-(parseInt(d(b).css("borderTopWidth"),10)||0)-(parseInt(d(b).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top]}},_convertPositionTo:function(a,b){if(!b)b=this.position;a=a=="absolute"?1:-1;var c=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],this.offsetParent[0]))?
|
||||
this.offsetParent:this.scrollParent,e=/(html|body)/i.test(c[0].tagName);return{top:b.top+this.offset.relative.top*a+this.offset.parent.top*a-(d.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollTop():e?0:c.scrollTop())*a),left:b.left+this.offset.relative.left*a+this.offset.parent.left*a-(d.browser.safari&&this.cssPosition=="fixed"?0:(this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():e?0:c.scrollLeft())*a)}},_generatePosition:function(a){var b=
|
||||
this.options,c=this.cssPosition=="absolute"&&!(this.scrollParent[0]!=document&&d.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,e=/(html|body)/i.test(c[0].tagName);if(this.cssPosition=="relative"&&!(this.scrollParent[0]!=document&&this.scrollParent[0]!=this.offsetParent[0]))this.offset.relative=this._getRelativeOffset();var f=a.pageX,g=a.pageY;if(this.originalPosition){if(this.containment){if(a.pageX-this.offset.click.left<this.containment[0])f=this.containment[0]+
|
||||
this.offset.click.left;if(a.pageY-this.offset.click.top<this.containment[1])g=this.containment[1]+this.offset.click.top;if(a.pageX-this.offset.click.left>this.containment[2])f=this.containment[2]+this.offset.click.left;if(a.pageY-this.offset.click.top>this.containment[3])g=this.containment[3]+this.offset.click.top}if(b.grid){g=this.originalPageY+Math.round((g-this.originalPageY)/b.grid[1])*b.grid[1];g=this.containment?!(g-this.offset.click.top<this.containment[1]||g-this.offset.click.top>this.containment[3])?
|
||||
g:!(g-this.offset.click.top<this.containment[1])?g-b.grid[1]:g+b.grid[1]:g;f=this.originalPageX+Math.round((f-this.originalPageX)/b.grid[0])*b.grid[0];f=this.containment?!(f-this.offset.click.left<this.containment[0]||f-this.offset.click.left>this.containment[2])?f:!(f-this.offset.click.left<this.containment[0])?f-b.grid[0]:f+b.grid[0]:f}}return{top:g-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(d.browser.safari&&this.cssPosition=="fixed"?0:this.cssPosition=="fixed"?-this.scrollParent.scrollTop():
|
||||
e?0:c.scrollTop()),left:f-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+(d.browser.safari&&this.cssPosition=="fixed"?0:this.cssPosition=="fixed"?-this.scrollParent.scrollLeft():e?0:c.scrollLeft())}},_rearrange:function(a,b,c,e){c?c[0].appendChild(this.placeholder[0]):b.item[0].parentNode.insertBefore(this.placeholder[0],this.direction=="down"?b.item[0]:b.item[0].nextSibling);this.counter=this.counter?++this.counter:1;var f=this,g=this.counter;window.setTimeout(function(){g==
|
||||
f.counter&&f.refreshPositions(!e)},0)},_clear:function(a,b){this.reverting=false;var c=[];!this._noFinalSort&&this.currentItem[0].parentNode&&this.placeholder.before(this.currentItem);this._noFinalSort=null;if(this.helper[0]==this.currentItem[0]){for(var e in this._storedCSS)if(this._storedCSS[e]=="auto"||this._storedCSS[e]=="static")this._storedCSS[e]="";this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")}else this.currentItem.show();this.fromOutside&&!b&&c.push(function(f){this._trigger("receive",
|
||||
f,this._uiHash(this.fromOutside))});if((this.fromOutside||this.domPosition.prev!=this.currentItem.prev().not(".ui-sortable-helper")[0]||this.domPosition.parent!=this.currentItem.parent()[0])&&!b)c.push(function(f){this._trigger("update",f,this._uiHash())});if(!d.ui.contains(this.element[0],this.currentItem[0])){b||c.push(function(f){this._trigger("remove",f,this._uiHash())});for(e=this.containers.length-1;e>=0;e--)if(d.ui.contains(this.containers[e].element[0],this.currentItem[0])&&!b){c.push(function(f){return function(g){f._trigger("receive",
|
||||
g,this._uiHash(this))}}.call(this,this.containers[e]));c.push(function(f){return function(g){f._trigger("update",g,this._uiHash(this))}}.call(this,this.containers[e]))}}for(e=this.containers.length-1;e>=0;e--){b||c.push(function(f){return function(g){f._trigger("deactivate",g,this._uiHash(this))}}.call(this,this.containers[e]));if(this.containers[e].containerCache.over){c.push(function(f){return function(g){f._trigger("out",g,this._uiHash(this))}}.call(this,this.containers[e]));this.containers[e].containerCache.over=
|
||||
0}}this._storedCursor&&d("body").css("cursor",this._storedCursor);this._storedOpacity&&this.helper.css("opacity",this._storedOpacity);if(this._storedZIndex)this.helper.css("zIndex",this._storedZIndex=="auto"?"":this._storedZIndex);this.dragging=false;if(this.cancelHelperRemoval){if(!b){this._trigger("beforeStop",a,this._uiHash());for(e=0;e<c.length;e++)c[e].call(this,a);this._trigger("stop",a,this._uiHash())}return false}b||this._trigger("beforeStop",a,this._uiHash());this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
|
||||
this.helper[0]!=this.currentItem[0]&&this.helper.remove();this.helper=null;if(!b){for(e=0;e<c.length;e++)c[e].call(this,a);this._trigger("stop",a,this._uiHash())}this.fromOutside=false;return true},_trigger:function(){d.Widget.prototype._trigger.apply(this,arguments)===false&&this.cancel()},_uiHash:function(a){var b=a||this;return{helper:b.helper,placeholder:b.placeholder||d([]),position:b.position,originalPosition:b.originalPosition,offset:b.positionAbs,item:b.currentItem,sender:a?a.element:null}}});
|
||||
d.extend(d.ui.sortable,{version:"1.8.5"})})(jQuery);
|
||||
jQuery.effects||function(f,j){function l(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10)];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],
|
||||
16),parseInt(a[2],16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];if(/rgba\(0, 0, 0, 0\)/.exec(c))return m.transparent;return m[f.trim(c).toLowerCase()]}function r(c,a){var b;do{b=f.curCSS(c,a);if(b!=""&&b!="transparent"||f.nodeName(c,"body"))break;a="backgroundColor"}while(c=c.parentNode);return l(b)}function n(){var c=document.defaultView?document.defaultView.getComputedStyle(this,null):this.currentStyle,
|
||||
a={},b,d;if(c&&c.length&&c[0]&&c[c[0]])for(var e=c.length;e--;){b=c[e];if(typeof c[b]=="string"){d=b.replace(/\-(\w)/g,function(g,h){return h.toUpperCase()});a[d]=c[b]}}else for(b in c)if(typeof c[b]==="string")a[b]=c[b];return a}function o(c){var a,b;for(a in c){b=c[a];if(b==null||f.isFunction(b)||a in s||/scrollbar/.test(a)||!/color/i.test(a)&&isNaN(parseFloat(b)))delete c[a]}return c}function t(c,a){var b={_:0},d;for(d in a)if(c[d]!=a[d])b[d]=a[d];return b}function k(c,a,b,d){if(typeof c=="object"){d=
|
||||
a;b=null;a=c;c=a.effect}if(f.isFunction(a)){d=a;b=null;a={}}if(typeof a=="number"||f.fx.speeds[a]){d=b;b=a;a={}}if(f.isFunction(b)){d=b;b=null}a=a||{};b=b||a.duration;b=f.fx.off?0:typeof b=="number"?b:f.fx.speeds[b]||f.fx.speeds._default;d=d||a.complete;return[c,a,b,d]}f.effects={};f.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(c,a){f.fx.step[a]=function(b){if(!b.colorInit){b.start=r(b.elem,a);b.end=l(b.end);b.colorInit=
|
||||
true}b.elem.style[a]="rgb("+Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2],10),255),0)+")"}});var m={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,
|
||||
183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,
|
||||
165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]},p=["add","remove","toggle"],s={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};f.effects.animateClass=function(c,a,b,d){if(f.isFunction(b)){d=b;b=null}return this.each(function(){var e=f(this),g=e.attr("style")||" ",h=o(n.call(this)),q,u=e.attr("className");f.each(p,function(v,
|
||||
i){c[i]&&e[i+"Class"](c[i])});q=o(n.call(this));e.attr("className",u);e.animate(t(h,q),a,b,function(){f.each(p,function(v,i){c[i]&&e[i+"Class"](c[i])});if(typeof e.attr("style")=="object"){e.attr("style").cssText="";e.attr("style").cssText=g}else e.attr("style",g);d&&d.apply(this,arguments)})})};f.fn.extend({_addClass:f.fn.addClass,addClass:function(c,a,b,d){return a?f.effects.animateClass.apply(this,[{add:c},a,b,d]):this._addClass(c)},_removeClass:f.fn.removeClass,removeClass:function(c,a,b,d){return a?
|
||||
f.effects.animateClass.apply(this,[{remove:c},a,b,d]):this._removeClass(c)},_toggleClass:f.fn.toggleClass,toggleClass:function(c,a,b,d,e){return typeof a=="boolean"||a===j?b?f.effects.animateClass.apply(this,[a?{add:c}:{remove:c},b,d,e]):this._toggleClass(c,a):f.effects.animateClass.apply(this,[{toggle:c},a,b,d])},switchClass:function(c,a,b,d,e){return f.effects.animateClass.apply(this,[{add:a,remove:c},b,d,e])}});f.extend(f.effects,{version:"1.8.5",save:function(c,a){for(var b=0;b<a.length;b++)a[b]!==
|
||||
null&&c.data("ec.storage."+a[b],c[0].style[a[b]])},restore:function(c,a){for(var b=0;b<a.length;b++)a[b]!==null&&c.css(a[b],c.data("ec.storage."+a[b]))},setMode:function(c,a){if(a=="toggle")a=c.is(":hidden")?"show":"hide";return a},getBaseline:function(c,a){var b;switch(c[0]){case "top":b=0;break;case "middle":b=0.5;break;case "bottom":b=1;break;default:b=c[0]/a.height}switch(c[1]){case "left":c=0;break;case "center":c=0.5;break;case "right":c=1;break;default:c=c[1]/a.width}return{x:c,y:b}},createWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent();
|
||||
var a={width:c.outerWidth(true),height:c.outerHeight(true),"float":c.css("float")},b=f("<div></div>").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0});c.wrap(b);b=c.parent();if(c.css("position")=="static"){b.css({position:"relative"});c.css({position:"relative"})}else{f.extend(a,{position:c.css("position"),zIndex:c.css("z-index")});f.each(["top","left","bottom","right"],function(d,e){a[e]=c.css(e);if(isNaN(parseInt(a[e],10)))a[e]="auto"});
|
||||
c.css({position:"relative",top:0,left:0})}return b.css(a).show()},removeWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent().replaceWith(c);return c},setTransition:function(c,a,b,d){d=d||{};f.each(a,function(e,g){unit=c.cssUnit(g);if(unit[0]>0)d[g]=unit[0]*b+unit[1]});return d}});f.fn.extend({effect:function(c){var a=k.apply(this,arguments);a={options:a[1],duration:a[2],callback:a[3]};var b=f.effects[c];return b&&!f.fx.off?b.call(this,a):this},_show:f.fn.show,show:function(c){if(!c||
|
||||
typeof c=="number"||f.fx.speeds[c]||!f.effects[c])return this._show.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="show";return this.effect.apply(this,a)}},_hide:f.fn.hide,hide:function(c){if(!c||typeof c=="number"||f.fx.speeds[c]||!f.effects[c])return this._hide.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="hide";return this.effect.apply(this,a)}},__toggle:f.fn.toggle,toggle:function(c){if(!c||typeof c=="number"||f.fx.speeds[c]||!f.effects[c]||typeof c==
|
||||
"boolean"||f.isFunction(c))return this.__toggle.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="toggle";return this.effect.apply(this,a)}},cssUnit:function(c){var a=this.css(c),b=[];f.each(["em","px","%","pt"],function(d,e){if(a.indexOf(e)>0)b=[parseFloat(a),e]});return b}});f.easing.jswing=f.easing.swing;f.extend(f.easing,{def:"easeOutQuad",swing:function(c,a,b,d,e){return f.easing[f.easing.def](c,a,b,d,e)},easeInQuad:function(c,a,b,d,e){return d*(a/=e)*a+b},easeOutQuad:function(c,
|
||||
a,b,d,e){return-d*(a/=e)*(a-2)+b},easeInOutQuad:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a+b;return-d/2*(--a*(a-2)-1)+b},easeInCubic:function(c,a,b,d,e){return d*(a/=e)*a*a+b},easeOutCubic:function(c,a,b,d,e){return d*((a=a/e-1)*a*a+1)+b},easeInOutCubic:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a+b;return d/2*((a-=2)*a*a+2)+b},easeInQuart:function(c,a,b,d,e){return d*(a/=e)*a*a*a+b},easeOutQuart:function(c,a,b,d,e){return-d*((a=a/e-1)*a*a*a-1)+b},easeInOutQuart:function(c,a,b,d,e){if((a/=
|
||||
e/2)<1)return d/2*a*a*a*a+b;return-d/2*((a-=2)*a*a*a-2)+b},easeInQuint:function(c,a,b,d,e){return d*(a/=e)*a*a*a*a+b},easeOutQuint:function(c,a,b,d,e){return d*((a=a/e-1)*a*a*a*a+1)+b},easeInOutQuint:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a*a+b;return d/2*((a-=2)*a*a*a*a+2)+b},easeInSine:function(c,a,b,d,e){return-d*Math.cos(a/e*(Math.PI/2))+d+b},easeOutSine:function(c,a,b,d,e){return d*Math.sin(a/e*(Math.PI/2))+b},easeInOutSine:function(c,a,b,d,e){return-d/2*(Math.cos(Math.PI*a/e)-1)+
|
||||
b},easeInExpo:function(c,a,b,d,e){return a==0?b:d*Math.pow(2,10*(a/e-1))+b},easeOutExpo:function(c,a,b,d,e){return a==e?b+d:d*(-Math.pow(2,-10*a/e)+1)+b},easeInOutExpo:function(c,a,b,d,e){if(a==0)return b;if(a==e)return b+d;if((a/=e/2)<1)return d/2*Math.pow(2,10*(a-1))+b;return d/2*(-Math.pow(2,-10*--a)+2)+b},easeInCirc:function(c,a,b,d,e){return-d*(Math.sqrt(1-(a/=e)*a)-1)+b},easeOutCirc:function(c,a,b,d,e){return d*Math.sqrt(1-(a=a/e-1)*a)+b},easeInOutCirc:function(c,a,b,d,e){if((a/=e/2)<1)return-d/
|
||||
2*(Math.sqrt(1-a*a)-1)+b;return d/2*(Math.sqrt(1-(a-=2)*a)+1)+b},easeInElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return-(h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g))+b},easeOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return h*Math.pow(2,-10*
|
||||
a)*Math.sin((a*e-c)*2*Math.PI/g)+d+b},easeInOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e/2)==2)return b+d;g||(g=e*0.3*1.5);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);if(a<1)return-0.5*h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)+b;return h*Math.pow(2,-10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)*0.5+d+b},easeInBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;return d*(a/=e)*a*((g+1)*a-g)+b},easeOutBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;
|
||||
return d*((a=a/e-1)*a*((g+1)*a+g)+1)+b},easeInOutBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;if((a/=e/2)<1)return d/2*a*a*(((g*=1.525)+1)*a-g)+b;return d/2*((a-=2)*a*(((g*=1.525)+1)*a+g)+2)+b},easeInBounce:function(c,a,b,d,e){return d-f.easing.easeOutBounce(c,e-a,0,d,e)+b},easeOutBounce:function(c,a,b,d,e){return(a/=e)<1/2.75?d*7.5625*a*a+b:a<2/2.75?d*(7.5625*(a-=1.5/2.75)*a+0.75)+b:a<2.5/2.75?d*(7.5625*(a-=2.25/2.75)*a+0.9375)+b:d*(7.5625*(a-=2.625/2.75)*a+0.984375)+b},easeInOutBounce:function(c,
|
||||
a,b,d,e){if(a<e/2)return f.easing.easeInBounce(c,a*2,0,d,e)*0.5+b;return f.easing.easeOutBounce(c,a*2-e,0,d,e)*0.5+d*0.5+b}})}(jQuery);
|
||||
(function(b){b.effects.blind=function(c){return this.queue(function(){var a=b(this),g=["position","top","left"],f=b.effects.setMode(a,c.options.mode||"hide"),d=c.options.direction||"vertical";b.effects.save(a,g);a.show();var e=b.effects.createWrapper(a).css({overflow:"hidden"}),h=d=="vertical"?"height":"width";d=d=="vertical"?e.height():e.width();f=="show"&&e.css(h,0);var i={};i[h]=f=="show"?d:0;e.animate(i,c.duration,c.options.easing,function(){f=="hide"&&a.hide();b.effects.restore(a,g);b.effects.removeWrapper(a);
|
||||
c.callback&&c.callback.apply(a[0],arguments);a.dequeue()})})}})(jQuery);
|
||||
(function(e){e.effects.bounce=function(b){return this.queue(function(){var a=e(this),l=["position","top","left"],h=e.effects.setMode(a,b.options.mode||"effect"),d=b.options.direction||"up",c=b.options.distance||20,m=b.options.times||5,i=b.duration||250;/show|hide/.test(h)&&l.push("opacity");e.effects.save(a,l);a.show();e.effects.createWrapper(a);var f=d=="up"||d=="down"?"top":"left";d=d=="up"||d=="left"?"pos":"neg";c=b.options.distance||(f=="top"?a.outerHeight({margin:true})/3:a.outerWidth({margin:true})/
|
||||
3);if(h=="show")a.css("opacity",0).css(f,d=="pos"?-c:c);if(h=="hide")c/=m*2;h!="hide"&&m--;if(h=="show"){var g={opacity:1};g[f]=(d=="pos"?"+=":"-=")+c;a.animate(g,i/2,b.options.easing);c/=2;m--}for(g=0;g<m;g++){var j={},k={};j[f]=(d=="pos"?"-=":"+=")+c;k[f]=(d=="pos"?"+=":"-=")+c;a.animate(j,i/2,b.options.easing).animate(k,i/2,b.options.easing);c=h=="hide"?c*2:c/2}if(h=="hide"){g={opacity:0};g[f]=(d=="pos"?"-=":"+=")+c;a.animate(g,i/2,b.options.easing,function(){a.hide();e.effects.restore(a,l);e.effects.removeWrapper(a);
|
||||
b.callback&&b.callback.apply(this,arguments)})}else{j={};k={};j[f]=(d=="pos"?"-=":"+=")+c;k[f]=(d=="pos"?"+=":"-=")+c;a.animate(j,i/2,b.options.easing).animate(k,i/2,b.options.easing,function(){e.effects.restore(a,l);e.effects.removeWrapper(a);b.callback&&b.callback.apply(this,arguments)})}a.queue("fx",function(){a.dequeue()});a.dequeue()})}})(jQuery);
|
||||
(function(b){b.effects.clip=function(e){return this.queue(function(){var a=b(this),i=["position","top","left","height","width"],f=b.effects.setMode(a,e.options.mode||"hide"),c=e.options.direction||"vertical";b.effects.save(a,i);a.show();var d=b.effects.createWrapper(a).css({overflow:"hidden"});d=a[0].tagName=="IMG"?d:a;var g={size:c=="vertical"?"height":"width",position:c=="vertical"?"top":"left"};c=c=="vertical"?d.height():d.width();if(f=="show"){d.css(g.size,0);d.css(g.position,c/2)}var h={};h[g.size]=
|
||||
f=="show"?c:0;h[g.position]=f=="show"?0:c/2;d.animate(h,{queue:false,duration:e.duration,easing:e.options.easing,complete:function(){f=="hide"&&a.hide();b.effects.restore(a,i);b.effects.removeWrapper(a);e.callback&&e.callback.apply(a[0],arguments);a.dequeue()}})})}})(jQuery);
|
||||
(function(c){c.effects.drop=function(d){return this.queue(function(){var a=c(this),h=["position","top","left","opacity"],e=c.effects.setMode(a,d.options.mode||"hide"),b=d.options.direction||"left";c.effects.save(a,h);a.show();c.effects.createWrapper(a);var f=b=="up"||b=="down"?"top":"left";b=b=="up"||b=="left"?"pos":"neg";var g=d.options.distance||(f=="top"?a.outerHeight({margin:true})/2:a.outerWidth({margin:true})/2);if(e=="show")a.css("opacity",0).css(f,b=="pos"?-g:g);var i={opacity:e=="show"?1:
|
||||
0};i[f]=(e=="show"?b=="pos"?"+=":"-=":b=="pos"?"-=":"+=")+g;a.animate(i,{queue:false,duration:d.duration,easing:d.options.easing,complete:function(){e=="hide"&&a.hide();c.effects.restore(a,h);c.effects.removeWrapper(a);d.callback&&d.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
|
||||
(function(j){j.effects.explode=function(a){return this.queue(function(){var c=a.options.pieces?Math.round(Math.sqrt(a.options.pieces)):3,d=a.options.pieces?Math.round(Math.sqrt(a.options.pieces)):3;a.options.mode=a.options.mode=="toggle"?j(this).is(":visible")?"hide":"show":a.options.mode;var b=j(this).show().css("visibility","hidden"),g=b.offset();g.top-=parseInt(b.css("marginTop"),10)||0;g.left-=parseInt(b.css("marginLeft"),10)||0;for(var h=b.outerWidth(true),i=b.outerHeight(true),e=0;e<c;e++)for(var f=
|
||||
0;f<d;f++)b.clone().appendTo("body").wrap("<div></div>").css({position:"absolute",visibility:"visible",left:-f*(h/d),top:-e*(i/c)}).parent().addClass("ui-effects-explode").css({position:"absolute",overflow:"hidden",width:h/d,height:i/c,left:g.left+f*(h/d)+(a.options.mode=="show"?(f-Math.floor(d/2))*(h/d):0),top:g.top+e*(i/c)+(a.options.mode=="show"?(e-Math.floor(c/2))*(i/c):0),opacity:a.options.mode=="show"?0:1}).animate({left:g.left+f*(h/d)+(a.options.mode=="show"?0:(f-Math.floor(d/2))*(h/d)),top:g.top+
|
||||
e*(i/c)+(a.options.mode=="show"?0:(e-Math.floor(c/2))*(i/c)),opacity:a.options.mode=="show"?1:0},a.duration||500);setTimeout(function(){a.options.mode=="show"?b.css({visibility:"visible"}):b.css({visibility:"visible"}).hide();a.callback&&a.callback.apply(b[0]);b.dequeue();j("div.ui-effects-explode").remove()},a.duration||500)})}})(jQuery);
|
||||
(function(b){b.effects.fade=function(a){return this.queue(function(){var c=b(this),d=b.effects.setMode(c,a.options.mode||"hide");c.animate({opacity:d},{queue:false,duration:a.duration,easing:a.options.easing,complete:function(){a.callback&&a.callback.apply(this,arguments);c.dequeue()}})})}})(jQuery);
|
||||
(function(c){c.effects.fold=function(a){return this.queue(function(){var b=c(this),j=["position","top","left"],d=c.effects.setMode(b,a.options.mode||"hide"),g=a.options.size||15,h=!!a.options.horizFirst,k=a.duration?a.duration/2:c.fx.speeds._default/2;c.effects.save(b,j);b.show();var e=c.effects.createWrapper(b).css({overflow:"hidden"}),f=d=="show"!=h,l=f?["width","height"]:["height","width"];f=f?[e.width(),e.height()]:[e.height(),e.width()];var i=/([0-9]+)%/.exec(g);if(i)g=parseInt(i[1],10)/100*
|
||||
f[d=="hide"?0:1];if(d=="show")e.css(h?{height:0,width:g}:{height:g,width:0});h={};i={};h[l[0]]=d=="show"?f[0]:g;i[l[1]]=d=="show"?f[1]:0;e.animate(h,k,a.options.easing).animate(i,k,a.options.easing,function(){d=="hide"&&b.hide();c.effects.restore(b,j);c.effects.removeWrapper(b);a.callback&&a.callback.apply(b[0],arguments);b.dequeue()})})}})(jQuery);
|
||||
(function(b){b.effects.highlight=function(c){return this.queue(function(){var a=b(this),e=["backgroundImage","backgroundColor","opacity"],d=b.effects.setMode(a,c.options.mode||"show"),f={backgroundColor:a.css("backgroundColor")};if(d=="hide")f.opacity=0;b.effects.save(a,e);a.show().css({backgroundImage:"none",backgroundColor:c.options.color||"#ffff99"}).animate(f,{queue:false,duration:c.duration,easing:c.options.easing,complete:function(){d=="hide"&&a.hide();b.effects.restore(a,e);d=="show"&&!b.support.opacity&&
|
||||
this.style.removeAttribute("filter");c.callback&&c.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
|
||||
(function(d){d.effects.pulsate=function(a){return this.queue(function(){var b=d(this),c=d.effects.setMode(b,a.options.mode||"show");times=(a.options.times||5)*2-1;duration=a.duration?a.duration/2:d.fx.speeds._default/2;isVisible=b.is(":visible");animateTo=0;if(!isVisible){b.css("opacity",0).show();animateTo=1}if(c=="hide"&&isVisible||c=="show"&&!isVisible)times--;for(c=0;c<times;c++){b.animate({opacity:animateTo},duration,a.options.easing);animateTo=(animateTo+1)%2}b.animate({opacity:animateTo},duration,
|
||||
a.options.easing,function(){animateTo==0&&b.hide();a.callback&&a.callback.apply(this,arguments)});b.queue("fx",function(){b.dequeue()}).dequeue()})}})(jQuery);
|
||||
(function(c){c.effects.puff=function(b){return this.queue(function(){var a=c(this),e=c.effects.setMode(a,b.options.mode||"hide"),g=parseInt(b.options.percent,10)||150,h=g/100,i={height:a.height(),width:a.width()};c.extend(b.options,{fade:true,mode:e,percent:e=="hide"?g:100,from:e=="hide"?i:{height:i.height*h,width:i.width*h}});a.effect("scale",b.options,b.duration,b.callback);a.dequeue()})};c.effects.scale=function(b){return this.queue(function(){var a=c(this),e=c.extend(true,{},b.options),g=c.effects.setMode(a,
|
||||
b.options.mode||"effect"),h=parseInt(b.options.percent,10)||(parseInt(b.options.percent,10)==0?0:g=="hide"?0:100),i=b.options.direction||"both",f=b.options.origin;if(g!="effect"){e.origin=f||["middle","center"];e.restore=true}f={height:a.height(),width:a.width()};a.from=b.options.from||(g=="show"?{height:0,width:0}:f);h={y:i!="horizontal"?h/100:1,x:i!="vertical"?h/100:1};a.to={height:f.height*h.y,width:f.width*h.x};if(b.options.fade){if(g=="show"){a.from.opacity=0;a.to.opacity=1}if(g=="hide"){a.from.opacity=
|
||||
1;a.to.opacity=0}}e.from=a.from;e.to=a.to;e.mode=g;a.effect("size",e,b.duration,b.callback);a.dequeue()})};c.effects.size=function(b){return this.queue(function(){var a=c(this),e=["position","top","left","width","height","overflow","opacity"],g=["position","top","left","overflow","opacity"],h=["width","height","overflow"],i=["fontSize"],f=["borderTopWidth","borderBottomWidth","paddingTop","paddingBottom"],k=["borderLeftWidth","borderRightWidth","paddingLeft","paddingRight"],p=c.effects.setMode(a,
|
||||
b.options.mode||"effect"),n=b.options.restore||false,m=b.options.scale||"both",l=b.options.origin,j={height:a.height(),width:a.width()};a.from=b.options.from||j;a.to=b.options.to||j;if(l){l=c.effects.getBaseline(l,j);a.from.top=(j.height-a.from.height)*l.y;a.from.left=(j.width-a.from.width)*l.x;a.to.top=(j.height-a.to.height)*l.y;a.to.left=(j.width-a.to.width)*l.x}var d={from:{y:a.from.height/j.height,x:a.from.width/j.width},to:{y:a.to.height/j.height,x:a.to.width/j.width}};if(m=="box"||m=="both"){if(d.from.y!=
|
||||
d.to.y){e=e.concat(f);a.from=c.effects.setTransition(a,f,d.from.y,a.from);a.to=c.effects.setTransition(a,f,d.to.y,a.to)}if(d.from.x!=d.to.x){e=e.concat(k);a.from=c.effects.setTransition(a,k,d.from.x,a.from);a.to=c.effects.setTransition(a,k,d.to.x,a.to)}}if(m=="content"||m=="both")if(d.from.y!=d.to.y){e=e.concat(i);a.from=c.effects.setTransition(a,i,d.from.y,a.from);a.to=c.effects.setTransition(a,i,d.to.y,a.to)}c.effects.save(a,n?e:g);a.show();c.effects.createWrapper(a);a.css("overflow","hidden").css(a.from);
|
||||
if(m=="content"||m=="both"){f=f.concat(["marginTop","marginBottom"]).concat(i);k=k.concat(["marginLeft","marginRight"]);h=e.concat(f).concat(k);a.find("*[width]").each(function(){child=c(this);n&&c.effects.save(child,h);var o={height:child.height(),width:child.width()};child.from={height:o.height*d.from.y,width:o.width*d.from.x};child.to={height:o.height*d.to.y,width:o.width*d.to.x};if(d.from.y!=d.to.y){child.from=c.effects.setTransition(child,f,d.from.y,child.from);child.to=c.effects.setTransition(child,
|
||||
f,d.to.y,child.to)}if(d.from.x!=d.to.x){child.from=c.effects.setTransition(child,k,d.from.x,child.from);child.to=c.effects.setTransition(child,k,d.to.x,child.to)}child.css(child.from);child.animate(child.to,b.duration,b.options.easing,function(){n&&c.effects.restore(child,h)})})}a.animate(a.to,{queue:false,duration:b.duration,easing:b.options.easing,complete:function(){a.to.opacity===0&&a.css("opacity",a.from.opacity);p=="hide"&&a.hide();c.effects.restore(a,n?e:g);c.effects.removeWrapper(a);b.callback&&
|
||||
b.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
|
||||
(function(d){d.effects.shake=function(a){return this.queue(function(){var b=d(this),j=["position","top","left"];d.effects.setMode(b,a.options.mode||"effect");var c=a.options.direction||"left",e=a.options.distance||20,l=a.options.times||3,f=a.duration||a.options.duration||140;d.effects.save(b,j);b.show();d.effects.createWrapper(b);var g=c=="up"||c=="down"?"top":"left",h=c=="up"||c=="left"?"pos":"neg";c={};var i={},k={};c[g]=(h=="pos"?"-=":"+=")+e;i[g]=(h=="pos"?"+=":"-=")+e*2;k[g]=(h=="pos"?"-=":"+=")+
|
||||
e*2;b.animate(c,f,a.options.easing);for(e=1;e<l;e++)b.animate(i,f,a.options.easing).animate(k,f,a.options.easing);b.animate(i,f,a.options.easing).animate(c,f/2,a.options.easing,function(){d.effects.restore(b,j);d.effects.removeWrapper(b);a.callback&&a.callback.apply(this,arguments)});b.queue("fx",function(){b.dequeue()});b.dequeue()})}})(jQuery);
|
||||
(function(c){c.effects.slide=function(d){return this.queue(function(){var a=c(this),h=["position","top","left"],e=c.effects.setMode(a,d.options.mode||"show"),b=d.options.direction||"left";c.effects.save(a,h);a.show();c.effects.createWrapper(a).css({overflow:"hidden"});var f=b=="up"||b=="down"?"top":"left";b=b=="up"||b=="left"?"pos":"neg";var g=d.options.distance||(f=="top"?a.outerHeight({margin:true}):a.outerWidth({margin:true}));if(e=="show")a.css(f,b=="pos"?-g:g);var i={};i[f]=(e=="show"?b=="pos"?
|
||||
"+=":"-=":b=="pos"?"-=":"+=")+g;a.animate(i,{queue:false,duration:d.duration,easing:d.options.easing,complete:function(){e=="hide"&&a.hide();c.effects.restore(a,h);c.effects.removeWrapper(a);d.callback&&d.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
|
||||
(function(e){e.effects.transfer=function(a){return this.queue(function(){var b=e(this),c=e(a.options.to),d=c.offset();c={top:d.top,left:d.left,height:c.innerHeight(),width:c.innerWidth()};d=b.offset();var f=e('<div class="ui-effects-transfer"></div>').appendTo(document.body).addClass(a.options.className).css({top:d.top,left:d.left,height:b.innerHeight(),width:b.innerWidth(),position:"absolute"}).animate(c,a.duration,a.options.easing,function(){f.remove();a.callback&&a.callback.apply(b[0],arguments);
|
||||
b.dequeue()})})}})(jQuery);
|
||||
(function(c){c.widget("ui.accordion",{options:{active:0,animated:"slide",autoHeight:true,clearStyle:false,collapsible:false,event:"click",fillSpace:false,header:"> li > :first-child,> :not(li):even",icons:{header:"ui-icon-triangle-1-e",headerSelected:"ui-icon-triangle-1-s"},navigation:false,navigationFilter:function(){return this.href.toLowerCase()===location.href.toLowerCase()}},_create:function(){var a=this,b=a.options;a.running=0;a.element.addClass("ui-accordion ui-widget ui-helper-reset").children("li").addClass("ui-accordion-li-fix");
|
||||
a.headers=a.element.find(b.header).addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all").bind("mouseenter.accordion",function(){b.disabled||c(this).addClass("ui-state-hover")}).bind("mouseleave.accordion",function(){b.disabled||c(this).removeClass("ui-state-hover")}).bind("focus.accordion",function(){b.disabled||c(this).addClass("ui-state-focus")}).bind("blur.accordion",function(){b.disabled||c(this).removeClass("ui-state-focus")});a.headers.next().addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom");
|
||||
if(b.navigation){var d=a.element.find("a").filter(b.navigationFilter).eq(0);if(d.length){var f=d.closest(".ui-accordion-header");a.active=f.length?f:d.closest(".ui-accordion-content").prev()}}a.active=a._findActive(a.active||b.active).addClass("ui-state-default ui-state-active").toggleClass("ui-corner-all ui-corner-top");a.active.next().addClass("ui-accordion-content-active");a._createIcons();a.resize();a.element.attr("role","tablist");a.headers.attr("role","tab").bind("keydown.accordion",function(g){return a._keydown(g)}).next().attr("role",
|
||||
"tabpanel");a.headers.not(a.active||"").attr({"aria-expanded":"false",tabIndex:-1}).next().hide();a.active.length?a.active.attr({"aria-expanded":"true",tabIndex:0}):a.headers.eq(0).attr("tabIndex",0);c.browser.safari||a.headers.find("a").attr("tabIndex",-1);b.event&&a.headers.bind(b.event.split(" ").join(".accordion ")+".accordion",function(g){a._clickHandler.call(a,g,this);g.preventDefault()})},_createIcons:function(){var a=this.options;if(a.icons){c("<span></span>").addClass("ui-icon "+a.icons.header).prependTo(this.headers);
|
||||
this.active.children(".ui-icon").toggleClass(a.icons.header).toggleClass(a.icons.headerSelected);this.element.addClass("ui-accordion-icons")}},_destroyIcons:function(){this.headers.children(".ui-icon").remove();this.element.removeClass("ui-accordion-icons")},destroy:function(){var a=this.options;this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role");this.headers.unbind(".accordion").removeClass("ui-accordion-header ui-accordion-disabled ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-state-disabled ui-corner-top").removeAttr("role").removeAttr("aria-expanded").removeAttr("tabIndex");
|
||||
this.headers.find("a").removeAttr("tabIndex");this._destroyIcons();var b=this.headers.next().css("display","").removeAttr("role").removeClass("ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-accordion-disabled ui-state-disabled");if(a.autoHeight||a.fillHeight)b.css("height","");return c.Widget.prototype.destroy.call(this)},_setOption:function(a,b){c.Widget.prototype._setOption.apply(this,arguments);a=="active"&&this.activate(b);if(a=="icons"){this._destroyIcons();
|
||||
b&&this._createIcons()}if(a=="disabled")this.headers.add(this.headers.next())[b?"addClass":"removeClass"]("ui-accordion-disabled ui-state-disabled")},_keydown:function(a){if(!(this.options.disabled||a.altKey||a.ctrlKey)){var b=c.ui.keyCode,d=this.headers.length,f=this.headers.index(a.target),g=false;switch(a.keyCode){case b.RIGHT:case b.DOWN:g=this.headers[(f+1)%d];break;case b.LEFT:case b.UP:g=this.headers[(f-1+d)%d];break;case b.SPACE:case b.ENTER:this._clickHandler({target:a.target},a.target);
|
||||
a.preventDefault()}if(g){c(a.target).attr("tabIndex",-1);c(g).attr("tabIndex",0);g.focus();return false}return true}},resize:function(){var a=this.options,b;if(a.fillSpace){if(c.browser.msie){var d=this.element.parent().css("overflow");this.element.parent().css("overflow","hidden")}b=this.element.parent().height();c.browser.msie&&this.element.parent().css("overflow",d);this.headers.each(function(){b-=c(this).outerHeight(true)});this.headers.next().each(function(){c(this).height(Math.max(0,b-c(this).innerHeight()+
|
||||
c(this).height()))}).css("overflow","auto")}else if(a.autoHeight){b=0;this.headers.next().each(function(){b=Math.max(b,c(this).height("").height())}).height(b)}return this},activate:function(a){this.options.active=a;a=this._findActive(a)[0];this._clickHandler({target:a},a);return this},_findActive:function(a){return a?typeof a==="number"?this.headers.filter(":eq("+a+")"):this.headers.not(this.headers.not(a)):a===false?c([]):this.headers.filter(":eq(0)")},_clickHandler:function(a,b){var d=this.options;
|
||||
if(!d.disabled)if(a.target){a=c(a.currentTarget||b);b=a[0]===this.active[0];d.active=d.collapsible&&b?false:this.headers.index(a);if(!(this.running||!d.collapsible&&b)){this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all").children(".ui-icon").removeClass(d.icons.headerSelected).addClass(d.icons.header);if(!b){a.removeClass("ui-state-default ui-corner-all").addClass("ui-state-active ui-corner-top").children(".ui-icon").removeClass(d.icons.header).addClass(d.icons.headerSelected);
|
||||
a.next().addClass("ui-accordion-content-active")}h=a.next();f=this.active.next();g={options:d,newHeader:b&&d.collapsible?c([]):a,oldHeader:this.active,newContent:b&&d.collapsible?c([]):h,oldContent:f};d=this.headers.index(this.active[0])>this.headers.index(a[0]);this.active=b?c([]):a;this._toggle(h,f,g,b,d)}}else if(d.collapsible){this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all").children(".ui-icon").removeClass(d.icons.headerSelected).addClass(d.icons.header);
|
||||
this.active.next().addClass("ui-accordion-content-active");var f=this.active.next(),g={options:d,newHeader:c([]),oldHeader:d.active,newContent:c([]),oldContent:f},h=this.active=c([]);this._toggle(h,f,g)}},_toggle:function(a,b,d,f,g){var h=this,e=h.options;h.toShow=a;h.toHide=b;h.data=d;var j=function(){if(h)return h._completed.apply(h,arguments)};h._trigger("changestart",null,h.data);h.running=b.size()===0?a.size():b.size();if(e.animated){d={};d=e.collapsible&&f?{toShow:c([]),toHide:b,complete:j,
|
||||
down:g,autoHeight:e.autoHeight||e.fillSpace}:{toShow:a,toHide:b,complete:j,down:g,autoHeight:e.autoHeight||e.fillSpace};if(!e.proxied)e.proxied=e.animated;if(!e.proxiedDuration)e.proxiedDuration=e.duration;e.animated=c.isFunction(e.proxied)?e.proxied(d):e.proxied;e.duration=c.isFunction(e.proxiedDuration)?e.proxiedDuration(d):e.proxiedDuration;f=c.ui.accordion.animations;var i=e.duration,k=e.animated;if(k&&!f[k]&&!c.easing[k])k="slide";f[k]||(f[k]=function(l){this.slide(l,{easing:k,duration:i||700})});
|
||||
f[k](d)}else{if(e.collapsible&&f)a.toggle();else{b.hide();a.show()}j(true)}b.prev().attr({"aria-expanded":"false",tabIndex:-1}).blur();a.prev().attr({"aria-expanded":"true",tabIndex:0}).focus()},_completed:function(a){this.running=a?0:--this.running;if(!this.running){this.options.clearStyle&&this.toShow.add(this.toHide).css({height:"",overflow:""});this.toHide.removeClass("ui-accordion-content-active");this._trigger("change",null,this.data)}}});c.extend(c.ui.accordion,{version:"1.8.5",animations:{slide:function(a,
|
||||
b){a=c.extend({easing:"swing",duration:300},a,b);if(a.toHide.size())if(a.toShow.size()){var d=a.toShow.css("overflow"),f=0,g={},h={},e;b=a.toShow;e=b[0].style.width;b.width(parseInt(b.parent().width(),10)-parseInt(b.css("paddingLeft"),10)-parseInt(b.css("paddingRight"),10)-(parseInt(b.css("borderLeftWidth"),10)||0)-(parseInt(b.css("borderRightWidth"),10)||0));c.each(["height","paddingTop","paddingBottom"],function(j,i){h[i]="hide";j=(""+c.css(a.toShow[0],i)).match(/^([\d+-.]+)(.*)$/);g[i]={value:j[1],
|
||||
unit:j[2]||"px"}});a.toShow.css({height:0,overflow:"hidden"}).show();a.toHide.filter(":hidden").each(a.complete).end().filter(":visible").animate(h,{step:function(j,i){if(i.prop=="height")f=i.end-i.start===0?0:(i.now-i.start)/(i.end-i.start);a.toShow[0].style[i.prop]=f*g[i.prop].value+g[i.prop].unit},duration:a.duration,easing:a.easing,complete:function(){a.autoHeight||a.toShow.css("height","");a.toShow.css({width:e,overflow:d});a.complete()}})}else a.toHide.animate({height:"hide",paddingTop:"hide",
|
||||
paddingBottom:"hide"},a);else a.toShow.animate({height:"show",paddingTop:"show",paddingBottom:"show"},a)},bounceslide:function(a){this.slide(a,{easing:a.down?"easeOutBounce":"swing",duration:a.down?1E3:200})}}})})(jQuery);
|
||||
(function(e){e.widget("ui.autocomplete",{options:{appendTo:"body",delay:300,minLength:1,position:{my:"left top",at:"left bottom",collision:"none"},source:null},_create:function(){var a=this,b=this.element[0].ownerDocument;this.element.addClass("ui-autocomplete-input").attr("autocomplete","off").attr({role:"textbox","aria-autocomplete":"list","aria-haspopup":"true"}).bind("keydown.autocomplete",function(c){if(!a.options.disabled){var d=e.ui.keyCode;switch(c.keyCode){case d.PAGE_UP:a._move("previousPage",
|
||||
c);break;case d.PAGE_DOWN:a._move("nextPage",c);break;case d.UP:a._move("previous",c);c.preventDefault();break;case d.DOWN:a._move("next",c);c.preventDefault();break;case d.ENTER:case d.NUMPAD_ENTER:a.menu.element.is(":visible")&&c.preventDefault();case d.TAB:if(!a.menu.active)return;a.menu.select(c);break;case d.ESCAPE:a.element.val(a.term);a.close(c);break;default:clearTimeout(a.searching);a.searching=setTimeout(function(){if(a.term!=a.element.val()){a.selectedItem=null;a.search(null,c)}},a.options.delay);
|
||||
break}}}).bind("focus.autocomplete",function(){if(!a.options.disabled){a.selectedItem=null;a.previous=a.element.val()}}).bind("blur.autocomplete",function(c){if(!a.options.disabled){clearTimeout(a.searching);a.closing=setTimeout(function(){a.close(c);a._change(c)},150)}});this._initSource();this.response=function(){return a._response.apply(a,arguments)};this.menu=e("<ul></ul>").addClass("ui-autocomplete").appendTo(e(this.options.appendTo||"body",b)[0]).mousedown(function(c){var d=a.menu.element[0];
|
||||
c.target===d&&setTimeout(function(){e(document).one("mousedown",function(f){f.target!==a.element[0]&&f.target!==d&&!e.ui.contains(d,f.target)&&a.close()})},1);setTimeout(function(){clearTimeout(a.closing)},13)}).menu({focus:function(c,d){d=d.item.data("item.autocomplete");false!==a._trigger("focus",null,{item:d})&&/^key/.test(c.originalEvent.type)&&a.element.val(d.value)},selected:function(c,d){d=d.item.data("item.autocomplete");var f=a.previous;if(a.element[0]!==b.activeElement){a.element.focus();
|
||||
a.previous=f}if(false!==a._trigger("select",c,{item:d})){a.term=d.value;a.element.val(d.value)}a.close(c);a.selectedItem=d},blur:function(){a.menu.element.is(":visible")&&a.element.val()!==a.term&&a.element.val(a.term)}}).zIndex(this.element.zIndex()+1).css({top:0,left:0}).hide().data("menu");e.fn.bgiframe&&this.menu.element.bgiframe()},destroy:function(){this.element.removeClass("ui-autocomplete-input").removeAttr("autocomplete").removeAttr("role").removeAttr("aria-autocomplete").removeAttr("aria-haspopup");
|
||||
this.menu.element.remove();e.Widget.prototype.destroy.call(this)},_setOption:function(a,b){e.Widget.prototype._setOption.apply(this,arguments);a==="source"&&this._initSource();if(a==="appendTo")this.menu.element.appendTo(e(b||"body",this.element[0].ownerDocument)[0])},_initSource:function(){var a=this,b,c;if(e.isArray(this.options.source)){b=this.options.source;this.source=function(d,f){f(e.ui.autocomplete.filter(b,d.term))}}else if(typeof this.options.source==="string"){c=this.options.source;this.source=
|
||||
function(d,f){a.xhr&&a.xhr.abort();a.xhr=e.getJSON(c,d,function(g,i,h){h===a.xhr&&f(g);a.xhr=null})}}else this.source=this.options.source},search:function(a,b){a=a!=null?a:this.element.val();this.term=this.element.val();if(a.length<this.options.minLength)return this.close(b);clearTimeout(this.closing);if(this._trigger("search")!==false)return this._search(a)},_search:function(a){this.element.addClass("ui-autocomplete-loading");this.source({term:a},this.response)},_response:function(a){if(a.length){a=
|
||||
this._normalize(a);this._suggest(a);this._trigger("open")}else this.close();this.element.removeClass("ui-autocomplete-loading")},close:function(a){clearTimeout(this.closing);if(this.menu.element.is(":visible")){this._trigger("close",a);this.menu.element.hide();this.menu.deactivate()}},_change:function(a){this.previous!==this.element.val()&&this._trigger("change",a,{item:this.selectedItem})},_normalize:function(a){if(a.length&&a[0].label&&a[0].value)return a;return e.map(a,function(b){if(typeof b===
|
||||
"string")return{label:b,value:b};return e.extend({label:b.label||b.value,value:b.value||b.label},b)})},_suggest:function(a){var b=this.menu.element.empty().zIndex(this.element.zIndex()+1),c;this._renderMenu(b,a);this.menu.deactivate();this.menu.refresh();this.menu.element.show().position(e.extend({of:this.element},this.options.position));a=b.width("").outerWidth();c=this.element.outerWidth();b.outerWidth(Math.max(a,c))},_renderMenu:function(a,b){var c=this;e.each(b,function(d,f){c._renderItem(a,f)})},
|
||||
_renderItem:function(a,b){return e("<li></li>").data("item.autocomplete",b).append(e("<a></a>").text(b.label)).appendTo(a)},_move:function(a,b){if(this.menu.element.is(":visible"))if(this.menu.first()&&/^previous/.test(a)||this.menu.last()&&/^next/.test(a)){this.element.val(this.term);this.menu.deactivate()}else this.menu[a](b);else this.search(null,b)},widget:function(){return this.menu.element}});e.extend(e.ui.autocomplete,{escapeRegex:function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")},
|
||||
filter:function(a,b){var c=new RegExp(e.ui.autocomplete.escapeRegex(b),"i");return e.grep(a,function(d){return c.test(d.label||d.value||d)})}})})(jQuery);
|
||||
(function(e){e.widget("ui.menu",{_create:function(){var a=this;this.element.addClass("ui-menu ui-widget ui-widget-content ui-corner-all").attr({role:"listbox","aria-activedescendant":"ui-active-menuitem"}).click(function(b){if(e(b.target).closest(".ui-menu-item a").length){b.preventDefault();a.select(b)}});this.refresh()},refresh:function(){var a=this;this.element.children("li:not(.ui-menu-item):has(a)").addClass("ui-menu-item").attr("role","menuitem").children("a").addClass("ui-corner-all").attr("tabindex",
|
||||
-1).mouseenter(function(b){a.activate(b,e(this).parent())}).mouseleave(function(){a.deactivate()})},activate:function(a,b){this.deactivate();if(this.hasScroll()){var c=b.offset().top-this.element.offset().top,d=this.element.attr("scrollTop"),f=this.element.height();if(c<0)this.element.attr("scrollTop",d+c);else c>=f&&this.element.attr("scrollTop",d+c-f+b.height())}this.active=b.eq(0).children("a").addClass("ui-state-hover").attr("id","ui-active-menuitem").end();this._trigger("focus",a,{item:b})},
|
||||
deactivate:function(){if(this.active){this.active.children("a").removeClass("ui-state-hover").removeAttr("id");this._trigger("blur");this.active=null}},next:function(a){this.move("next",".ui-menu-item:first",a)},previous:function(a){this.move("prev",".ui-menu-item:last",a)},first:function(){return this.active&&!this.active.prevAll(".ui-menu-item").length},last:function(){return this.active&&!this.active.nextAll(".ui-menu-item").length},move:function(a,b,c){if(this.active){a=this.active[a+"All"](".ui-menu-item").eq(0);
|
||||
a.length?this.activate(c,a):this.activate(c,this.element.children(b))}else this.activate(c,this.element.children(b))},nextPage:function(a){if(this.hasScroll())if(!this.active||this.last())this.activate(a,this.element.children(":first"));else{var b=this.active.offset().top,c=this.element.height(),d=this.element.children("li").filter(function(){var f=e(this).offset().top-b-c+e(this).height();return f<10&&f>-10});d.length||(d=this.element.children(":last"));this.activate(a,d)}else this.activate(a,this.element.children(!this.active||
|
||||
this.last()?":first":":last"))},previousPage:function(a){if(this.hasScroll())if(!this.active||this.first())this.activate(a,this.element.children(":last"));else{var b=this.active.offset().top,c=this.element.height();result=this.element.children("li").filter(function(){var d=e(this).offset().top-b+c-e(this).height();return d<10&&d>-10});result.length||(result=this.element.children(":first"));this.activate(a,result)}else this.activate(a,this.element.children(!this.active||this.first()?":last":":first"))},
|
||||
hasScroll:function(){return this.element.height()<this.element.attr("scrollHeight")},select:function(a){this._trigger("selected",a,{item:this.active})}})})(jQuery);
|
||||
(function(a){var g,i=function(b){a(":ui-button",b.target.form).each(function(){var c=a(this).data("button");setTimeout(function(){c.refresh()},1)})},h=function(b){var c=b.name,d=b.form,e=a([]);if(c)e=d?a(d).find("[name='"+c+"']"):a("[name='"+c+"']",b.ownerDocument).filter(function(){return!this.form});return e};a.widget("ui.button",{options:{disabled:null,text:true,label:null,icons:{primary:null,secondary:null}},_create:function(){this.element.closest("form").unbind("reset.button").bind("reset.button",
|
||||
i);if(typeof this.options.disabled!=="boolean")this.options.disabled=this.element.attr("disabled");this._determineButtonType();this.hasTitle=!!this.buttonElement.attr("title");var b=this,c=this.options,d=this.type==="checkbox"||this.type==="radio",e="ui-state-hover"+(!d?" ui-state-active":"");if(c.label===null)c.label=this.buttonElement.html();if(this.element.is(":disabled"))c.disabled=true;this.buttonElement.addClass("ui-button ui-widget ui-state-default ui-corner-all").attr("role","button").bind("mouseenter.button",
|
||||
function(){if(!c.disabled){a(this).addClass("ui-state-hover");this===g&&a(this).addClass("ui-state-active")}}).bind("mouseleave.button",function(){c.disabled||a(this).removeClass(e)}).bind("focus.button",function(){a(this).addClass("ui-state-focus")}).bind("blur.button",function(){a(this).removeClass("ui-state-focus")});d&&this.element.bind("change.button",function(){b.refresh()});if(this.type==="checkbox")this.buttonElement.bind("click.button",function(){if(c.disabled)return false;a(this).toggleClass("ui-state-active");
|
||||
b.buttonElement.attr("aria-pressed",b.element[0].checked)});else if(this.type==="radio")this.buttonElement.bind("click.button",function(){if(c.disabled)return false;a(this).addClass("ui-state-active");b.buttonElement.attr("aria-pressed",true);var f=b.element[0];h(f).not(f).map(function(){return a(this).button("widget")[0]}).removeClass("ui-state-active").attr("aria-pressed",false)});else{this.buttonElement.bind("mousedown.button",function(){if(c.disabled)return false;a(this).addClass("ui-state-active");
|
||||
g=this;a(document).one("mouseup",function(){g=null})}).bind("mouseup.button",function(){if(c.disabled)return false;a(this).removeClass("ui-state-active")}).bind("keydown.button",function(f){if(c.disabled)return false;if(f.keyCode==a.ui.keyCode.SPACE||f.keyCode==a.ui.keyCode.ENTER)a(this).addClass("ui-state-active")}).bind("keyup.button",function(){a(this).removeClass("ui-state-active")});this.buttonElement.is("a")&&this.buttonElement.keyup(function(f){f.keyCode===a.ui.keyCode.SPACE&&a(this).click()})}this._setOption("disabled",
|
||||
c.disabled)},_determineButtonType:function(){this.type=this.element.is(":checkbox")?"checkbox":this.element.is(":radio")?"radio":this.element.is("input")?"input":"button";if(this.type==="checkbox"||this.type==="radio"){this.buttonElement=this.element.parents().last().find("label[for="+this.element.attr("id")+"]");this.element.addClass("ui-helper-hidden-accessible");var b=this.element.is(":checked");b&&this.buttonElement.addClass("ui-state-active");this.buttonElement.attr("aria-pressed",b)}else this.buttonElement=
|
||||
this.element},widget:function(){return this.buttonElement},destroy:function(){this.element.removeClass("ui-helper-hidden-accessible");this.buttonElement.removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-state-hover ui-state-active ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only").removeAttr("role").removeAttr("aria-pressed").html(this.buttonElement.find(".ui-button-text").html());this.hasTitle||
|
||||
this.buttonElement.removeAttr("title");a.Widget.prototype.destroy.call(this)},_setOption:function(b,c){a.Widget.prototype._setOption.apply(this,arguments);if(b==="disabled")c?this.element.attr("disabled",true):this.element.removeAttr("disabled");this._resetButton()},refresh:function(){var b=this.element.is(":disabled");b!==this.options.disabled&&this._setOption("disabled",b);if(this.type==="radio")h(this.element[0]).each(function(){a(this).is(":checked")?a(this).button("widget").addClass("ui-state-active").attr("aria-pressed",
|
||||
true):a(this).button("widget").removeClass("ui-state-active").attr("aria-pressed",false)});else if(this.type==="checkbox")this.element.is(":checked")?this.buttonElement.addClass("ui-state-active").attr("aria-pressed",true):this.buttonElement.removeClass("ui-state-active").attr("aria-pressed",false)},_resetButton:function(){if(this.type==="input")this.options.label&&this.element.val(this.options.label);else{var b=this.buttonElement.removeClass("ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only"),
|
||||
c=a("<span></span>").addClass("ui-button-text").html(this.options.label).appendTo(b.empty()).text(),d=this.options.icons,e=d.primary&&d.secondary;if(d.primary||d.secondary){b.addClass("ui-button-text-icon"+(e?"s":d.primary?"-primary":"-secondary"));d.primary&&b.prepend("<span class='ui-button-icon-primary ui-icon "+d.primary+"'></span>");d.secondary&&b.append("<span class='ui-button-icon-secondary ui-icon "+d.secondary+"'></span>");if(!this.options.text){b.addClass(e?"ui-button-icons-only":"ui-button-icon-only").removeClass("ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary");
|
||||
this.hasTitle||b.attr("title",c)}}else b.addClass("ui-button-text-only")}}});a.widget("ui.buttonset",{_create:function(){this.element.addClass("ui-buttonset");this._init()},_init:function(){this.refresh()},_setOption:function(b,c){b==="disabled"&&this.buttons.button("option",b,c);a.Widget.prototype._setOption.apply(this,arguments)},refresh:function(){this.buttons=this.element.find(":button, :submit, :reset, :checkbox, :radio, a, :data(button)").filter(":ui-button").button("refresh").end().not(":ui-button").button().end().map(function(){return a(this).button("widget")[0]}).removeClass("ui-corner-all ui-corner-left ui-corner-right").filter(":visible").filter(":first").addClass("ui-corner-left").end().filter(":last").addClass("ui-corner-right").end().end().end()},
|
||||
destroy:function(){this.element.removeClass("ui-buttonset");this.buttons.map(function(){return a(this).button("widget")[0]}).removeClass("ui-corner-left ui-corner-right").end().button("destroy");a.Widget.prototype.destroy.call(this)}})})(jQuery);
|
||||
(function(d,G){function L(){this.debug=false;this._curInst=null;this._keyEvent=false;this._disabledInputs=[];this._inDialog=this._datepickerShowing=false;this._mainDivId="ui-datepicker-div";this._inlineClass="ui-datepicker-inline";this._appendClass="ui-datepicker-append";this._triggerClass="ui-datepicker-trigger";this._dialogClass="ui-datepicker-dialog";this._disableClass="ui-datepicker-disabled";this._unselectableClass="ui-datepicker-unselectable";this._currentClass="ui-datepicker-current-day";this._dayOverClass=
|
||||
"ui-datepicker-days-cell-over";this.regional=[];this.regional[""]={closeText:"Done",prevText:"Prev",nextText:"Next",currentText:"Today",monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su",
|
||||
"Mo","Tu","We","Th","Fr","Sa"],weekHeader:"Wk",dateFormat:"mm/dd/yy",firstDay:0,isRTL:false,showMonthAfterYear:false,yearSuffix:""};this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},defaultDate:null,appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:false,hideIfNoPrevNext:false,navigationAsDateFormat:false,gotoCurrent:false,changeMonth:false,changeYear:false,yearRange:"c-10:c+10",showOtherMonths:false,selectOtherMonths:false,showWeek:false,calculateWeek:this.iso8601Week,shortYearCutoff:"+10",
|
||||
minDate:null,maxDate:null,duration:"fast",beforeShowDay:null,beforeShow:null,onSelect:null,onChangeMonthYear:null,onClose:null,numberOfMonths:1,showCurrentAtPos:0,stepMonths:1,stepBigMonths:12,altField:"",altFormat:"",constrainInput:true,showButtonPanel:false,autoSize:false};d.extend(this._defaults,this.regional[""]);this.dpDiv=d('<div id="'+this._mainDivId+'" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>')}function E(a,b){d.extend(a,
|
||||
b);for(var c in b)if(b[c]==null||b[c]==G)a[c]=b[c];return a}d.extend(d.ui,{datepicker:{version:"1.8.5"}});var y=(new Date).getTime();d.extend(L.prototype,{markerClassName:"hasDatepicker",log:function(){this.debug&&console.log.apply("",arguments)},_widgetDatepicker:function(){return this.dpDiv},setDefaults:function(a){E(this._defaults,a||{});return this},_attachDatepicker:function(a,b){var c=null;for(var e in this._defaults){var f=a.getAttribute("date:"+e);if(f){c=c||{};try{c[e]=eval(f)}catch(h){c[e]=
|
||||
f}}}e=a.nodeName.toLowerCase();f=e=="div"||e=="span";if(!a.id){this.uuid+=1;a.id="dp"+this.uuid}var i=this._newInst(d(a),f);i.settings=d.extend({},b||{},c||{});if(e=="input")this._connectDatepicker(a,i);else f&&this._inlineDatepicker(a,i)},_newInst:function(a,b){return{id:a[0].id.replace(/([^A-Za-z0-9_])/g,"\\\\$1"),input:a,selectedDay:0,selectedMonth:0,selectedYear:0,drawMonth:0,drawYear:0,inline:b,dpDiv:!b?this.dpDiv:d('<div class="'+this._inlineClass+' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>')}},
|
||||
_connectDatepicker:function(a,b){var c=d(a);b.append=d([]);b.trigger=d([]);if(!c.hasClass(this.markerClassName)){this._attachments(c,b);c.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).keyup(this._doKeyUp).bind("setData.datepicker",function(e,f,h){b.settings[f]=h}).bind("getData.datepicker",function(e,f){return this._get(b,f)});this._autoSize(b);d.data(a,"datepicker",b)}},_attachments:function(a,b){var c=this._get(b,"appendText"),e=this._get(b,"isRTL");b.append&&
|
||||
b.append.remove();if(c){b.append=d('<span class="'+this._appendClass+'">'+c+"</span>");a[e?"before":"after"](b.append)}a.unbind("focus",this._showDatepicker);b.trigger&&b.trigger.remove();c=this._get(b,"showOn");if(c=="focus"||c=="both")a.focus(this._showDatepicker);if(c=="button"||c=="both"){c=this._get(b,"buttonText");var f=this._get(b,"buttonImage");b.trigger=d(this._get(b,"buttonImageOnly")?d("<img/>").addClass(this._triggerClass).attr({src:f,alt:c,title:c}):d('<button type="button"></button>').addClass(this._triggerClass).html(f==
|
||||
""?c:d("<img/>").attr({src:f,alt:c,title:c})));a[e?"before":"after"](b.trigger);b.trigger.click(function(){d.datepicker._datepickerShowing&&d.datepicker._lastInput==a[0]?d.datepicker._hideDatepicker():d.datepicker._showDatepicker(a[0]);return false})}},_autoSize:function(a){if(this._get(a,"autoSize")&&!a.inline){var b=new Date(2009,11,20),c=this._get(a,"dateFormat");if(c.match(/[DM]/)){var e=function(f){for(var h=0,i=0,g=0;g<f.length;g++)if(f[g].length>h){h=f[g].length;i=g}return i};b.setMonth(e(this._get(a,
|
||||
c.match(/MM/)?"monthNames":"monthNamesShort")));b.setDate(e(this._get(a,c.match(/DD/)?"dayNames":"dayNamesShort"))+20-b.getDay())}a.input.attr("size",this._formatDate(a,b).length)}},_inlineDatepicker:function(a,b){var c=d(a);if(!c.hasClass(this.markerClassName)){c.addClass(this.markerClassName).append(b.dpDiv).bind("setData.datepicker",function(e,f,h){b.settings[f]=h}).bind("getData.datepicker",function(e,f){return this._get(b,f)});d.data(a,"datepicker",b);this._setDate(b,this._getDefaultDate(b),
|
||||
true);this._updateDatepicker(b);this._updateAlternate(b)}},_dialogDatepicker:function(a,b,c,e,f){a=this._dialogInst;if(!a){this.uuid+=1;this._dialogInput=d('<input type="text" id="'+("dp"+this.uuid)+'" style="position: absolute; top: -100px; width: 0px; z-index: -10;"/>');this._dialogInput.keydown(this._doKeyDown);d("body").append(this._dialogInput);a=this._dialogInst=this._newInst(this._dialogInput,false);a.settings={};d.data(this._dialogInput[0],"datepicker",a)}E(a.settings,e||{});b=b&&b.constructor==
|
||||
Date?this._formatDate(a,b):b;this._dialogInput.val(b);this._pos=f?f.length?f:[f.pageX,f.pageY]:null;if(!this._pos)this._pos=[document.documentElement.clientWidth/2-100+(document.documentElement.scrollLeft||document.body.scrollLeft),document.documentElement.clientHeight/2-150+(document.documentElement.scrollTop||document.body.scrollTop)];this._dialogInput.css("left",this._pos[0]+20+"px").css("top",this._pos[1]+"px");a.settings.onSelect=c;this._inDialog=true;this.dpDiv.addClass(this._dialogClass);this._showDatepicker(this._dialogInput[0]);
|
||||
d.blockUI&&d.blockUI(this.dpDiv);d.data(this._dialogInput[0],"datepicker",a);return this},_destroyDatepicker:function(a){var b=d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=a.nodeName.toLowerCase();d.removeData(a,"datepicker");if(e=="input"){c.append.remove();c.trigger.remove();b.removeClass(this.markerClassName).unbind("focus",this._showDatepicker).unbind("keydown",this._doKeyDown).unbind("keypress",this._doKeyPress).unbind("keyup",this._doKeyUp)}else if(e=="div"||e=="span")b.removeClass(this.markerClassName).empty()}},
|
||||
_enableDatepicker:function(a){var b=d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=a.nodeName.toLowerCase();if(e=="input"){a.disabled=false;c.trigger.filter("button").each(function(){this.disabled=false}).end().filter("img").css({opacity:"1.0",cursor:""})}else if(e=="div"||e=="span")b.children("."+this._inlineClass).children().removeClass("ui-state-disabled");this._disabledInputs=d.map(this._disabledInputs,function(f){return f==a?null:f})}},_disableDatepicker:function(a){var b=
|
||||
d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=a.nodeName.toLowerCase();if(e=="input"){a.disabled=true;c.trigger.filter("button").each(function(){this.disabled=true}).end().filter("img").css({opacity:"0.5",cursor:"default"})}else if(e=="div"||e=="span")b.children("."+this._inlineClass).children().addClass("ui-state-disabled");this._disabledInputs=d.map(this._disabledInputs,function(f){return f==a?null:f});this._disabledInputs[this._disabledInputs.length]=a}},_isDisabledDatepicker:function(a){if(!a)return false;
|
||||
for(var b=0;b<this._disabledInputs.length;b++)if(this._disabledInputs[b]==a)return true;return false},_getInst:function(a){try{return d.data(a,"datepicker")}catch(b){throw"Missing instance data for this datepicker";}},_optionDatepicker:function(a,b,c){var e=this._getInst(a);if(arguments.length==2&&typeof b=="string")return b=="defaults"?d.extend({},d.datepicker._defaults):e?b=="all"?d.extend({},e.settings):this._get(e,b):null;var f=b||{};if(typeof b=="string"){f={};f[b]=c}if(e){this._curInst==e&&
|
||||
this._hideDatepicker();var h=this._getDateDatepicker(a,true);E(e.settings,f);this._attachments(d(a),e);this._autoSize(e);this._setDateDatepicker(a,h);this._updateDatepicker(e)}},_changeDatepicker:function(a,b,c){this._optionDatepicker(a,b,c)},_refreshDatepicker:function(a){(a=this._getInst(a))&&this._updateDatepicker(a)},_setDateDatepicker:function(a,b){if(a=this._getInst(a)){this._setDate(a,b);this._updateDatepicker(a);this._updateAlternate(a)}},_getDateDatepicker:function(a,b){(a=this._getInst(a))&&
|
||||
!a.inline&&this._setDateFromField(a,b);return a?this._getDate(a):null},_doKeyDown:function(a){var b=d.datepicker._getInst(a.target),c=true,e=b.dpDiv.is(".ui-datepicker-rtl");b._keyEvent=true;if(d.datepicker._datepickerShowing)switch(a.keyCode){case 9:d.datepicker._hideDatepicker();c=false;break;case 13:c=d("td."+d.datepicker._dayOverClass,b.dpDiv).add(d("td."+d.datepicker._currentClass,b.dpDiv));c[0]?d.datepicker._selectDay(a.target,b.selectedMonth,b.selectedYear,c[0]):d.datepicker._hideDatepicker();
|
||||
return false;case 27:d.datepicker._hideDatepicker();break;case 33:d.datepicker._adjustDate(a.target,a.ctrlKey?-d.datepicker._get(b,"stepBigMonths"):-d.datepicker._get(b,"stepMonths"),"M");break;case 34:d.datepicker._adjustDate(a.target,a.ctrlKey?+d.datepicker._get(b,"stepBigMonths"):+d.datepicker._get(b,"stepMonths"),"M");break;case 35:if(a.ctrlKey||a.metaKey)d.datepicker._clearDate(a.target);c=a.ctrlKey||a.metaKey;break;case 36:if(a.ctrlKey||a.metaKey)d.datepicker._gotoToday(a.target);c=a.ctrlKey||
|
||||
a.metaKey;break;case 37:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,e?+1:-1,"D");c=a.ctrlKey||a.metaKey;if(a.originalEvent.altKey)d.datepicker._adjustDate(a.target,a.ctrlKey?-d.datepicker._get(b,"stepBigMonths"):-d.datepicker._get(b,"stepMonths"),"M");break;case 38:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,-7,"D");c=a.ctrlKey||a.metaKey;break;case 39:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,e?-1:+1,"D");c=a.ctrlKey||a.metaKey;if(a.originalEvent.altKey)d.datepicker._adjustDate(a.target,
|
||||
a.ctrlKey?+d.datepicker._get(b,"stepBigMonths"):+d.datepicker._get(b,"stepMonths"),"M");break;case 40:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,+7,"D");c=a.ctrlKey||a.metaKey;break;default:c=false}else if(a.keyCode==36&&a.ctrlKey)d.datepicker._showDatepicker(this);else c=false;if(c){a.preventDefault();a.stopPropagation()}},_doKeyPress:function(a){var b=d.datepicker._getInst(a.target);if(d.datepicker._get(b,"constrainInput")){b=d.datepicker._possibleChars(d.datepicker._get(b,"dateFormat"));
|
||||
var c=String.fromCharCode(a.charCode==G?a.keyCode:a.charCode);return a.ctrlKey||c<" "||!b||b.indexOf(c)>-1}},_doKeyUp:function(a){a=d.datepicker._getInst(a.target);if(a.input.val()!=a.lastVal)try{if(d.datepicker.parseDate(d.datepicker._get(a,"dateFormat"),a.input?a.input.val():null,d.datepicker._getFormatConfig(a))){d.datepicker._setDateFromField(a);d.datepicker._updateAlternate(a);d.datepicker._updateDatepicker(a)}}catch(b){d.datepicker.log(b)}return true},_showDatepicker:function(a){a=a.target||
|
||||
a;if(a.nodeName.toLowerCase()!="input")a=d("input",a.parentNode)[0];if(!(d.datepicker._isDisabledDatepicker(a)||d.datepicker._lastInput==a)){var b=d.datepicker._getInst(a);d.datepicker._curInst&&d.datepicker._curInst!=b&&d.datepicker._curInst.dpDiv.stop(true,true);var c=d.datepicker._get(b,"beforeShow");E(b.settings,c?c.apply(a,[a,b]):{});b.lastVal=null;d.datepicker._lastInput=a;d.datepicker._setDateFromField(b);if(d.datepicker._inDialog)a.value="";if(!d.datepicker._pos){d.datepicker._pos=d.datepicker._findPos(a);
|
||||
d.datepicker._pos[1]+=a.offsetHeight}var e=false;d(a).parents().each(function(){e|=d(this).css("position")=="fixed";return!e});if(e&&d.browser.opera){d.datepicker._pos[0]-=document.documentElement.scrollLeft;d.datepicker._pos[1]-=document.documentElement.scrollTop}c={left:d.datepicker._pos[0],top:d.datepicker._pos[1]};d.datepicker._pos=null;b.dpDiv.css({position:"absolute",display:"block",top:"-1000px"});d.datepicker._updateDatepicker(b);c=d.datepicker._checkOffset(b,c,e);b.dpDiv.css({position:d.datepicker._inDialog&&
|
||||
d.blockUI?"static":e?"fixed":"absolute",display:"none",left:c.left+"px",top:c.top+"px"});if(!b.inline){c=d.datepicker._get(b,"showAnim");var f=d.datepicker._get(b,"duration"),h=function(){d.datepicker._datepickerShowing=true;var i=d.datepicker._getBorders(b.dpDiv);b.dpDiv.find("iframe.ui-datepicker-cover").css({left:-i[0],top:-i[1],width:b.dpDiv.outerWidth(),height:b.dpDiv.outerHeight()})};b.dpDiv.zIndex(d(a).zIndex()+1);d.effects&&d.effects[c]?b.dpDiv.show(c,d.datepicker._get(b,"showOptions"),f,
|
||||
h):b.dpDiv[c||"show"](c?f:null,h);if(!c||!f)h();b.input.is(":visible")&&!b.input.is(":disabled")&&b.input.focus();d.datepicker._curInst=b}}},_updateDatepicker:function(a){var b=this,c=d.datepicker._getBorders(a.dpDiv);a.dpDiv.empty().append(this._generateHTML(a)).find("iframe.ui-datepicker-cover").css({left:-c[0],top:-c[1],width:a.dpDiv.outerWidth(),height:a.dpDiv.outerHeight()}).end().find("button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a").bind("mouseout",function(){d(this).removeClass("ui-state-hover");
|
||||
this.className.indexOf("ui-datepicker-prev")!=-1&&d(this).removeClass("ui-datepicker-prev-hover");this.className.indexOf("ui-datepicker-next")!=-1&&d(this).removeClass("ui-datepicker-next-hover")}).bind("mouseover",function(){if(!b._isDisabledDatepicker(a.inline?a.dpDiv.parent()[0]:a.input[0])){d(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");d(this).addClass("ui-state-hover");this.className.indexOf("ui-datepicker-prev")!=-1&&d(this).addClass("ui-datepicker-prev-hover");
|
||||
this.className.indexOf("ui-datepicker-next")!=-1&&d(this).addClass("ui-datepicker-next-hover")}}).end().find("."+this._dayOverClass+" a").trigger("mouseover").end();c=this._getNumberOfMonths(a);var e=c[1];e>1?a.dpDiv.addClass("ui-datepicker-multi-"+e).css("width",17*e+"em"):a.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width("");a.dpDiv[(c[0]!=1||c[1]!=1?"add":"remove")+"Class"]("ui-datepicker-multi");a.dpDiv[(this._get(a,"isRTL")?"add":"remove")+"Class"]("ui-datepicker-rtl");
|
||||
a==d.datepicker._curInst&&d.datepicker._datepickerShowing&&a.input&&a.input.is(":visible")&&!a.input.is(":disabled")&&a.input.focus()},_getBorders:function(a){var b=function(c){return{thin:1,medium:2,thick:3}[c]||c};return[parseFloat(b(a.css("border-left-width"))),parseFloat(b(a.css("border-top-width")))]},_checkOffset:function(a,b,c){var e=a.dpDiv.outerWidth(),f=a.dpDiv.outerHeight(),h=a.input?a.input.outerWidth():0,i=a.input?a.input.outerHeight():0,g=document.documentElement.clientWidth+d(document).scrollLeft(),
|
||||
k=document.documentElement.clientHeight+d(document).scrollTop();b.left-=this._get(a,"isRTL")?e-h:0;b.left-=c&&b.left==a.input.offset().left?d(document).scrollLeft():0;b.top-=c&&b.top==a.input.offset().top+i?d(document).scrollTop():0;b.left-=Math.min(b.left,b.left+e>g&&g>e?Math.abs(b.left+e-g):0);b.top-=Math.min(b.top,b.top+f>k&&k>f?Math.abs(f+i):0);return b},_findPos:function(a){for(var b=this._get(this._getInst(a),"isRTL");a&&(a.type=="hidden"||a.nodeType!=1);)a=a[b?"previousSibling":"nextSibling"];
|
||||
a=d(a).offset();return[a.left,a.top]},_hideDatepicker:function(a){var b=this._curInst;if(!(!b||a&&b!=d.data(a,"datepicker")))if(this._datepickerShowing){a=this._get(b,"showAnim");var c=this._get(b,"duration"),e=function(){d.datepicker._tidyDialog(b);this._curInst=null};d.effects&&d.effects[a]?b.dpDiv.hide(a,d.datepicker._get(b,"showOptions"),c,e):b.dpDiv[a=="slideDown"?"slideUp":a=="fadeIn"?"fadeOut":"hide"](a?c:null,e);a||e();if(a=this._get(b,"onClose"))a.apply(b.input?b.input[0]:null,[b.input?b.input.val():
|
||||
"",b]);this._datepickerShowing=false;this._lastInput=null;if(this._inDialog){this._dialogInput.css({position:"absolute",left:"0",top:"-100px"});if(d.blockUI){d.unblockUI();d("body").append(this.dpDiv)}}this._inDialog=false}},_tidyDialog:function(a){a.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar")},_checkExternalClick:function(a){if(d.datepicker._curInst){a=d(a.target);a[0].id!=d.datepicker._mainDivId&&a.parents("#"+d.datepicker._mainDivId).length==0&&!a.hasClass(d.datepicker.markerClassName)&&
|
||||
!a.hasClass(d.datepicker._triggerClass)&&d.datepicker._datepickerShowing&&!(d.datepicker._inDialog&&d.blockUI)&&d.datepicker._hideDatepicker()}},_adjustDate:function(a,b,c){a=d(a);var e=this._getInst(a[0]);if(!this._isDisabledDatepicker(a[0])){this._adjustInstDate(e,b+(c=="M"?this._get(e,"showCurrentAtPos"):0),c);this._updateDatepicker(e)}},_gotoToday:function(a){a=d(a);var b=this._getInst(a[0]);if(this._get(b,"gotoCurrent")&&b.currentDay){b.selectedDay=b.currentDay;b.drawMonth=b.selectedMonth=b.currentMonth;
|
||||
b.drawYear=b.selectedYear=b.currentYear}else{var c=new Date;b.selectedDay=c.getDate();b.drawMonth=b.selectedMonth=c.getMonth();b.drawYear=b.selectedYear=c.getFullYear()}this._notifyChange(b);this._adjustDate(a)},_selectMonthYear:function(a,b,c){a=d(a);var e=this._getInst(a[0]);e._selectingMonthYear=false;e["selected"+(c=="M"?"Month":"Year")]=e["draw"+(c=="M"?"Month":"Year")]=parseInt(b.options[b.selectedIndex].value,10);this._notifyChange(e);this._adjustDate(a)},_clickMonthYear:function(a){var b=
|
||||
this._getInst(d(a)[0]);b.input&&b._selectingMonthYear&&setTimeout(function(){b.input.focus()},0);b._selectingMonthYear=!b._selectingMonthYear},_selectDay:function(a,b,c,e){var f=d(a);if(!(d(e).hasClass(this._unselectableClass)||this._isDisabledDatepicker(f[0]))){f=this._getInst(f[0]);f.selectedDay=f.currentDay=d("a",e).html();f.selectedMonth=f.currentMonth=b;f.selectedYear=f.currentYear=c;this._selectDate(a,this._formatDate(f,f.currentDay,f.currentMonth,f.currentYear))}},_clearDate:function(a){a=
|
||||
d(a);this._getInst(a[0]);this._selectDate(a,"")},_selectDate:function(a,b){a=this._getInst(d(a)[0]);b=b!=null?b:this._formatDate(a);a.input&&a.input.val(b);this._updateAlternate(a);var c=this._get(a,"onSelect");if(c)c.apply(a.input?a.input[0]:null,[b,a]);else a.input&&a.input.trigger("change");if(a.inline)this._updateDatepicker(a);else{this._hideDatepicker();this._lastInput=a.input[0];typeof a.input[0]!="object"&&a.input.focus();this._lastInput=null}},_updateAlternate:function(a){var b=this._get(a,
|
||||
"altField");if(b){var c=this._get(a,"altFormat")||this._get(a,"dateFormat"),e=this._getDate(a),f=this.formatDate(c,e,this._getFormatConfig(a));d(b).each(function(){d(this).val(f)})}},noWeekends:function(a){a=a.getDay();return[a>0&&a<6,""]},iso8601Week:function(a){a=new Date(a.getTime());a.setDate(a.getDate()+4-(a.getDay()||7));var b=a.getTime();a.setMonth(0);a.setDate(1);return Math.floor(Math.round((b-a)/864E5)/7)+1},parseDate:function(a,b,c){if(a==null||b==null)throw"Invalid arguments";b=typeof b==
|
||||
"object"?b.toString():b+"";if(b=="")return null;for(var e=(c?c.shortYearCutoff:null)||this._defaults.shortYearCutoff,f=(c?c.dayNamesShort:null)||this._defaults.dayNamesShort,h=(c?c.dayNames:null)||this._defaults.dayNames,i=(c?c.monthNamesShort:null)||this._defaults.monthNamesShort,g=(c?c.monthNames:null)||this._defaults.monthNames,k=c=-1,l=-1,u=-1,j=false,o=function(p){(p=z+1<a.length&&a.charAt(z+1)==p)&&z++;return p},m=function(p){o(p);p=new RegExp("^\\d{1,"+(p=="@"?14:p=="!"?20:p=="y"?4:p=="o"?
|
||||
3:2)+"}");p=b.substring(s).match(p);if(!p)throw"Missing number at position "+s;s+=p[0].length;return parseInt(p[0],10)},n=function(p,w,H){p=o(p)?H:w;for(w=0;w<p.length;w++)if(b.substr(s,p[w].length).toLowerCase()==p[w].toLowerCase()){s+=p[w].length;return w+1}throw"Unknown name at position "+s;},r=function(){if(b.charAt(s)!=a.charAt(z))throw"Unexpected literal at position "+s;s++},s=0,z=0;z<a.length;z++)if(j)if(a.charAt(z)=="'"&&!o("'"))j=false;else r();else switch(a.charAt(z)){case "d":l=m("d");
|
||||
break;case "D":n("D",f,h);break;case "o":u=m("o");break;case "m":k=m("m");break;case "M":k=n("M",i,g);break;case "y":c=m("y");break;case "@":var v=new Date(m("@"));c=v.getFullYear();k=v.getMonth()+1;l=v.getDate();break;case "!":v=new Date((m("!")-this._ticksTo1970)/1E4);c=v.getFullYear();k=v.getMonth()+1;l=v.getDate();break;case "'":if(o("'"))r();else j=true;break;default:r()}if(c==-1)c=(new Date).getFullYear();else if(c<100)c+=(new Date).getFullYear()-(new Date).getFullYear()%100+(c<=e?0:-100);if(u>
|
||||
-1){k=1;l=u;do{e=this._getDaysInMonth(c,k-1);if(l<=e)break;k++;l-=e}while(1)}v=this._daylightSavingAdjust(new Date(c,k-1,l));if(v.getFullYear()!=c||v.getMonth()+1!=k||v.getDate()!=l)throw"Invalid date";return v},ATOM:"yy-mm-dd",COOKIE:"D, dd M yy",ISO_8601:"yy-mm-dd",RFC_822:"D, d M y",RFC_850:"DD, dd-M-y",RFC_1036:"D, d M y",RFC_1123:"D, d M yy",RFC_2822:"D, d M yy",RSS:"D, d M y",TICKS:"!",TIMESTAMP:"@",W3C:"yy-mm-dd",_ticksTo1970:(718685+Math.floor(492.5)-Math.floor(19.7)+Math.floor(4.925))*24*
|
||||
60*60*1E7,formatDate:function(a,b,c){if(!b)return"";var e=(c?c.dayNamesShort:null)||this._defaults.dayNamesShort,f=(c?c.dayNames:null)||this._defaults.dayNames,h=(c?c.monthNamesShort:null)||this._defaults.monthNamesShort;c=(c?c.monthNames:null)||this._defaults.monthNames;var i=function(o){(o=j+1<a.length&&a.charAt(j+1)==o)&&j++;return o},g=function(o,m,n){m=""+m;if(i(o))for(;m.length<n;)m="0"+m;return m},k=function(o,m,n,r){return i(o)?r[m]:n[m]},l="",u=false;if(b)for(var j=0;j<a.length;j++)if(u)if(a.charAt(j)==
|
||||
"'"&&!i("'"))u=false;else l+=a.charAt(j);else switch(a.charAt(j)){case "d":l+=g("d",b.getDate(),2);break;case "D":l+=k("D",b.getDay(),e,f);break;case "o":l+=g("o",(b.getTime()-(new Date(b.getFullYear(),0,0)).getTime())/864E5,3);break;case "m":l+=g("m",b.getMonth()+1,2);break;case "M":l+=k("M",b.getMonth(),h,c);break;case "y":l+=i("y")?b.getFullYear():(b.getYear()%100<10?"0":"")+b.getYear()%100;break;case "@":l+=b.getTime();break;case "!":l+=b.getTime()*1E4+this._ticksTo1970;break;case "'":if(i("'"))l+=
|
||||
"'";else u=true;break;default:l+=a.charAt(j)}return l},_possibleChars:function(a){for(var b="",c=false,e=function(h){(h=f+1<a.length&&a.charAt(f+1)==h)&&f++;return h},f=0;f<a.length;f++)if(c)if(a.charAt(f)=="'"&&!e("'"))c=false;else b+=a.charAt(f);else switch(a.charAt(f)){case "d":case "m":case "y":case "@":b+="0123456789";break;case "D":case "M":return null;case "'":if(e("'"))b+="'";else c=true;break;default:b+=a.charAt(f)}return b},_get:function(a,b){return a.settings[b]!==G?a.settings[b]:this._defaults[b]},
|
||||
_setDateFromField:function(a,b){if(a.input.val()!=a.lastVal){var c=this._get(a,"dateFormat"),e=a.lastVal=a.input?a.input.val():null,f,h;f=h=this._getDefaultDate(a);var i=this._getFormatConfig(a);try{f=this.parseDate(c,e,i)||h}catch(g){this.log(g);e=b?"":e}a.selectedDay=f.getDate();a.drawMonth=a.selectedMonth=f.getMonth();a.drawYear=a.selectedYear=f.getFullYear();a.currentDay=e?f.getDate():0;a.currentMonth=e?f.getMonth():0;a.currentYear=e?f.getFullYear():0;this._adjustInstDate(a)}},_getDefaultDate:function(a){return this._restrictMinMax(a,
|
||||
this._determineDate(a,this._get(a,"defaultDate"),new Date))},_determineDate:function(a,b,c){var e=function(h){var i=new Date;i.setDate(i.getDate()+h);return i},f=function(h){try{return d.datepicker.parseDate(d.datepicker._get(a,"dateFormat"),h,d.datepicker._getFormatConfig(a))}catch(i){}var g=(h.toLowerCase().match(/^c/)?d.datepicker._getDate(a):null)||new Date,k=g.getFullYear(),l=g.getMonth();g=g.getDate();for(var u=/([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,j=u.exec(h);j;){switch(j[2]||"d"){case "d":case "D":g+=
|
||||
parseInt(j[1],10);break;case "w":case "W":g+=parseInt(j[1],10)*7;break;case "m":case "M":l+=parseInt(j[1],10);g=Math.min(g,d.datepicker._getDaysInMonth(k,l));break;case "y":case "Y":k+=parseInt(j[1],10);g=Math.min(g,d.datepicker._getDaysInMonth(k,l));break}j=u.exec(h)}return new Date(k,l,g)};if(b=(b=b==null?c:typeof b=="string"?f(b):typeof b=="number"?isNaN(b)?c:e(b):b)&&b.toString()=="Invalid Date"?c:b){b.setHours(0);b.setMinutes(0);b.setSeconds(0);b.setMilliseconds(0)}return this._daylightSavingAdjust(b)},
|
||||
_daylightSavingAdjust:function(a){if(!a)return null;a.setHours(a.getHours()>12?a.getHours()+2:0);return a},_setDate:function(a,b,c){var e=!b,f=a.selectedMonth,h=a.selectedYear;b=this._restrictMinMax(a,this._determineDate(a,b,new Date));a.selectedDay=a.currentDay=b.getDate();a.drawMonth=a.selectedMonth=a.currentMonth=b.getMonth();a.drawYear=a.selectedYear=a.currentYear=b.getFullYear();if((f!=a.selectedMonth||h!=a.selectedYear)&&!c)this._notifyChange(a);this._adjustInstDate(a);if(a.input)a.input.val(e?
|
||||
"":this._formatDate(a))},_getDate:function(a){return!a.currentYear||a.input&&a.input.val()==""?null:this._daylightSavingAdjust(new Date(a.currentYear,a.currentMonth,a.currentDay))},_generateHTML:function(a){var b=new Date;b=this._daylightSavingAdjust(new Date(b.getFullYear(),b.getMonth(),b.getDate()));var c=this._get(a,"isRTL"),e=this._get(a,"showButtonPanel"),f=this._get(a,"hideIfNoPrevNext"),h=this._get(a,"navigationAsDateFormat"),i=this._getNumberOfMonths(a),g=this._get(a,"showCurrentAtPos"),k=
|
||||
this._get(a,"stepMonths"),l=i[0]!=1||i[1]!=1,u=this._daylightSavingAdjust(!a.currentDay?new Date(9999,9,9):new Date(a.currentYear,a.currentMonth,a.currentDay)),j=this._getMinMaxDate(a,"min"),o=this._getMinMaxDate(a,"max");g=a.drawMonth-g;var m=a.drawYear;if(g<0){g+=12;m--}if(o){var n=this._daylightSavingAdjust(new Date(o.getFullYear(),o.getMonth()-i[0]*i[1]+1,o.getDate()));for(n=j&&n<j?j:n;this._daylightSavingAdjust(new Date(m,g,1))>n;){g--;if(g<0){g=11;m--}}}a.drawMonth=g;a.drawYear=m;n=this._get(a,
|
||||
"prevText");n=!h?n:this.formatDate(n,this._daylightSavingAdjust(new Date(m,g-k,1)),this._getFormatConfig(a));n=this._canAdjustMonth(a,-1,m,g)?'<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_'+y+".datepicker._adjustDate('#"+a.id+"', -"+k+", 'M');\" title=\""+n+'"><span class="ui-icon ui-icon-circle-triangle-'+(c?"e":"w")+'">'+n+"</span></a>":f?"":'<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+n+'"><span class="ui-icon ui-icon-circle-triangle-'+(c?"e":"w")+'">'+
|
||||
n+"</span></a>";var r=this._get(a,"nextText");r=!h?r:this.formatDate(r,this._daylightSavingAdjust(new Date(m,g+k,1)),this._getFormatConfig(a));f=this._canAdjustMonth(a,+1,m,g)?'<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_'+y+".datepicker._adjustDate('#"+a.id+"', +"+k+", 'M');\" title=\""+r+'"><span class="ui-icon ui-icon-circle-triangle-'+(c?"w":"e")+'">'+r+"</span></a>":f?"":'<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+r+'"><span class="ui-icon ui-icon-circle-triangle-'+
|
||||
(c?"w":"e")+'">'+r+"</span></a>";k=this._get(a,"currentText");r=this._get(a,"gotoCurrent")&&a.currentDay?u:b;k=!h?k:this.formatDate(k,r,this._getFormatConfig(a));h=!a.inline?'<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_'+y+'.datepicker._hideDatepicker();">'+this._get(a,"closeText")+"</button>":"";e=e?'<div class="ui-datepicker-buttonpane ui-widget-content">'+(c?h:"")+(this._isInRange(a,r)?'<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_'+
|
||||
y+".datepicker._gotoToday('#"+a.id+"');\">"+k+"</button>":"")+(c?"":h)+"</div>":"";h=parseInt(this._get(a,"firstDay"),10);h=isNaN(h)?0:h;k=this._get(a,"showWeek");r=this._get(a,"dayNames");this._get(a,"dayNamesShort");var s=this._get(a,"dayNamesMin"),z=this._get(a,"monthNames"),v=this._get(a,"monthNamesShort"),p=this._get(a,"beforeShowDay"),w=this._get(a,"showOtherMonths"),H=this._get(a,"selectOtherMonths");this._get(a,"calculateWeek");for(var M=this._getDefaultDate(a),I="",C=0;C<i[0];C++){for(var N=
|
||||
"",D=0;D<i[1];D++){var J=this._daylightSavingAdjust(new Date(m,g,a.selectedDay)),t=" ui-corner-all",x="";if(l){x+='<div class="ui-datepicker-group';if(i[1]>1)switch(D){case 0:x+=" ui-datepicker-group-first";t=" ui-corner-"+(c?"right":"left");break;case i[1]-1:x+=" ui-datepicker-group-last";t=" ui-corner-"+(c?"left":"right");break;default:x+=" ui-datepicker-group-middle";t="";break}x+='">'}x+='<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix'+t+'">'+(/all|left/.test(t)&&C==0?c?
|
||||
f:n:"")+(/all|right/.test(t)&&C==0?c?n:f:"")+this._generateMonthYearHeader(a,g,m,j,o,C>0||D>0,z,v)+'</div><table class="ui-datepicker-calendar"><thead><tr>';var A=k?'<th class="ui-datepicker-week-col">'+this._get(a,"weekHeader")+"</th>":"";for(t=0;t<7;t++){var q=(t+h)%7;A+="<th"+((t+h+6)%7>=5?' class="ui-datepicker-week-end"':"")+'><span title="'+r[q]+'">'+s[q]+"</span></th>"}x+=A+"</tr></thead><tbody>";A=this._getDaysInMonth(m,g);if(m==a.selectedYear&&g==a.selectedMonth)a.selectedDay=Math.min(a.selectedDay,
|
||||
A);t=(this._getFirstDayOfMonth(m,g)-h+7)%7;A=l?6:Math.ceil((t+A)/7);q=this._daylightSavingAdjust(new Date(m,g,1-t));for(var O=0;O<A;O++){x+="<tr>";var P=!k?"":'<td class="ui-datepicker-week-col">'+this._get(a,"calculateWeek")(q)+"</td>";for(t=0;t<7;t++){var F=p?p.apply(a.input?a.input[0]:null,[q]):[true,""],B=q.getMonth()!=g,K=B&&!H||!F[0]||j&&q<j||o&&q>o;P+='<td class="'+((t+h+6)%7>=5?" ui-datepicker-week-end":"")+(B?" ui-datepicker-other-month":"")+(q.getTime()==J.getTime()&&g==a.selectedMonth&&
|
||||
a._keyEvent||M.getTime()==q.getTime()&&M.getTime()==J.getTime()?" "+this._dayOverClass:"")+(K?" "+this._unselectableClass+" ui-state-disabled":"")+(B&&!w?"":" "+F[1]+(q.getTime()==u.getTime()?" "+this._currentClass:"")+(q.getTime()==b.getTime()?" ui-datepicker-today":""))+'"'+((!B||w)&&F[2]?' title="'+F[2]+'"':"")+(K?"":' onclick="DP_jQuery_'+y+".datepicker._selectDay('#"+a.id+"',"+q.getMonth()+","+q.getFullYear()+', this);return false;"')+">"+(B&&!w?" ":K?'<span class="ui-state-default">'+q.getDate()+
|
||||
"</span>":'<a class="ui-state-default'+(q.getTime()==b.getTime()?" ui-state-highlight":"")+(q.getTime()==J.getTime()?" ui-state-active":"")+(B?" ui-priority-secondary":"")+'" href="#">'+q.getDate()+"</a>")+"</td>";q.setDate(q.getDate()+1);q=this._daylightSavingAdjust(q)}x+=P+"</tr>"}g++;if(g>11){g=0;m++}x+="</tbody></table>"+(l?"</div>"+(i[0]>0&&D==i[1]-1?'<div class="ui-datepicker-row-break"></div>':""):"");N+=x}I+=N}I+=e+(d.browser.msie&&parseInt(d.browser.version,10)<7&&!a.inline?'<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>':
|
||||
"");a._keyEvent=false;return I},_generateMonthYearHeader:function(a,b,c,e,f,h,i,g){var k=this._get(a,"changeMonth"),l=this._get(a,"changeYear"),u=this._get(a,"showMonthAfterYear"),j='<div class="ui-datepicker-title">',o="";if(h||!k)o+='<span class="ui-datepicker-month">'+i[b]+"</span>";else{i=e&&e.getFullYear()==c;var m=f&&f.getFullYear()==c;o+='<select class="ui-datepicker-month" onchange="DP_jQuery_'+y+".datepicker._selectMonthYear('#"+a.id+"', this, 'M');\" onclick=\"DP_jQuery_"+y+".datepicker._clickMonthYear('#"+
|
||||
a.id+"');\">";for(var n=0;n<12;n++)if((!i||n>=e.getMonth())&&(!m||n<=f.getMonth()))o+='<option value="'+n+'"'+(n==b?' selected="selected"':"")+">"+g[n]+"</option>";o+="</select>"}u||(j+=o+(h||!(k&&l)?" ":""));if(h||!l)j+='<span class="ui-datepicker-year">'+c+"</span>";else{g=this._get(a,"yearRange").split(":");var r=(new Date).getFullYear();i=function(s){s=s.match(/c[+-].*/)?c+parseInt(s.substring(1),10):s.match(/[+-].*/)?r+parseInt(s,10):parseInt(s,10);return isNaN(s)?r:s};b=i(g[0]);g=Math.max(b,
|
||||
i(g[1]||""));b=e?Math.max(b,e.getFullYear()):b;g=f?Math.min(g,f.getFullYear()):g;for(j+='<select class="ui-datepicker-year" onchange="DP_jQuery_'+y+".datepicker._selectMonthYear('#"+a.id+"', this, 'Y');\" onclick=\"DP_jQuery_"+y+".datepicker._clickMonthYear('#"+a.id+"');\">";b<=g;b++)j+='<option value="'+b+'"'+(b==c?' selected="selected"':"")+">"+b+"</option>";j+="</select>"}j+=this._get(a,"yearSuffix");if(u)j+=(h||!(k&&l)?" ":"")+o;j+="</div>";return j},_adjustInstDate:function(a,b,c){var e=
|
||||
a.drawYear+(c=="Y"?b:0),f=a.drawMonth+(c=="M"?b:0);b=Math.min(a.selectedDay,this._getDaysInMonth(e,f))+(c=="D"?b:0);e=this._restrictMinMax(a,this._daylightSavingAdjust(new Date(e,f,b)));a.selectedDay=e.getDate();a.drawMonth=a.selectedMonth=e.getMonth();a.drawYear=a.selectedYear=e.getFullYear();if(c=="M"||c=="Y")this._notifyChange(a)},_restrictMinMax:function(a,b){var c=this._getMinMaxDate(a,"min");a=this._getMinMaxDate(a,"max");b=c&&b<c?c:b;return b=a&&b>a?a:b},_notifyChange:function(a){var b=this._get(a,
|
||||
"onChangeMonthYear");if(b)b.apply(a.input?a.input[0]:null,[a.selectedYear,a.selectedMonth+1,a])},_getNumberOfMonths:function(a){a=this._get(a,"numberOfMonths");return a==null?[1,1]:typeof a=="number"?[1,a]:a},_getMinMaxDate:function(a,b){return this._determineDate(a,this._get(a,b+"Date"),null)},_getDaysInMonth:function(a,b){return 32-(new Date(a,b,32)).getDate()},_getFirstDayOfMonth:function(a,b){return(new Date(a,b,1)).getDay()},_canAdjustMonth:function(a,b,c,e){var f=this._getNumberOfMonths(a);
|
||||
c=this._daylightSavingAdjust(new Date(c,e+(b<0?b:f[0]*f[1]),1));b<0&&c.setDate(this._getDaysInMonth(c.getFullYear(),c.getMonth()));return this._isInRange(a,c)},_isInRange:function(a,b){var c=this._getMinMaxDate(a,"min");a=this._getMinMaxDate(a,"max");return(!c||b.getTime()>=c.getTime())&&(!a||b.getTime()<=a.getTime())},_getFormatConfig:function(a){var b=this._get(a,"shortYearCutoff");b=typeof b!="string"?b:(new Date).getFullYear()%100+parseInt(b,10);return{shortYearCutoff:b,dayNamesShort:this._get(a,
|
||||
"dayNamesShort"),dayNames:this._get(a,"dayNames"),monthNamesShort:this._get(a,"monthNamesShort"),monthNames:this._get(a,"monthNames")}},_formatDate:function(a,b,c,e){if(!b){a.currentDay=a.selectedDay;a.currentMonth=a.selectedMonth;a.currentYear=a.selectedYear}b=b?typeof b=="object"?b:this._daylightSavingAdjust(new Date(e,c,b)):this._daylightSavingAdjust(new Date(a.currentYear,a.currentMonth,a.currentDay));return this.formatDate(this._get(a,"dateFormat"),b,this._getFormatConfig(a))}});d.fn.datepicker=
|
||||
function(a){if(!d.datepicker.initialized){d(document).mousedown(d.datepicker._checkExternalClick).find("body").append(d.datepicker.dpDiv);d.datepicker.initialized=true}var b=Array.prototype.slice.call(arguments,1);if(typeof a=="string"&&(a=="isDisabled"||a=="getDate"||a=="widget"))return d.datepicker["_"+a+"Datepicker"].apply(d.datepicker,[this[0]].concat(b));if(a=="option"&&arguments.length==2&&typeof arguments[1]=="string")return d.datepicker["_"+a+"Datepicker"].apply(d.datepicker,[this[0]].concat(b));
|
||||
return this.each(function(){typeof a=="string"?d.datepicker["_"+a+"Datepicker"].apply(d.datepicker,[this].concat(b)):d.datepicker._attachDatepicker(this,a)})};d.datepicker=new L;d.datepicker.initialized=false;d.datepicker.uuid=(new Date).getTime();d.datepicker.version="1.8.5";window["DP_jQuery_"+y]=d})(jQuery);
|
||||
(function(c,j){c.widget("ui.dialog",{options:{autoOpen:true,buttons:{},closeOnEscape:true,closeText:"close",dialogClass:"",draggable:true,hide:null,height:"auto",maxHeight:false,maxWidth:false,minHeight:150,minWidth:150,modal:false,position:{my:"center",at:"center",of:window,collision:"fit",using:function(a){var b=c(this).css(a).offset().top;b<0&&c(this).css("top",a.top-b)}},resizable:true,show:null,stack:true,title:"",width:300,zIndex:1E3},_create:function(){this.originalTitle=this.element.attr("title");
|
||||
if(typeof this.originalTitle!=="string")this.originalTitle="";this.options.title=this.options.title||this.originalTitle;var a=this,b=a.options,d=b.title||" ",f=c.ui.dialog.getTitleId(a.element),g=(a.uiDialog=c("<div></div>")).appendTo(document.body).hide().addClass("ui-dialog ui-widget ui-widget-content ui-corner-all "+b.dialogClass).css({zIndex:b.zIndex}).attr("tabIndex",-1).css("outline",0).keydown(function(i){if(b.closeOnEscape&&i.keyCode&&i.keyCode===c.ui.keyCode.ESCAPE){a.close(i);i.preventDefault()}}).attr({role:"dialog",
|
||||
"aria-labelledby":f}).mousedown(function(i){a.moveToTop(false,i)});a.element.show().removeAttr("title").addClass("ui-dialog-content ui-widget-content").appendTo(g);var e=(a.uiDialogTitlebar=c("<div></div>")).addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix").prependTo(g),h=c('<a href="#"></a>').addClass("ui-dialog-titlebar-close ui-corner-all").attr("role","button").hover(function(){h.addClass("ui-state-hover")},function(){h.removeClass("ui-state-hover")}).focus(function(){h.addClass("ui-state-focus")}).blur(function(){h.removeClass("ui-state-focus")}).click(function(i){a.close(i);
|
||||
return false}).appendTo(e);(a.uiDialogTitlebarCloseText=c("<span></span>")).addClass("ui-icon ui-icon-closethick").text(b.closeText).appendTo(h);c("<span></span>").addClass("ui-dialog-title").attr("id",f).html(d).prependTo(e);if(c.isFunction(b.beforeclose)&&!c.isFunction(b.beforeClose))b.beforeClose=b.beforeclose;e.find("*").add(e).disableSelection();b.draggable&&c.fn.draggable&&a._makeDraggable();b.resizable&&c.fn.resizable&&a._makeResizable();a._createButtons(b.buttons);a._isOpen=false;c.fn.bgiframe&&
|
||||
g.bgiframe()},_init:function(){this.options.autoOpen&&this.open()},destroy:function(){var a=this;a.overlay&&a.overlay.destroy();a.uiDialog.hide();a.element.unbind(".dialog").removeData("dialog").removeClass("ui-dialog-content ui-widget-content").hide().appendTo("body");a.uiDialog.remove();a.originalTitle&&a.element.attr("title",a.originalTitle);return a},widget:function(){return this.uiDialog},close:function(a){var b=this,d;if(false!==b._trigger("beforeClose",a)){b.overlay&&b.overlay.destroy();b.uiDialog.unbind("keypress.ui-dialog");
|
||||
b._isOpen=false;if(b.options.hide)b.uiDialog.hide(b.options.hide,function(){b._trigger("close",a)});else{b.uiDialog.hide();b._trigger("close",a)}c.ui.dialog.overlay.resize();if(b.options.modal){d=0;c(".ui-dialog").each(function(){if(this!==b.uiDialog[0])d=Math.max(d,c(this).css("z-index"))});c.ui.dialog.maxZ=d}return b}},isOpen:function(){return this._isOpen},moveToTop:function(a,b){var d=this,f=d.options;if(f.modal&&!a||!f.stack&&!f.modal)return d._trigger("focus",b);if(f.zIndex>c.ui.dialog.maxZ)c.ui.dialog.maxZ=
|
||||
f.zIndex;if(d.overlay){c.ui.dialog.maxZ+=1;d.overlay.$el.css("z-index",c.ui.dialog.overlay.maxZ=c.ui.dialog.maxZ)}a={scrollTop:d.element.attr("scrollTop"),scrollLeft:d.element.attr("scrollLeft")};c.ui.dialog.maxZ+=1;d.uiDialog.css("z-index",c.ui.dialog.maxZ);d.element.attr(a);d._trigger("focus",b);return d},open:function(){if(!this._isOpen){var a=this,b=a.options,d=a.uiDialog;a.overlay=b.modal?new c.ui.dialog.overlay(a):null;d.next().length&&d.appendTo("body");a._size();a._position(b.position);d.show(b.show);
|
||||
a.moveToTop(true);b.modal&&d.bind("keypress.ui-dialog",function(f){if(f.keyCode===c.ui.keyCode.TAB){var g=c(":tabbable",this),e=g.filter(":first");g=g.filter(":last");if(f.target===g[0]&&!f.shiftKey){e.focus(1);return false}else if(f.target===e[0]&&f.shiftKey){g.focus(1);return false}}});c(a.element.find(":tabbable").get().concat(d.find(".ui-dialog-buttonpane :tabbable").get().concat(d.get()))).eq(0).focus();a._isOpen=true;a._trigger("open");return a}},_createButtons:function(a){var b=this,d=false,
|
||||
f=c("<div></div>").addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"),g=c("<div></div>").addClass("ui-dialog-buttonset").appendTo(f);b.uiDialog.find(".ui-dialog-buttonpane").remove();typeof a==="object"&&a!==null&&c.each(a,function(){return!(d=true)});if(d){c.each(a,function(e,h){h=c.isFunction(h)?{click:h,text:e}:h;e=c("<button></button>",h).unbind("click").click(function(){h.click.apply(b.element[0],arguments)}).appendTo(g);c.fn.button&&e.button()});f.appendTo(b.uiDialog)}},_makeDraggable:function(){function a(e){return{position:e.position,
|
||||
offset:e.offset}}var b=this,d=b.options,f=c(document),g;b.uiDialog.draggable({cancel:".ui-dialog-content, .ui-dialog-titlebar-close",handle:".ui-dialog-titlebar",containment:"document",start:function(e,h){g=d.height==="auto"?"auto":c(this).height();c(this).height(c(this).height()).addClass("ui-dialog-dragging");b._trigger("dragStart",e,a(h))},drag:function(e,h){b._trigger("drag",e,a(h))},stop:function(e,h){d.position=[h.position.left-f.scrollLeft(),h.position.top-f.scrollTop()];c(this).removeClass("ui-dialog-dragging").height(g);
|
||||
b._trigger("dragStop",e,a(h));c.ui.dialog.overlay.resize()}})},_makeResizable:function(a){function b(e){return{originalPosition:e.originalPosition,originalSize:e.originalSize,position:e.position,size:e.size}}a=a===j?this.options.resizable:a;var d=this,f=d.options,g=d.uiDialog.css("position");a=typeof a==="string"?a:"n,e,s,w,se,sw,ne,nw";d.uiDialog.resizable({cancel:".ui-dialog-content",containment:"document",alsoResize:d.element,maxWidth:f.maxWidth,maxHeight:f.maxHeight,minWidth:f.minWidth,minHeight:d._minHeight(),
|
||||
handles:a,start:function(e,h){c(this).addClass("ui-dialog-resizing");d._trigger("resizeStart",e,b(h))},resize:function(e,h){d._trigger("resize",e,b(h))},stop:function(e,h){c(this).removeClass("ui-dialog-resizing");f.height=c(this).height();f.width=c(this).width();d._trigger("resizeStop",e,b(h));c.ui.dialog.overlay.resize()}}).css("position",g).find(".ui-resizable-se").addClass("ui-icon ui-icon-grip-diagonal-se")},_minHeight:function(){var a=this.options;return a.height==="auto"?a.minHeight:Math.min(a.minHeight,
|
||||
a.height)},_position:function(a){var b=[],d=[0,0],f;if(a){if(typeof a==="string"||typeof a==="object"&&"0"in a){b=a.split?a.split(" "):[a[0],a[1]];if(b.length===1)b[1]=b[0];c.each(["left","top"],function(g,e){if(+b[g]===b[g]){d[g]=b[g];b[g]=e}});a={my:b.join(" "),at:b.join(" "),offset:d.join(" ")}}a=c.extend({},c.ui.dialog.prototype.options.position,a)}else a=c.ui.dialog.prototype.options.position;(f=this.uiDialog.is(":visible"))||this.uiDialog.show();this.uiDialog.css({top:0,left:0}).position(a);
|
||||
f||this.uiDialog.hide()},_setOption:function(a,b){var d=this,f=d.uiDialog,g=f.is(":data(resizable)"),e=false;switch(a){case "beforeclose":a="beforeClose";break;case "buttons":d._createButtons(b);e=true;break;case "closeText":d.uiDialogTitlebarCloseText.text(""+b);break;case "dialogClass":f.removeClass(d.options.dialogClass).addClass("ui-dialog ui-widget ui-widget-content ui-corner-all "+b);break;case "disabled":b?f.addClass("ui-dialog-disabled"):f.removeClass("ui-dialog-disabled");break;case "draggable":b?
|
||||
d._makeDraggable():f.draggable("destroy");break;case "height":e=true;break;case "maxHeight":g&&f.resizable("option","maxHeight",b);e=true;break;case "maxWidth":g&&f.resizable("option","maxWidth",b);e=true;break;case "minHeight":g&&f.resizable("option","minHeight",b);e=true;break;case "minWidth":g&&f.resizable("option","minWidth",b);e=true;break;case "position":d._position(b);break;case "resizable":g&&!b&&f.resizable("destroy");g&&typeof b==="string"&&f.resizable("option","handles",b);!g&&b!==false&&
|
||||
d._makeResizable(b);break;case "title":c(".ui-dialog-title",d.uiDialogTitlebar).html(""+(b||" "));break;case "width":e=true;break}c.Widget.prototype._setOption.apply(d,arguments);e&&d._size()},_size:function(){var a=this.options,b;this.element.css({width:"auto",minHeight:0,height:0});if(a.minWidth>a.width)a.width=a.minWidth;b=this.uiDialog.css({height:"auto",width:a.width}).height();this.element.css(a.height==="auto"?{minHeight:Math.max(a.minHeight-b,0),height:c.support.minHeight?"auto":Math.max(a.minHeight-
|
||||
b,0)}:{minHeight:0,height:Math.max(a.height-b,0)}).show();this.uiDialog.is(":data(resizable)")&&this.uiDialog.resizable("option","minHeight",this._minHeight())}});c.extend(c.ui.dialog,{version:"1.8.5",uuid:0,maxZ:0,getTitleId:function(a){a=a.attr("id");if(!a){this.uuid+=1;a=this.uuid}return"ui-dialog-title-"+a},overlay:function(a){this.$el=c.ui.dialog.overlay.create(a)}});c.extend(c.ui.dialog.overlay,{instances:[],oldInstances:[],maxZ:0,events:c.map("focus,mousedown,mouseup,keydown,keypress,click".split(","),
|
||||
function(a){return a+".dialog-overlay"}).join(" "),create:function(a){if(this.instances.length===0){setTimeout(function(){c.ui.dialog.overlay.instances.length&&c(document).bind(c.ui.dialog.overlay.events,function(d){if(c(d.target).zIndex()<c.ui.dialog.overlay.maxZ)return false})},1);c(document).bind("keydown.dialog-overlay",function(d){if(a.options.closeOnEscape&&d.keyCode&&d.keyCode===c.ui.keyCode.ESCAPE){a.close(d);d.preventDefault()}});c(window).bind("resize.dialog-overlay",c.ui.dialog.overlay.resize)}var b=
|
||||
(this.oldInstances.pop()||c("<div></div>").addClass("ui-widget-overlay")).appendTo(document.body).css({width:this.width(),height:this.height()});c.fn.bgiframe&&b.bgiframe();this.instances.push(b);return b},destroy:function(a){this.oldInstances.push(this.instances.splice(c.inArray(a,this.instances),1)[0]);this.instances.length===0&&c([document,window]).unbind(".dialog-overlay");a.remove();var b=0;c.each(this.instances,function(){b=Math.max(b,this.css("z-index"))});this.maxZ=b},height:function(){var a,
|
||||
b;if(c.browser.msie&&c.browser.version<7){a=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);b=Math.max(document.documentElement.offsetHeight,document.body.offsetHeight);return a<b?c(window).height()+"px":a+"px"}else return c(document).height()+"px"},width:function(){var a,b;if(c.browser.msie&&c.browser.version<7){a=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth);b=Math.max(document.documentElement.offsetWidth,document.body.offsetWidth);return a<
|
||||
b?c(window).width()+"px":a+"px"}else return c(document).width()+"px"},resize:function(){var a=c([]);c.each(c.ui.dialog.overlay.instances,function(){a=a.add(this)});a.css({width:0,height:0}).css({width:c.ui.dialog.overlay.width(),height:c.ui.dialog.overlay.height()})}});c.extend(c.ui.dialog.overlay.prototype,{destroy:function(){c.ui.dialog.overlay.destroy(this.$el)}})})(jQuery);
|
||||
(function(c){c.ui=c.ui||{};var n=/left|center|right/,o=/top|center|bottom/,t=c.fn.position,u=c.fn.offset;c.fn.position=function(b){if(!b||!b.of)return t.apply(this,arguments);b=c.extend({},b);var a=c(b.of),d=a[0],g=(b.collision||"flip").split(" "),e=b.offset?b.offset.split(" "):[0,0],h,k,j;if(d.nodeType===9){h=a.width();k=a.height();j={top:0,left:0}}else if(d.scrollTo&&d.document){h=a.width();k=a.height();j={top:a.scrollTop(),left:a.scrollLeft()}}else if(d.preventDefault){b.at="left top";h=k=0;j=
|
||||
{top:b.of.pageY,left:b.of.pageX}}else{h=a.outerWidth();k=a.outerHeight();j=a.offset()}c.each(["my","at"],function(){var f=(b[this]||"").split(" ");if(f.length===1)f=n.test(f[0])?f.concat(["center"]):o.test(f[0])?["center"].concat(f):["center","center"];f[0]=n.test(f[0])?f[0]:"center";f[1]=o.test(f[1])?f[1]:"center";b[this]=f});if(g.length===1)g[1]=g[0];e[0]=parseInt(e[0],10)||0;if(e.length===1)e[1]=e[0];e[1]=parseInt(e[1],10)||0;if(b.at[0]==="right")j.left+=h;else if(b.at[0]==="center")j.left+=h/
|
||||
2;if(b.at[1]==="bottom")j.top+=k;else if(b.at[1]==="center")j.top+=k/2;j.left+=e[0];j.top+=e[1];return this.each(function(){var f=c(this),l=f.outerWidth(),m=f.outerHeight(),p=parseInt(c.curCSS(this,"marginLeft",true))||0,q=parseInt(c.curCSS(this,"marginTop",true))||0,v=l+p+parseInt(c.curCSS(this,"marginRight",true))||0,w=m+q+parseInt(c.curCSS(this,"marginBottom",true))||0,i=c.extend({},j),r;if(b.my[0]==="right")i.left-=l;else if(b.my[0]==="center")i.left-=l/2;if(b.my[1]==="bottom")i.top-=m;else if(b.my[1]===
|
||||
"center")i.top-=m/2;i.left=parseInt(i.left);i.top=parseInt(i.top);r={left:i.left-p,top:i.top-q};c.each(["left","top"],function(s,x){c.ui.position[g[s]]&&c.ui.position[g[s]][x](i,{targetWidth:h,targetHeight:k,elemWidth:l,elemHeight:m,collisionPosition:r,collisionWidth:v,collisionHeight:w,offset:e,my:b.my,at:b.at})});c.fn.bgiframe&&f.bgiframe();f.offset(c.extend(i,{using:b.using}))})};c.ui.position={fit:{left:function(b,a){var d=c(window);d=a.collisionPosition.left+a.collisionWidth-d.width()-d.scrollLeft();
|
||||
b.left=d>0?b.left-d:Math.max(b.left-a.collisionPosition.left,b.left)},top:function(b,a){var d=c(window);d=a.collisionPosition.top+a.collisionHeight-d.height()-d.scrollTop();b.top=d>0?b.top-d:Math.max(b.top-a.collisionPosition.top,b.top)}},flip:{left:function(b,a){if(a.at[0]!=="center"){var d=c(window);d=a.collisionPosition.left+a.collisionWidth-d.width()-d.scrollLeft();var g=a.my[0]==="left"?-a.elemWidth:a.my[0]==="right"?a.elemWidth:0,e=a.at[0]==="left"?a.targetWidth:-a.targetWidth,h=-2*a.offset[0];
|
||||
b.left+=a.collisionPosition.left<0?g+e+h:d>0?g+e+h:0}},top:function(b,a){if(a.at[1]!=="center"){var d=c(window);d=a.collisionPosition.top+a.collisionHeight-d.height()-d.scrollTop();var g=a.my[1]==="top"?-a.elemHeight:a.my[1]==="bottom"?a.elemHeight:0,e=a.at[1]==="top"?a.targetHeight:-a.targetHeight,h=-2*a.offset[1];b.top+=a.collisionPosition.top<0?g+e+h:d>0?g+e+h:0}}}};if(!c.offset.setOffset){c.offset.setOffset=function(b,a){if(/static/.test(c.curCSS(b,"position")))b.style.position="relative";var d=
|
||||
c(b),g=d.offset(),e=parseInt(c.curCSS(b,"top",true),10)||0,h=parseInt(c.curCSS(b,"left",true),10)||0;g={top:a.top-g.top+e,left:a.left-g.left+h};"using"in a?a.using.call(b,g):d.css(g)};c.fn.offset=function(b){var a=this[0];if(!a||!a.ownerDocument)return null;if(b)return this.each(function(){c.offset.setOffset(this,b)});return u.call(this)}}})(jQuery);
|
||||
(function(b,c){b.widget("ui.progressbar",{options:{value:0},min:0,max:100,_create:function(){this.element.addClass("ui-progressbar ui-widget ui-widget-content ui-corner-all").attr({role:"progressbar","aria-valuemin":this.min,"aria-valuemax":this.max,"aria-valuenow":this._value()});this.valueDiv=b("<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>").appendTo(this.element);this._refreshValue()},destroy:function(){this.element.removeClass("ui-progressbar ui-widget ui-widget-content ui-corner-all").removeAttr("role").removeAttr("aria-valuemin").removeAttr("aria-valuemax").removeAttr("aria-valuenow");
|
||||
this.valueDiv.remove();b.Widget.prototype.destroy.apply(this,arguments)},value:function(a){if(a===c)return this._value();this._setOption("value",a);return this},_setOption:function(a,d){if(a==="value"){this.options.value=d;this._refreshValue();this._trigger("change")}b.Widget.prototype._setOption.apply(this,arguments)},_value:function(){var a=this.options.value;if(typeof a!=="number")a=0;return Math.min(this.max,Math.max(this.min,a))},_refreshValue:function(){var a=this.value();this.valueDiv.toggleClass("ui-corner-right",
|
||||
a===this.max).width(a+"%");this.element.attr("aria-valuenow",a)}});b.extend(b.ui.progressbar,{version:"1.8.5"})})(jQuery);
|
||||
(function(d){d.widget("ui.slider",d.ui.mouse,{widgetEventPrefix:"slide",options:{animate:false,distance:0,max:100,min:0,orientation:"horizontal",range:false,step:1,value:0,values:null},_create:function(){var a=this,b=this.options;this._mouseSliding=this._keySliding=false;this._animateOff=true;this._handleIndex=null;this._detectOrientation();this._mouseInit();this.element.addClass("ui-slider ui-slider-"+this.orientation+" ui-widget ui-widget-content ui-corner-all");b.disabled&&this.element.addClass("ui-slider-disabled ui-disabled");
|
||||
this.range=d([]);if(b.range){if(b.range===true){this.range=d("<div></div>");if(!b.values)b.values=[this._valueMin(),this._valueMin()];if(b.values.length&&b.values.length!==2)b.values=[b.values[0],b.values[0]]}else this.range=d("<div></div>");this.range.appendTo(this.element).addClass("ui-slider-range");if(b.range==="min"||b.range==="max")this.range.addClass("ui-slider-range-"+b.range);this.range.addClass("ui-widget-header")}d(".ui-slider-handle",this.element).length===0&&d("<a href='#'></a>").appendTo(this.element).addClass("ui-slider-handle");
|
||||
if(b.values&&b.values.length)for(;d(".ui-slider-handle",this.element).length<b.values.length;)d("<a href='#'></a>").appendTo(this.element).addClass("ui-slider-handle");this.handles=d(".ui-slider-handle",this.element).addClass("ui-state-default ui-corner-all");this.handle=this.handles.eq(0);this.handles.add(this.range).filter("a").click(function(c){c.preventDefault()}).hover(function(){b.disabled||d(this).addClass("ui-state-hover")},function(){d(this).removeClass("ui-state-hover")}).focus(function(){if(b.disabled)d(this).blur();
|
||||
else{d(".ui-slider .ui-state-focus").removeClass("ui-state-focus");d(this).addClass("ui-state-focus")}}).blur(function(){d(this).removeClass("ui-state-focus")});this.handles.each(function(c){d(this).data("index.ui-slider-handle",c)});this.handles.keydown(function(c){var e=true,f=d(this).data("index.ui-slider-handle"),h,g,i;if(!a.options.disabled){switch(c.keyCode){case d.ui.keyCode.HOME:case d.ui.keyCode.END:case d.ui.keyCode.PAGE_UP:case d.ui.keyCode.PAGE_DOWN:case d.ui.keyCode.UP:case d.ui.keyCode.RIGHT:case d.ui.keyCode.DOWN:case d.ui.keyCode.LEFT:e=
|
||||
false;if(!a._keySliding){a._keySliding=true;d(this).addClass("ui-state-active");h=a._start(c,f);if(h===false)return}break}i=a.options.step;h=a.options.values&&a.options.values.length?(g=a.values(f)):(g=a.value());switch(c.keyCode){case d.ui.keyCode.HOME:g=a._valueMin();break;case d.ui.keyCode.END:g=a._valueMax();break;case d.ui.keyCode.PAGE_UP:g=a._trimAlignValue(h+(a._valueMax()-a._valueMin())/5);break;case d.ui.keyCode.PAGE_DOWN:g=a._trimAlignValue(h-(a._valueMax()-a._valueMin())/5);break;case d.ui.keyCode.UP:case d.ui.keyCode.RIGHT:if(h===
|
||||
a._valueMax())return;g=a._trimAlignValue(h+i);break;case d.ui.keyCode.DOWN:case d.ui.keyCode.LEFT:if(h===a._valueMin())return;g=a._trimAlignValue(h-i);break}a._slide(c,f,g);return e}}).keyup(function(c){var e=d(this).data("index.ui-slider-handle");if(a._keySliding){a._keySliding=false;a._stop(c,e);a._change(c,e);d(this).removeClass("ui-state-active")}});this._refreshValue();this._animateOff=false},destroy:function(){this.handles.remove();this.range.remove();this.element.removeClass("ui-slider ui-slider-horizontal ui-slider-vertical ui-slider-disabled ui-widget ui-widget-content ui-corner-all").removeData("slider").unbind(".slider");
|
||||
this._mouseDestroy();return this},_mouseCapture:function(a){var b=this.options,c,e,f,h,g;if(b.disabled)return false;this.elementSize={width:this.element.outerWidth(),height:this.element.outerHeight()};this.elementOffset=this.element.offset();c=this._normValueFromMouse({x:a.pageX,y:a.pageY});e=this._valueMax()-this._valueMin()+1;h=this;this.handles.each(function(i){var j=Math.abs(c-h.values(i));if(e>j){e=j;f=d(this);g=i}});if(b.range===true&&this.values(1)===b.min){g+=1;f=d(this.handles[g])}if(this._start(a,
|
||||
g)===false)return false;this._mouseSliding=true;h._handleIndex=g;f.addClass("ui-state-active").focus();b=f.offset();this._clickOffset=!d(a.target).parents().andSelf().is(".ui-slider-handle")?{left:0,top:0}:{left:a.pageX-b.left-f.width()/2,top:a.pageY-b.top-f.height()/2-(parseInt(f.css("borderTopWidth"),10)||0)-(parseInt(f.css("borderBottomWidth"),10)||0)+(parseInt(f.css("marginTop"),10)||0)};this._slide(a,g,c);return this._animateOff=true},_mouseStart:function(){return true},_mouseDrag:function(a){var b=
|
||||
this._normValueFromMouse({x:a.pageX,y:a.pageY});this._slide(a,this._handleIndex,b);return false},_mouseStop:function(a){this.handles.removeClass("ui-state-active");this._mouseSliding=false;this._stop(a,this._handleIndex);this._change(a,this._handleIndex);this._clickOffset=this._handleIndex=null;return this._animateOff=false},_detectOrientation:function(){this.orientation=this.options.orientation==="vertical"?"vertical":"horizontal"},_normValueFromMouse:function(a){var b;if(this.orientation==="horizontal"){b=
|
||||
this.elementSize.width;a=a.x-this.elementOffset.left-(this._clickOffset?this._clickOffset.left:0)}else{b=this.elementSize.height;a=a.y-this.elementOffset.top-(this._clickOffset?this._clickOffset.top:0)}b=a/b;if(b>1)b=1;if(b<0)b=0;if(this.orientation==="vertical")b=1-b;a=this._valueMax()-this._valueMin();return this._trimAlignValue(this._valueMin()+b*a)},_start:function(a,b){var c={handle:this.handles[b],value:this.value()};if(this.options.values&&this.options.values.length){c.value=this.values(b);
|
||||
c.values=this.values()}return this._trigger("start",a,c)},_slide:function(a,b,c){var e;if(this.options.values&&this.options.values.length){e=this.values(b?0:1);if(this.options.values.length===2&&this.options.range===true&&(b===0&&c>e||b===1&&c<e))c=e;if(c!==this.values(b)){e=this.values();e[b]=c;a=this._trigger("slide",a,{handle:this.handles[b],value:c,values:e});this.values(b?0:1);a!==false&&this.values(b,c,true)}}else if(c!==this.value()){a=this._trigger("slide",a,{handle:this.handles[b],value:c});
|
||||
a!==false&&this.value(c)}},_stop:function(a,b){var c={handle:this.handles[b],value:this.value()};if(this.options.values&&this.options.values.length){c.value=this.values(b);c.values=this.values()}this._trigger("stop",a,c)},_change:function(a,b){if(!this._keySliding&&!this._mouseSliding){var c={handle:this.handles[b],value:this.value()};if(this.options.values&&this.options.values.length){c.value=this.values(b);c.values=this.values()}this._trigger("change",a,c)}},value:function(a){if(arguments.length){this.options.value=
|
||||
this._trimAlignValue(a);this._refreshValue();this._change(null,0)}return this._value()},values:function(a,b){var c,e,f;if(arguments.length>1){this.options.values[a]=this._trimAlignValue(b);this._refreshValue();this._change(null,a)}if(arguments.length)if(d.isArray(arguments[0])){c=this.options.values;e=arguments[0];for(f=0;f<c.length;f+=1){c[f]=this._trimAlignValue(e[f]);this._change(null,f)}this._refreshValue()}else return this.options.values&&this.options.values.length?this._values(a):this.value();
|
||||
else return this._values()},_setOption:function(a,b){var c,e=0;if(d.isArray(this.options.values))e=this.options.values.length;d.Widget.prototype._setOption.apply(this,arguments);switch(a){case "disabled":if(b){this.handles.filter(".ui-state-focus").blur();this.handles.removeClass("ui-state-hover");this.handles.attr("disabled","disabled");this.element.addClass("ui-disabled")}else{this.handles.removeAttr("disabled");this.element.removeClass("ui-disabled")}break;case "orientation":this._detectOrientation();
|
||||
this.element.removeClass("ui-slider-horizontal ui-slider-vertical").addClass("ui-slider-"+this.orientation);this._refreshValue();break;case "value":this._animateOff=true;this._refreshValue();this._change(null,0);this._animateOff=false;break;case "values":this._animateOff=true;this._refreshValue();for(c=0;c<e;c+=1)this._change(null,c);this._animateOff=false;break}},_value:function(){var a=this.options.value;return a=this._trimAlignValue(a)},_values:function(a){var b,c;if(arguments.length){b=this.options.values[a];
|
||||
return b=this._trimAlignValue(b)}else{b=this.options.values.slice();for(c=0;c<b.length;c+=1)b[c]=this._trimAlignValue(b[c]);return b}},_trimAlignValue:function(a){if(a<this._valueMin())return this._valueMin();if(a>this._valueMax())return this._valueMax();var b=this.options.step>0?this.options.step:1,c=a%b;a=a-c;if(Math.abs(c)*2>=b)a+=c>0?b:-b;return parseFloat(a.toFixed(5))},_valueMin:function(){return this.options.min},_valueMax:function(){return this.options.max},_refreshValue:function(){var a=
|
||||
this.options.range,b=this.options,c=this,e=!this._animateOff?b.animate:false,f,h={},g,i,j,l;if(this.options.values&&this.options.values.length)this.handles.each(function(k){f=(c.values(k)-c._valueMin())/(c._valueMax()-c._valueMin())*100;h[c.orientation==="horizontal"?"left":"bottom"]=f+"%";d(this).stop(1,1)[e?"animate":"css"](h,b.animate);if(c.options.range===true)if(c.orientation==="horizontal"){if(k===0)c.range.stop(1,1)[e?"animate":"css"]({left:f+"%"},b.animate);if(k===1)c.range[e?"animate":"css"]({width:f-
|
||||
g+"%"},{queue:false,duration:b.animate})}else{if(k===0)c.range.stop(1,1)[e?"animate":"css"]({bottom:f+"%"},b.animate);if(k===1)c.range[e?"animate":"css"]({height:f-g+"%"},{queue:false,duration:b.animate})}g=f});else{i=this.value();j=this._valueMin();l=this._valueMax();f=l!==j?(i-j)/(l-j)*100:0;h[c.orientation==="horizontal"?"left":"bottom"]=f+"%";this.handle.stop(1,1)[e?"animate":"css"](h,b.animate);if(a==="min"&&this.orientation==="horizontal")this.range.stop(1,1)[e?"animate":"css"]({width:f+"%"},
|
||||
b.animate);if(a==="max"&&this.orientation==="horizontal")this.range[e?"animate":"css"]({width:100-f+"%"},{queue:false,duration:b.animate});if(a==="min"&&this.orientation==="vertical")this.range.stop(1,1)[e?"animate":"css"]({height:f+"%"},b.animate);if(a==="max"&&this.orientation==="vertical")this.range[e?"animate":"css"]({height:100-f+"%"},{queue:false,duration:b.animate})}}});d.extend(d.ui.slider,{version:"1.8.5"})})(jQuery);
|
||||
(function(d,p){function u(){return++v}function w(){return++x}var v=0,x=0;d.widget("ui.tabs",{options:{add:null,ajaxOptions:null,cache:false,cookie:null,collapsible:false,disable:null,disabled:[],enable:null,event:"click",fx:null,idPrefix:"ui-tabs-",load:null,panelTemplate:"<div></div>",remove:null,select:null,show:null,spinner:"<em>Loading…</em>",tabTemplate:"<li><a href='#{href}'><span>#{label}</span></a></li>"},_create:function(){this._tabify(true)},_setOption:function(a,e){if(a=="selected")this.options.collapsible&&
|
||||
e==this.options.selected||this.select(e);else{this.options[a]=e;this._tabify()}},_tabId:function(a){return a.title&&a.title.replace(/\s/g,"_").replace(/[^\w\u00c0-\uFFFF-]/g,"")||this.options.idPrefix+u()},_sanitizeSelector:function(a){return a.replace(/:/g,"\\:")},_cookie:function(){var a=this.cookie||(this.cookie=this.options.cookie.name||"ui-tabs-"+w());return d.cookie.apply(null,[a].concat(d.makeArray(arguments)))},_ui:function(a,e){return{tab:a,panel:e,index:this.anchors.index(a)}},_cleanup:function(){this.lis.filter(".ui-state-processing").removeClass("ui-state-processing").find("span:data(label.tabs)").each(function(){var a=
|
||||
d(this);a.html(a.data("label.tabs")).removeData("label.tabs")})},_tabify:function(a){function e(g,f){g.css("display","");!d.support.opacity&&f.opacity&&g[0].style.removeAttribute("filter")}var b=this,c=this.options,h=/^#.+/;this.list=this.element.find("ol,ul").eq(0);this.lis=d(" > li:has(a[href])",this.list);this.anchors=this.lis.map(function(){return d("a",this)[0]});this.panels=d([]);this.anchors.each(function(g,f){var i=d(f).attr("href"),l=i.split("#")[0],q;if(l&&(l===location.toString().split("#")[0]||
|
||||
(q=d("base")[0])&&l===q.href)){i=f.hash;f.href=i}if(h.test(i))b.panels=b.panels.add(b._sanitizeSelector(i));else if(i&&i!=="#"){d.data(f,"href.tabs",i);d.data(f,"load.tabs",i.replace(/#.*$/,""));i=b._tabId(f);f.href="#"+i;f=d("#"+i);if(!f.length){f=d(c.panelTemplate).attr("id",i).addClass("ui-tabs-panel ui-widget-content ui-corner-bottom").insertAfter(b.panels[g-1]||b.list);f.data("destroy.tabs",true)}b.panels=b.panels.add(f)}else c.disabled.push(g)});if(a){this.element.addClass("ui-tabs ui-widget ui-widget-content ui-corner-all");
|
||||
this.list.addClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all");this.lis.addClass("ui-state-default ui-corner-top");this.panels.addClass("ui-tabs-panel ui-widget-content ui-corner-bottom");if(c.selected===p){location.hash&&this.anchors.each(function(g,f){if(f.hash==location.hash){c.selected=g;return false}});if(typeof c.selected!=="number"&&c.cookie)c.selected=parseInt(b._cookie(),10);if(typeof c.selected!=="number"&&this.lis.filter(".ui-tabs-selected").length)c.selected=
|
||||
this.lis.index(this.lis.filter(".ui-tabs-selected"));c.selected=c.selected||(this.lis.length?0:-1)}else if(c.selected===null)c.selected=-1;c.selected=c.selected>=0&&this.anchors[c.selected]||c.selected<0?c.selected:0;c.disabled=d.unique(c.disabled.concat(d.map(this.lis.filter(".ui-state-disabled"),function(g){return b.lis.index(g)}))).sort();d.inArray(c.selected,c.disabled)!=-1&&c.disabled.splice(d.inArray(c.selected,c.disabled),1);this.panels.addClass("ui-tabs-hide");this.lis.removeClass("ui-tabs-selected ui-state-active");
|
||||
if(c.selected>=0&&this.anchors.length){this.panels.eq(c.selected).removeClass("ui-tabs-hide");this.lis.eq(c.selected).addClass("ui-tabs-selected ui-state-active");b.element.queue("tabs",function(){b._trigger("show",null,b._ui(b.anchors[c.selected],b.panels[c.selected]))});this.load(c.selected)}d(window).bind("unload",function(){b.lis.add(b.anchors).unbind(".tabs");b.lis=b.anchors=b.panels=null})}else c.selected=this.lis.index(this.lis.filter(".ui-tabs-selected"));this.element[c.collapsible?"addClass":
|
||||
"removeClass"]("ui-tabs-collapsible");c.cookie&&this._cookie(c.selected,c.cookie);a=0;for(var j;j=this.lis[a];a++)d(j)[d.inArray(a,c.disabled)!=-1&&!d(j).hasClass("ui-tabs-selected")?"addClass":"removeClass"]("ui-state-disabled");c.cache===false&&this.anchors.removeData("cache.tabs");this.lis.add(this.anchors).unbind(".tabs");if(c.event!=="mouseover"){var k=function(g,f){f.is(":not(.ui-state-disabled)")&&f.addClass("ui-state-"+g)},n=function(g,f){f.removeClass("ui-state-"+g)};this.lis.bind("mouseover.tabs",
|
||||
function(){k("hover",d(this))});this.lis.bind("mouseout.tabs",function(){n("hover",d(this))});this.anchors.bind("focus.tabs",function(){k("focus",d(this).closest("li"))});this.anchors.bind("blur.tabs",function(){n("focus",d(this).closest("li"))})}var m,o;if(c.fx)if(d.isArray(c.fx)){m=c.fx[0];o=c.fx[1]}else m=o=c.fx;var r=o?function(g,f){d(g).closest("li").addClass("ui-tabs-selected ui-state-active");f.hide().removeClass("ui-tabs-hide").animate(o,o.duration||"normal",function(){e(f,o);b._trigger("show",
|
||||
null,b._ui(g,f[0]))})}:function(g,f){d(g).closest("li").addClass("ui-tabs-selected ui-state-active");f.removeClass("ui-tabs-hide");b._trigger("show",null,b._ui(g,f[0]))},s=m?function(g,f){f.animate(m,m.duration||"normal",function(){b.lis.removeClass("ui-tabs-selected ui-state-active");f.addClass("ui-tabs-hide");e(f,m);b.element.dequeue("tabs")})}:function(g,f){b.lis.removeClass("ui-tabs-selected ui-state-active");f.addClass("ui-tabs-hide");b.element.dequeue("tabs")};this.anchors.bind(c.event+".tabs",
|
||||
function(){var g=this,f=d(g).closest("li"),i=b.panels.filter(":not(.ui-tabs-hide)"),l=d(b._sanitizeSelector(g.hash));if(f.hasClass("ui-tabs-selected")&&!c.collapsible||f.hasClass("ui-state-disabled")||f.hasClass("ui-state-processing")||b.panels.filter(":animated").length||b._trigger("select",null,b._ui(this,l[0]))===false){this.blur();return false}c.selected=b.anchors.index(this);b.abort();if(c.collapsible)if(f.hasClass("ui-tabs-selected")){c.selected=-1;c.cookie&&b._cookie(c.selected,c.cookie);b.element.queue("tabs",
|
||||
function(){s(g,i)}).dequeue("tabs");this.blur();return false}else if(!i.length){c.cookie&&b._cookie(c.selected,c.cookie);b.element.queue("tabs",function(){r(g,l)});b.load(b.anchors.index(this));this.blur();return false}c.cookie&&b._cookie(c.selected,c.cookie);if(l.length){i.length&&b.element.queue("tabs",function(){s(g,i)});b.element.queue("tabs",function(){r(g,l)});b.load(b.anchors.index(this))}else throw"jQuery UI Tabs: Mismatching fragment identifier.";d.browser.msie&&this.blur()});this.anchors.bind("click.tabs",
|
||||
function(){return false})},_getIndex:function(a){if(typeof a=="string")a=this.anchors.index(this.anchors.filter("[href$="+a+"]"));return a},destroy:function(){var a=this.options;this.abort();this.element.unbind(".tabs").removeClass("ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible").removeData("tabs");this.list.removeClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all");this.anchors.each(function(){var e=d.data(this,"href.tabs");if(e)this.href=
|
||||
e;var b=d(this).unbind(".tabs");d.each(["href","load","cache"],function(c,h){b.removeData(h+".tabs")})});this.lis.unbind(".tabs").add(this.panels).each(function(){d.data(this,"destroy.tabs")?d(this).remove():d(this).removeClass("ui-state-default ui-corner-top ui-tabs-selected ui-state-active ui-state-hover ui-state-focus ui-state-disabled ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide")});a.cookie&&this._cookie(null,a.cookie);return this},add:function(a,e,b){if(b===p)b=this.anchors.length;
|
||||
var c=this,h=this.options;e=d(h.tabTemplate.replace(/#\{href\}/g,a).replace(/#\{label\}/g,e));a=!a.indexOf("#")?a.replace("#",""):this._tabId(d("a",e)[0]);e.addClass("ui-state-default ui-corner-top").data("destroy.tabs",true);var j=d("#"+a);j.length||(j=d(h.panelTemplate).attr("id",a).data("destroy.tabs",true));j.addClass("ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide");if(b>=this.lis.length){e.appendTo(this.list);j.appendTo(this.list[0].parentNode)}else{e.insertBefore(this.lis[b]);
|
||||
j.insertBefore(this.panels[b])}h.disabled=d.map(h.disabled,function(k){return k>=b?++k:k});this._tabify();if(this.anchors.length==1){h.selected=0;e.addClass("ui-tabs-selected ui-state-active");j.removeClass("ui-tabs-hide");this.element.queue("tabs",function(){c._trigger("show",null,c._ui(c.anchors[0],c.panels[0]))});this.load(0)}this._trigger("add",null,this._ui(this.anchors[b],this.panels[b]));return this},remove:function(a){a=this._getIndex(a);var e=this.options,b=this.lis.eq(a).remove(),c=this.panels.eq(a).remove();
|
||||
if(b.hasClass("ui-tabs-selected")&&this.anchors.length>1)this.select(a+(a+1<this.anchors.length?1:-1));e.disabled=d.map(d.grep(e.disabled,function(h){return h!=a}),function(h){return h>=a?--h:h});this._tabify();this._trigger("remove",null,this._ui(b.find("a")[0],c[0]));return this},enable:function(a){a=this._getIndex(a);var e=this.options;if(d.inArray(a,e.disabled)!=-1){this.lis.eq(a).removeClass("ui-state-disabled");e.disabled=d.grep(e.disabled,function(b){return b!=a});this._trigger("enable",null,
|
||||
this._ui(this.anchors[a],this.panels[a]));return this}},disable:function(a){a=this._getIndex(a);var e=this.options;if(a!=e.selected){this.lis.eq(a).addClass("ui-state-disabled");e.disabled.push(a);e.disabled.sort();this._trigger("disable",null,this._ui(this.anchors[a],this.panels[a]))}return this},select:function(a){a=this._getIndex(a);if(a==-1)if(this.options.collapsible&&this.options.selected!=-1)a=this.options.selected;else return this;this.anchors.eq(a).trigger(this.options.event+".tabs");return this},
|
||||
load:function(a){a=this._getIndex(a);var e=this,b=this.options,c=this.anchors.eq(a)[0],h=d.data(c,"load.tabs");this.abort();if(!h||this.element.queue("tabs").length!==0&&d.data(c,"cache.tabs"))this.element.dequeue("tabs");else{this.lis.eq(a).addClass("ui-state-processing");if(b.spinner){var j=d("span",c);j.data("label.tabs",j.html()).html(b.spinner)}this.xhr=d.ajax(d.extend({},b.ajaxOptions,{url:h,success:function(k,n){d(e._sanitizeSelector(c.hash)).html(k);e._cleanup();b.cache&&d.data(c,"cache.tabs",
|
||||
true);e._trigger("load",null,e._ui(e.anchors[a],e.panels[a]));try{b.ajaxOptions.success(k,n)}catch(m){}},error:function(k,n){e._cleanup();e._trigger("load",null,e._ui(e.anchors[a],e.panels[a]));try{b.ajaxOptions.error(k,n,a,c)}catch(m){}}}));e.element.dequeue("tabs");return this}},abort:function(){this.element.queue([]);this.panels.stop(false,true);this.element.queue("tabs",this.element.queue("tabs").splice(-2,2));if(this.xhr){this.xhr.abort();delete this.xhr}this._cleanup();return this},url:function(a,
|
||||
e){this.anchors.eq(a).removeData("cache.tabs").data("load.tabs",e);return this},length:function(){return this.anchors.length}});d.extend(d.ui.tabs,{version:"1.8.5"});d.extend(d.ui.tabs.prototype,{rotation:null,rotate:function(a,e){var b=this,c=this.options,h=b._rotate||(b._rotate=function(j){clearTimeout(b.rotation);b.rotation=setTimeout(function(){var k=c.selected;b.select(++k<b.anchors.length?k:0)},a);j&&j.stopPropagation()});e=b._unrotate||(b._unrotate=!e?function(j){j.clientX&&b.rotate(null)}:
|
||||
function(){t=c.selected;h()});if(a){this.element.bind("tabsshow",h);this.anchors.bind(c.event+".tabs",e);h()}else{clearTimeout(b.rotation);this.element.unbind("tabsshow",h);this.anchors.unbind(c.event+".tabs",e);delete this._rotate;delete this._unrotate}return this}})})(jQuery);
|
||||
4
esphomeyaml/dashboard/static/jquery.min.js
vendored
Normal file
4
esphomeyaml/dashboard/static/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
esphomeyaml/dashboard/static/jquery.validate.min.js
vendored
Normal file
4
esphomeyaml/dashboard/static/jquery.validate.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
13
esphomeyaml/dashboard/static/materialize.min.css
vendored
Normal file
13
esphomeyaml/dashboard/static/materialize.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6
esphomeyaml/dashboard/static/materialize.min.js
vendored
Normal file
6
esphomeyaml/dashboard/static/materialize.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
8
esphomeyaml/dashboard/static/mode-yaml.js
Normal file
8
esphomeyaml/dashboard/static/mode-yaml.js
Normal file
@@ -0,0 +1,8 @@
|
||||
ace.define("ace/mode/yaml_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("./text_highlight_rules").TextHighlightRules,s=function(){this.$rules={start:[{token:"comment",regex:"#.*$"},{token:"list.markup",regex:/^(?:-{3}|\.{3})\s*(?=#|$)/},{token:"list.markup",regex:/^\s*[\-?](?:$|\s)/},{token:"constant",regex:"!![\\w//]+"},{token:"constant.language",regex:"[&\\*][a-zA-Z0-9-_]+"},{token:["meta.tag","keyword"],regex:/^(\s*\w.*?)(:(?=\s|$))/},{token:["meta.tag","keyword"],regex:/(\w+?)(\s*:(?=\s|$))/},{token:"keyword.operator",regex:"<<\\w*:\\w*"},{token:"keyword.operator",regex:"-\\s*(?=[{])"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",regex:/[|>][-+\d\s]*$/,onMatch:function(e,t,n,r){var i=/^\s*/.exec(r)[0];return n.length<1?n.push(this.next):n[0]="mlString",n.length<2?n.push(i.length):n[1]=i.length,this.token},next:"mlString"},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"constant.numeric",regex:/(\b|[+\-\.])[\d_]+(?:(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)(?=[^\d-\w]|$)/},{token:"constant.numeric",regex:/[+\-]?\.inf\b|NaN\b|0x[\dA-Fa-f_]+|0b[10_]+/},{token:"constant.language.boolean",regex:"\\b(?:true|false|TRUE|FALSE|True|False|yes|no)\\b"},{token:"paren.lparen",regex:"[[({]"},{token:"paren.rparen",regex:"[\\])}]"},{token:"text",regex:/[^\s,:\[\]\{\}]+/}],mlString:[{token:"indent",regex:/^\s*$/},{token:"indent",regex:/^\s*/,onMatch:function(e,t,n){var r=n[1];return r>=e.length?(this.next="start",n.splice(0)):this.next="mlString",this.token},next:"mlString"},{token:"string",regex:".+"}]},this.normalizeRules()};r.inherits(s,i),t.YamlHighlightRules=s}),ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"],function(e,t,n){"use strict";var r=e("../range").Range,i=function(){};(function(){this.checkOutdent=function(e,t){return/^\s+$/.test(e)?/^\s*\}/.test(t):!1},this.autoOutdent=function(e,t){var n=e.getLine(t),i=n.match(/^(\s*\})/);if(!i)return 0;var s=i[1].length,o=e.findMatchingBracket({row:t,column:s});if(!o||o.row==t)return 0;var u=this.$getIndent(e.getLine(o.row));e.replace(new r(t,0,t,s-1),u)},this.$getIndent=function(e){return e.match(/^\s*/)[0]}}).call(i.prototype),t.MatchingBraceOutdent=i}),ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"],function(e,t,n){"use strict";var r=e("../../lib/oop"),i=e("./fold_mode").FoldMode,s=e("../../range").Range,o=t.FoldMode=function(){};r.inherits(o,i),function(){this.getFoldWidgetRange=function(e,t,n){var r=this.indentationBlock(e,n);if(r)return r;var i=/\S/,o=e.getLine(n),u=o.search(i);if(u==-1||o[u]!="#")return;var a=o.length,f=e.getLength(),l=n,c=n;while(++n<f){o=e.getLine(n);var h=o.search(i);if(h==-1)continue;if(o[h]!="#")break;c=n}if(c>l){var p=e.getLine(c).length;return new s(l,a,c,p)}},this.getFoldWidget=function(e,t,n){var r=e.getLine(n),i=r.search(/\S/),s=e.getLine(n+1),o=e.getLine(n-1),u=o.search(/\S/),a=s.search(/\S/);if(i==-1)return e.foldWidgets[n-1]=u!=-1&&u<a?"start":"","";if(u==-1){if(i==a&&r[i]=="#"&&s[i]=="#")return e.foldWidgets[n-1]="",e.foldWidgets[n+1]="","start"}else if(u==i&&r[i]=="#"&&o[i]=="#"&&e.getLine(n-2).search(/\S/)==-1)return e.foldWidgets[n-1]="start",e.foldWidgets[n+1]="","";return u!=-1&&u<i?e.foldWidgets[n-1]="start":e.foldWidgets[n-1]="",i<a?"start":""}}.call(o.prototype)}),ace.define("ace/mode/yaml",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/yaml_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/coffee"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("./text").Mode,s=e("./yaml_highlight_rules").YamlHighlightRules,o=e("./matching_brace_outdent").MatchingBraceOutdent,u=e("./folding/coffee").FoldMode,a=function(){this.HighlightRules=s,this.$outdent=new o,this.foldingRules=new u,this.$behaviour=this.$defaultBehaviour};r.inherits(a,i),function(){this.lineCommentStart=["#"],this.getNextLineIndent=function(e,t,n){var r=this.$getIndent(t);if(e=="start"){var i=t.match(/^.*[\{\(\[]\s*$/);i&&(r+=n)}return r},this.checkOutdent=function(e,t,n){return this.$outdent.checkOutdent(t,n)},this.autoOutdent=function(e,t,n){this.$outdent.autoOutdent(t,n)},this.$id="ace/mode/yaml"}.call(a.prototype),t.Mode=a}); (function() {
|
||||
ace.require(["ace/mode/yaml"], function(m) {
|
||||
if (typeof module == "object" && typeof exports == "object" && module) {
|
||||
module.exports = m;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
8
esphomeyaml/dashboard/static/theme-dreamweaver.js
Normal file
8
esphomeyaml/dashboard/static/theme-dreamweaver.js
Normal file
@@ -0,0 +1,8 @@
|
||||
ace.define("ace/theme/dreamweaver",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-dreamweaver",t.cssText='.ace-dreamweaver .ace_gutter {background: #e8e8e8;color: #333;}.ace-dreamweaver .ace_print-margin {width: 1px;background: #e8e8e8;}.ace-dreamweaver {background-color: #FFFFFF;color: black;}.ace-dreamweaver .ace_fold {background-color: #757AD8;}.ace-dreamweaver .ace_cursor {color: black;}.ace-dreamweaver .ace_invisible {color: rgb(191, 191, 191);}.ace-dreamweaver .ace_storage,.ace-dreamweaver .ace_keyword {color: blue;}.ace-dreamweaver .ace_constant.ace_buildin {color: rgb(88, 72, 246);}.ace-dreamweaver .ace_constant.ace_language {color: rgb(88, 92, 246);}.ace-dreamweaver .ace_constant.ace_library {color: rgb(6, 150, 14);}.ace-dreamweaver .ace_invalid {background-color: rgb(153, 0, 0);color: white;}.ace-dreamweaver .ace_support.ace_function {color: rgb(60, 76, 114);}.ace-dreamweaver .ace_support.ace_constant {color: rgb(6, 150, 14);}.ace-dreamweaver .ace_support.ace_type,.ace-dreamweaver .ace_support.ace_class {color: #009;}.ace-dreamweaver .ace_support.ace_php_tag {color: #f00;}.ace-dreamweaver .ace_keyword.ace_operator {color: rgb(104, 118, 135);}.ace-dreamweaver .ace_string {color: #00F;}.ace-dreamweaver .ace_comment {color: rgb(76, 136, 107);}.ace-dreamweaver .ace_comment.ace_doc {color: rgb(0, 102, 255);}.ace-dreamweaver .ace_comment.ace_doc.ace_tag {color: rgb(128, 159, 191);}.ace-dreamweaver .ace_constant.ace_numeric {color: rgb(0, 0, 205);}.ace-dreamweaver .ace_variable {color: #06F}.ace-dreamweaver .ace_xml-pe {color: rgb(104, 104, 91);}.ace-dreamweaver .ace_entity.ace_name.ace_function {color: #00F;}.ace-dreamweaver .ace_heading {color: rgb(12, 7, 255);}.ace-dreamweaver .ace_list {color:rgb(185, 6, 144);}.ace-dreamweaver .ace_marker-layer .ace_selection {background: rgb(181, 213, 255);}.ace-dreamweaver .ace_marker-layer .ace_step {background: rgb(252, 255, 0);}.ace-dreamweaver .ace_marker-layer .ace_stack {background: rgb(164, 229, 101);}.ace-dreamweaver .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgb(192, 192, 192);}.ace-dreamweaver .ace_marker-layer .ace_active-line {background: rgba(0, 0, 0, 0.07);}.ace-dreamweaver .ace_gutter-active-line {background-color : #DCDCDC;}.ace-dreamweaver .ace_marker-layer .ace_selected-word {background: rgb(250, 250, 255);border: 1px solid rgb(200, 200, 250);}.ace-dreamweaver .ace_meta.ace_tag {color:#009;}.ace-dreamweaver .ace_meta.ace_tag.ace_anchor {color:#060;}.ace-dreamweaver .ace_meta.ace_tag.ace_form {color:#F90;}.ace-dreamweaver .ace_meta.ace_tag.ace_image {color:#909;}.ace-dreamweaver .ace_meta.ace_tag.ace_script {color:#900;}.ace-dreamweaver .ace_meta.ace_tag.ace_style {color:#909;}.ace-dreamweaver .ace_meta.ace_tag.ace_table {color:#099;}.ace-dreamweaver .ace_string.ace_regex {color: rgb(255, 0, 0)}.ace-dreamweaver .ace_indent-guide {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y;}';var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)}); (function() {
|
||||
ace.require(["ace/theme/dreamweaver"], function(m) {
|
||||
if (typeof module == "object" && typeof exports == "object" && module) {
|
||||
module.exports = m;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -4,161 +4,17 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>esphomeyaml Dashboard</title>
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
|
||||
<link rel="stylesheet" href="/static/materialize.min.css?v=1">
|
||||
<link rel="stylesheet" href="/static/materialize-stepper.min.css?v=1">
|
||||
<link rel="stylesheet" href="/static/esphomeyaml.css?v=1">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico?v=1">
|
||||
|
||||
<link rel="stylesheet" href="/static/materialize-stepper.min.css">
|
||||
|
||||
<!-- jQuery :( -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.8.5/jquery-ui.min.js" integrity="sha256-fOse6WapxTrUSJOJICXXYwHRJOPa6C1OUQXi7C9Ddy8=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
|
||||
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
|
||||
|
||||
|
||||
<script src="/static/materialize-stepper.min.js"></script>
|
||||
|
||||
<style>
|
||||
nav .brand-logo {
|
||||
margin-left: 48px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
main .container {
|
||||
margin-top: -12vh;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ribbon {
|
||||
width: 100%;
|
||||
height: 17vh;
|
||||
background-color: #3F51B5;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ribbon-fab:not(.tap-target-origin) {
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
top: calc(17vh + 34px);
|
||||
}
|
||||
|
||||
i.very-large {
|
||||
font-size: 8rem;
|
||||
padding-top: 2px;
|
||||
color: #424242;
|
||||
}
|
||||
|
||||
.card .card-content {
|
||||
padding-left: 18px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.log {
|
||||
background-color: #1c1c1c;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
font-size: 12px;
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
line-height: 1.45;
|
||||
border-radius: 3px;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: break-word;
|
||||
color: #DDD;
|
||||
}
|
||||
|
||||
.inlinecode {
|
||||
box-sizing: border-box;
|
||||
padding: 0.2em 0.4em;
|
||||
margin: 0;
|
||||
font-size: 85%;
|
||||
background-color: rgba(27,31,35,0.05);
|
||||
border-radius: 3px;
|
||||
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;
|
||||
}
|
||||
|
||||
.log.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.log .v {
|
||||
color: #888888;
|
||||
}
|
||||
|
||||
.log .d {
|
||||
color: #00DDDD;
|
||||
}
|
||||
|
||||
.log .c {
|
||||
color: magenta;
|
||||
}
|
||||
|
||||
.log .i {
|
||||
color: limegreen;
|
||||
}
|
||||
|
||||
.log .w {
|
||||
color: yellow;
|
||||
}
|
||||
|
||||
.log .e {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.log .e {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.log .ww {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.modal {
|
||||
width: 95%;
|
||||
max-height: 90%;
|
||||
height: 85% !important;
|
||||
}
|
||||
|
||||
.page-footer {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1 0 auto;
|
||||
}
|
||||
|
||||
ul.browser-default {
|
||||
padding-left: 30px;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
ul.browser-default li {
|
||||
list-style-type: initial;
|
||||
}
|
||||
|
||||
ul.stepper:not(.horizontal) .step.active::before, ul.stepper:not(.horizontal) .step.done::before, ul.stepper.horizontal .step.active .step-title::before, ul.stepper.horizontal .step.done .step-title::before {
|
||||
background-color: #3f51b5 !important;
|
||||
}
|
||||
|
||||
.select-port-container {
|
||||
margin-top: 8px;
|
||||
margin-right: 24px;
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
.dropdown-trigger {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
<script src="/static/jquery.min.js?v=1"></script>
|
||||
<script src="/static/jquery-ui.min.js?v=1"></script>
|
||||
<script src="/static/materialize.min.js?v=1"></script>
|
||||
<script src="/static/jquery.validate.min.js?v=1"></script>
|
||||
|
||||
<script src="/static/materialize-stepper.min.js?v=1"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
</head>
|
||||
<body>
|
||||
@@ -178,7 +34,7 @@
|
||||
<h5>Select Upload Port</h5>
|
||||
<p>
|
||||
Here you can select where esphomeyaml will attempt to show logs and upload firmwares to.
|
||||
By default, this is "OTA", or Over-The-Air. Note that you might have to restart the HassIO add-on
|
||||
By default, this is "OTA", or Over-The-Air. Note that you might have to restart the Hass.io add-on
|
||||
for new serial ports to be detected.
|
||||
</p>
|
||||
</div>
|
||||
@@ -189,7 +45,7 @@
|
||||
|
||||
<main>
|
||||
<div class="container">
|
||||
{% for i, (file, full_path) in enumerate(zip(files, full_path_files)) %}
|
||||
{% for i, entry in enumerate(entries) %}
|
||||
<div class="row">
|
||||
<div class="col s8 offset-s2 m10 offset-m1 l12">
|
||||
<div class="card horizontal">
|
||||
@@ -199,23 +55,33 @@
|
||||
<div class="card-stacked">
|
||||
<div class="card-content">
|
||||
<span class="card-title">
|
||||
{{ escape(file) }}
|
||||
{{ escape(entry.name) }}
|
||||
<i class="material-icons right dropdown-trigger" data-target="dropdown-{{ i }}">more_vert</i>
|
||||
</span>
|
||||
<p>
|
||||
Full path: <code class="inlinecode">{{ escape(full_path) }}</code>
|
||||
<span class="status-indicator unknown" data-node="{{ entry.filename }}">
|
||||
<span class="status-indicator-icon"></span>
|
||||
<span class="status-indicator-text"></span></span>.
|
||||
Full path: <code class="inlinecode">{{ escape(entry.full_path) }}</code>
|
||||
</p>
|
||||
{% if entry.update_available %}
|
||||
<p class="update-available" data-node="{{ entry.filename }}">
|
||||
<i class="material-icons">system_update</i>
|
||||
Update Available! {{ entry.update_old }} ➡️{{ entry.update_new }}
|
||||
</p>
|
||||
{% end %}
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<a href="#" class="action-upload" data-node="{{ file }}">Upload</a>
|
||||
<a href="#" class="action-compile" data-node="{{ file }}">Compile</a>
|
||||
<a href="#" class="action-show-logs" data-node="{{ file }}">Show Logs</a>
|
||||
<a href="#" class="action-validate" data-node="{{ file }}">Validate</a>
|
||||
<a class="action-upload" data-node="{{ entry.filename }}">Upload</a>
|
||||
<a class="action-edit" data-node="{{ entry.filename }}">Edit</a>
|
||||
<a class="action-show-logs" data-node="{{ entry.filename }}">Show Logs</a>
|
||||
<a class="action-validate" data-node="{{ entry.filename }}">Validate</a>
|
||||
</div>
|
||||
<ul id="dropdown-{{ i }}" class="dropdown-content">
|
||||
<li><a href="#" class="action-clean-mqtt" data-node="{{ file }}">Clean MQTT</a></li>
|
||||
<li><a href="#" class="action-clean" data-node="{{ file }}">Clean Build</a></li>
|
||||
<li><a href="#" class="action-hass-config" data-node="{{ file }}">Home Assistant Configuration</a></li>
|
||||
<ul id="dropdown-{{ i }}" class="dropdown-content card-dropdown-action">
|
||||
<li><a class="action-clean-mqtt" data-node="{{ entry.filename }}">Clean MQTT</a></li>
|
||||
<li><a class="action-clean" data-node="{{ entry.filename }}">Clean Build</a></li>
|
||||
<li><a class="action-compile" data-node="{{ entry.filename }}">Compile</a></li>
|
||||
<li><a class="action-hass-config" data-node="{{ entry.filename }}">Home Assistant Configuration</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -225,10 +91,14 @@
|
||||
</div>
|
||||
|
||||
<div id="modal-logs" class="modal modal-fixed-footer">
|
||||
<div class="modal-content">
|
||||
<h4>Show Logs <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
<div class="modal-content autoscroll">
|
||||
<div>
|
||||
<h4>Show Logs <code class="inlinecode filename"></code></h4>
|
||||
<div>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -237,25 +107,37 @@
|
||||
</div>
|
||||
|
||||
<div id="modal-upload" class="modal modal-fixed-footer">
|
||||
<div class="modal-content">
|
||||
<h4>Compile And Upload <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
<div class="modal-content autoscroll">
|
||||
<div>
|
||||
<h4>Compile And Upload <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="https://esphomelib.com/esphomeyaml/guides/faq.html#i-can-t-get-flashing-over-usb-to-work" target="_blank"
|
||||
class="tooltipped" data-position="left" data-tooltip="Flash using esphomeflasher">
|
||||
<i class="material-icons flash-using-esphomeflasher">help_outline</i>
|
||||
</a>
|
||||
<a class="modal-close waves-effect waves-green btn-flat stop-logs">Stop</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-compile" class="modal modal-fixed-footer">
|
||||
<div class="modal-content">
|
||||
<h4>Compile <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
<div class="modal-content autoscroll">
|
||||
<div>
|
||||
<h4>Compile <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="https://esphomelib.com/esphomeyaml/guides/faq.html#i-can-t-get-flashing-over-usb-to-work" target="_blank"
|
||||
class="tooltipped" data-position="left" data-tooltip="Flash using esphomeflasher">
|
||||
<i class="material-icons flash-using-esphomeflasher">help_outline</i>
|
||||
</a>
|
||||
<a class="modal-close waves-effect waves-green btn-flat disabled download-binary">Download Binary</a>
|
||||
<a class="modal-close waves-effect waves-green btn-flat stop-logs">Stop</a>
|
||||
</div>
|
||||
@@ -324,25 +206,97 @@
|
||||
<div class="row">
|
||||
<p>
|
||||
Great! Now I need to know what type of microcontroller you're using so that I can compile firmware for them.
|
||||
Please choose either ESP32 or ESP8266 (use ESP8266 for Sonoff devices).
|
||||
Please choose the board you're using below. If you're not sure you can also use similar ones
|
||||
or even the "Generic" option. In most cases that will work too.
|
||||
</p>
|
||||
<div class="input-field col s12">
|
||||
<select id="esp_type" name="platform" required>
|
||||
<option value="ESP8266">ESP8266</option>
|
||||
<option value="ESP32">ESP32</option>
|
||||
<select id="board" name="board" required>
|
||||
<optgroup label="ESP8266">
|
||||
<option value="esp01_1m">Generic ESP8266 (for example Sonoff)</option>
|
||||
<option value="nodemcuv2">NodeMCU</option>
|
||||
<option value="d1_mini">Wemos D1 and Wemos D1 mini</option>
|
||||
<option value="d1_mini_lite">Wemos D1 mini Lite</option>
|
||||
<option value="d1_mini_pro">Wemos D1 mini Pro</option>
|
||||
<option value="huzzah">Adafruit HUZZAH ESP8266</option>
|
||||
<option value="oak">DigiStump Oak</option>
|
||||
<option value="thing">Sparkfun ESP8266 Thing</option>
|
||||
<option value="thingdev">Sparkfun ESP8266 Thing - Dev Board</option>
|
||||
</optgroup>
|
||||
<optgroup label="ESP32">
|
||||
<option value="esp-wrover-kit">Generic ESP32 (WROVER Module)</option>
|
||||
<option value="nodemcu-32s">NodeMCU-32S</option>
|
||||
<option value="lolin_d32">Wemos Lolin D32</option>
|
||||
<option value="lolin_d32_pro">Wemos Lolin D32 Pro</option>
|
||||
<option value="featheresp32">Adafruit ESP32 Feather</option>
|
||||
<option value="m5stack-core-esp32">M5Stack Core ESP32</option>
|
||||
</optgroup>
|
||||
<optgroup label="Other ESP8266s">
|
||||
<option value="gen4iod">4D Systems gen4 IoD Range</option>
|
||||
<option value="wifi_slot">Amperka WiFi Slot</option>
|
||||
<option value="espduino">Doit ESPDuino</option>
|
||||
<option value="espectro">DycodeX ESPectro Core</option>
|
||||
<option value="espino">ESPino</option>
|
||||
<option value="esp_wroom_02">Espressif ESP-WROOM-02 module</option>
|
||||
<option value="esp12e">Espressif ESP-12E module</option>
|
||||
<option value="esp01">Espressif ESP-01 512k module</option>
|
||||
<option value="esp07">Espressif ESP-07 module</option>
|
||||
<option value="esp8285">Generic ESP8285 module</option>
|
||||
<option value="espresso_lite_v1">ESPert ESPresso Lite 1.0</option>
|
||||
<option value="espresso_lite_v2">ESPert ESPresso Lite 2.0</option>
|
||||
<option value="phoenix_v1">ESPert Phoenix 1.0</option>
|
||||
<option value="wifinfo">WiFInfo</option>
|
||||
<option value="heltec_wifi_kit_8">Heltec WiFi kit 8</option>
|
||||
<option value="nodemcu">NodeMCU 0.9</option>
|
||||
<option value="modwifi">Olimex MOD-WIFI</option>
|
||||
<option value="wio_link">SeedStudio Wio Link</option>
|
||||
<option value="wio_node">SeedStudio Wio Node</option>
|
||||
<option value="sparkfunBlynk">Sparkfun Blynk Board</option>
|
||||
<option value="esp210">SweetPea ESP-210</option>
|
||||
<option value="espinotee">ThaiEasyElec ESPino</option>
|
||||
<option value="d1">Wemos D1 Revision 1</option>
|
||||
<option value="wifiduino">WiFiDuino</option>
|
||||
<option value="xinabox_cw01">XinaBox CW01</option>
|
||||
</optgroup>
|
||||
<optgroup label="Other ESP32s">
|
||||
<option value="lolin32">Wemos Lolin 32</option>
|
||||
<option value="esp32dev">Espressif ESP32 Dev Module</option>
|
||||
<option value="m5stack-fire">M5Stack FIRE</option>
|
||||
<option value="wemosbat">Wemos WiFi & Bluetooth Battery</option>
|
||||
<option value="node32s">Aiyarafun Node32s</option>
|
||||
<option value="espea32">April Brother ESPea32</option>
|
||||
<option value="firebeetle32">DFRobot FireBeetle-ESP32</option>
|
||||
<option value="esp32doit-devkit-v1">Doit ESP32 Devkit v1</option>
|
||||
<option value="pocket_32">Dongsen Tech Pocket 32</option>
|
||||
<option value="espectro32">DycodeX ESPectro32</option>
|
||||
<option value="esp32vn-iot-uno">ESP32vn IoT Uno</option>
|
||||
<option value="esp320">Electronic SweetPeas ESP320</option>
|
||||
<option value="pico32">Espressif ESP32 Pico Kit</option>
|
||||
<option value="odroid_esp32">Hardkernel Odroid GO</option>
|
||||
<option value="heltec_wifi_kit_32">Heltec WIFI Kit 32</option>
|
||||
<option value="heltec_wifi_lora_32">Heltec WIFI LoRa 32</option>
|
||||
<option value="hornbill32dev">Hornbill ESP32 Dev</option>
|
||||
<option value="hornbill32minima">Hornbill ESP32 Minima</option>
|
||||
<option value="intorobot">IntoRobot Fig</option>
|
||||
<option value="mhetesp32devkit">MH-ET Live ESP32 Devkit</option>
|
||||
<option value="mhetesp32minikit">MH-ET Live ESP32 Minikit</option>
|
||||
<option value="nano32">MakerAsia Nano32</option>
|
||||
<option value="microduino-core-esp32">Microduino Core ESP32</option>
|
||||
<option value="quantum">Noduino Quantum</option>
|
||||
<option value="esp32-evb">Olimex ESP32-EVB</option>
|
||||
<option value="esp32-gateway">Olimex ESP32-GATEWAY</option>
|
||||
<option value="esp32-pro">Olimex ESP32-PRO</option>
|
||||
<option value="onehorse32dev">Onehorse ESP32 Dev Module</option>
|
||||
<option value="alksesp32">RoboticsBrno ALKS ESP32</option>
|
||||
<option value="esp32thing">Sparkfun ESP32 Thing</option>
|
||||
<option value="ttgo-lora32-v1">TTGO LoRa32-OLED v1</option>
|
||||
<option value="espino32">ThaiEasyElec ESPino32</option>
|
||||
<option value="widora-air">Widora AIR</option>
|
||||
<option value="xinabox_cw02">XinaBox CW02</option>
|
||||
<option value="iotbusio">oddWires IoT-Bus Io</option>
|
||||
<option value="iotbusproteus">oddWires Proteus IoT-Bus</option>
|
||||
<option value="nina_w10">u-blox NINA-W10 series</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
<label>Microcontroller Type</label>
|
||||
</div>
|
||||
<p>
|
||||
I'm also going to need to know which type of board you're using. Please go to
|
||||
<a href="http://docs.platformio.org/en/latest/platforms/espressif32.html#boards" target="_blank">ESP32 boards</a> or
|
||||
<a href="http://docs.platformio.org/en/latest/platforms/espressif8266.html#boards" target="_blank">ESP8266 boards</a>,
|
||||
find your board and enter it here. For example, enter <code class="inlinecode">nodemcuv2</code>
|
||||
for ESP8266 NodeMCU boards. Note: Use <code class="inlinecode">esp01_1m</code> for Sonoff devices.
|
||||
</p>
|
||||
<div class="input-field col s12">
|
||||
<input id="board_type" class="validate" type="text" name="board" required>
|
||||
<label for="board_type">Board Type</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="step-actions">
|
||||
@@ -385,29 +339,54 @@
|
||||
<div class="step-title waves-effect">MQTT</div>
|
||||
<div class="step-content">
|
||||
<div class="row">
|
||||
<p>
|
||||
esphomelib connects to your Home Assistant instance via
|
||||
<a href="https://www.home-assistant.io/docs/mqtt/">MQTT</a>. If you haven't already, please set up
|
||||
MQTT on your Home Assistant server, for example with the awesome
|
||||
<a href="https://www.home-assistant.io/addons/mosquitto/">Mosquitto Hass.io Add-on</a>.
|
||||
</p>
|
||||
<p>
|
||||
When you're done with that, please enter your MQTT broker here. For example
|
||||
<code class="inlinecode">192.168.1.100</code> (Note
|
||||
<code class="inlinecode">hassio.local</code> doesn't always work, please use a static IP).
|
||||
Please also specify the MQTT username and password you wish esphomelib to use
|
||||
(leave them empty if you're not using any authentication).
|
||||
</p>
|
||||
{% if mqtt_config is None %}
|
||||
<p>
|
||||
esphomelib connects to your Home Assistant instance via
|
||||
<a href="https://www.home-assistant.io/docs/mqtt/">MQTT</a>.
|
||||
If you haven't already, please set up
|
||||
MQTT on your Home Assistant server, for example with the
|
||||
<a href="https://www.home-assistant.io/addons/mosquitto/">Mosquitto Hass.io Add-on</a>.
|
||||
</p>
|
||||
<p>
|
||||
When you're done with that, please enter your MQTT broker here. For example
|
||||
<code class="inlinecode">192.168.1.100</code>.
|
||||
Please also specify the MQTT username and password you wish esphomelib to use
|
||||
(leave them empty if you're not using any authentication).
|
||||
</p>
|
||||
{% else %}
|
||||
<p>
|
||||
esphomelib connects to your Home Assistant instance via
|
||||
<a href="https://www.home-assistant.io/docs/mqtt/">MQTT</a>. In this section you will have
|
||||
to tell esphomelib which MQTT "broker" to use.
|
||||
|
||||
</p>
|
||||
<p>
|
||||
It looks like you've already set up MQTT, the values below are taken from your Hass.io MQTT add-on.
|
||||
Please confirm they are correct and press CONTINUE.
|
||||
</p>
|
||||
{% end %}
|
||||
<div class="input-field col s12">
|
||||
<input id="mqtt_broker" class="validate" type="text" name="broker" required>
|
||||
{% if mqtt_config is None %}
|
||||
<input id="mqtt_broker" class="validate" type="text" name="broker" required>
|
||||
{% else %}
|
||||
<input id="mqtt_broker" class="validate" type="text" name="broker" value="{{ mqtt_config['host'] }}" required>
|
||||
{% end %}
|
||||
<label for="mqtt_broker">MQTT Broker</label>
|
||||
</div>
|
||||
<div class="input-field col s6">
|
||||
<input id="mqtt_username" class="validate" type="text" name="mqtt_username">
|
||||
{% if mqtt_config is None %}
|
||||
<input id="mqtt_username" class="validate" type="text" name="mqtt_username">
|
||||
{% else %}
|
||||
<input id="mqtt_username" class="validate" type="text" name="mqtt_username" value="{{ mqtt_config['username'] }}">
|
||||
{% end%}
|
||||
<label for="mqtt_username">MQTT Username</label>
|
||||
</div>
|
||||
<div class="input-field col s6">
|
||||
<input id="mqtt_password" class="validate" name="mqtt_password" type="password">
|
||||
{% if mqtt_config is None %}
|
||||
<input id="mqtt_password" class="validate" name="mqtt_password" type="password">
|
||||
{% else %}
|
||||
<input id="mqtt_password" class="validate" name="mqtt_password" type="password" value="{{ mqtt_config['password'] }}">
|
||||
{% end %}
|
||||
<label for="mqtt_password">MQTT Password</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -464,15 +443,17 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Abort</a>
|
||||
<a class="modal-close waves-effect waves-green btn-flat">Abort</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-clean-mqtt" class="modal modal-fixed-footer">
|
||||
<div class="modal-content">
|
||||
<h4>Clean MQTT discovery <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
<div class="modal-content autoscroll">
|
||||
<div>
|
||||
<h4>Clean MQTT discovery <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -481,10 +462,12 @@
|
||||
</div>
|
||||
|
||||
<div id="modal-clean" class="modal modal-fixed-footer">
|
||||
<div class="modal-content">
|
||||
<h4>Clean Build Files <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
<div class="modal-content autoscroll">
|
||||
<div>
|
||||
<h4>Clean Build Files <code class="inlinecode filename"></code></h4>
|
||||
<div class="log-container">
|
||||
<pre class="log"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -504,6 +487,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-editor" class="modal modal-fixed-footer">
|
||||
<div class="modal-content">
|
||||
<h4>Edit <code class="inlinecode filename"></code></h4>
|
||||
<div id="editor">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="waves-effect waves-green btn-flat save-button">Save</a>
|
||||
<a class="modal-close waves-effect waves-green btn-flat">Close</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a class="btn-floating btn-large ribbon-fab waves-effect waves-light pink accent-2" id="setup-wizard-start">
|
||||
<i class="material-icons">add</i>
|
||||
</a>
|
||||
@@ -526,467 +522,15 @@
|
||||
<div class="footer-copyright">
|
||||
<div class="container">
|
||||
© 2018 Copyright Otto Winter, Made with <a class="grey-text text-lighten-4" href="https://materializecss.com/" target="_blank">Materialize</a>
|
||||
<a class="grey-text text-lighten-4 right" href="https://esphomelib.com/esphomeyaml/index.html" target="_blank">esphomeyaml {{ version }} Documentation</a>
|
||||
<a class="grey-text text-lighten-4 right" href="{{ docs_link }}" target="_blank">esphomeyaml {{ version }} Documentation</a>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
M.AutoInit(document.body);
|
||||
});
|
||||
<script src="/static/ace.js?v=1" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="/static/esphomeyaml.js?v=1" type="text/javascript"></script>
|
||||
|
||||
const colorReplace = (input) => {
|
||||
input = input.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
input = input.replace(/\\033\[(?:0;)?31m/g, '<span class="e">');
|
||||
input = input.replace(/\\033\[(?:1;)?31m/g, '<span class="e bold">');
|
||||
input = input.replace(/\\033\[(?:0;)?32m/g, '<span class="i">');
|
||||
input = input.replace(/\\033\[(?:1;)?32m/g, '<span class="i bold">');
|
||||
input = input.replace(/\\033\[(?:0;)?33m/g, '<span class="w">');
|
||||
input = input.replace(/\\033\[(?:1;)?33m/g, '<span class="w bold">');
|
||||
input = input.replace(/\\033\[(?:0;)?35m/g, '<span class="c">');
|
||||
input = input.replace(/\\033\[(?:1;)?35m/g, '<span class="c bold">');
|
||||
input = input.replace(/\\033\[(?:0;)?36m/g, '<span class="d">');
|
||||
input = input.replace(/\\033\[(?:1;)?36m/g, '<span class="d bold">');
|
||||
input = input.replace(/\\033\[(?:0;)?37m/g, '<span class="v">');
|
||||
input = input.replace(/\\033\[(?:1;)?37m/g, '<span class="v bold">');
|
||||
input = input.replace(/\\033\[(?:0;)?38m/g, '<span class="vv">');
|
||||
input = input.replace(/\\033\[(?:1;)?38m/g, '<span class="vv bold">');
|
||||
input = input.replace(/\\033\[0m/g, '</span>');
|
||||
|
||||
return input;
|
||||
};
|
||||
|
||||
let configuration = "";
|
||||
let wsProtocol = "ws:";
|
||||
if (window.location.protocol === "https:") {
|
||||
wsProtocol = 'wss:';
|
||||
}
|
||||
const wsUrl = wsProtocol + '//' + window.location.hostname + ':' + window.location.port;
|
||||
|
||||
const portSelect = document.querySelector('.nav-wrapper select');
|
||||
let ports = [];
|
||||
|
||||
const fetchSerialPorts = (begin=false) => {
|
||||
fetch('/serial-ports', {credentials: "same-origin"}).then(res => res.json())
|
||||
.then(response => {
|
||||
if (ports.length === response.length) {
|
||||
let allEqual = true;
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
if (ports[i].port !== response[i].port) {
|
||||
allEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allEqual)
|
||||
return;
|
||||
}
|
||||
const hasNewPort = response.length >= ports.length;
|
||||
|
||||
ports = response;
|
||||
|
||||
const inst = M.FormSelect.getInstance(portSelect);
|
||||
if (inst !== undefined) {
|
||||
inst.destroy();
|
||||
}
|
||||
|
||||
portSelect.innerHTML = "";
|
||||
const prevSelected = getUploadPort();
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
const val = response[i];
|
||||
if (val.port === prevSelected) {
|
||||
portSelect.innerHTML += `<option value="${val.port}" selected>${val.port} (${val.desc})</option>`;
|
||||
} else {
|
||||
portSelect.innerHTML += `<option value="${val.port}">${val.port} (${val.desc})</option>`;
|
||||
}
|
||||
}
|
||||
|
||||
M.FormSelect.init(portSelect, {});
|
||||
if (!begin && hasNewPort)
|
||||
M.toast({html: "Discovered new serial port."});
|
||||
});
|
||||
};
|
||||
|
||||
const getUploadPort = () => {
|
||||
const inst = M.FormSelect.getInstance(portSelect);
|
||||
if (inst === undefined) {
|
||||
return "OTA";
|
||||
}
|
||||
|
||||
inst._setSelectedStates();
|
||||
return inst.getSelectedValues()[0];
|
||||
};
|
||||
setInterval(fetchSerialPorts, 5000);
|
||||
fetchSerialPorts(true);
|
||||
|
||||
const logsModalElem = document.getElementById("modal-logs");
|
||||
|
||||
document.querySelectorAll(".action-show-logs").forEach((showLogs) => {
|
||||
showLogs.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(logsModalElem);
|
||||
const log = logsModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = logsModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = logsModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/logs");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration, port: getUploadPort()});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const uploadModalElem = document.getElementById("modal-upload");
|
||||
|
||||
document.querySelectorAll(".action-upload").forEach((upload) => {
|
||||
upload.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(uploadModalElem);
|
||||
const log = uploadModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = uploadModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = uploadModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/run");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration, port: getUploadPort()});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const validateModalElem = document.getElementById("modal-validate");
|
||||
|
||||
document.querySelectorAll(".action-validate").forEach((upload) => {
|
||||
upload.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(validateModalElem);
|
||||
const log = validateModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = validateModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = validateModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/validate");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({
|
||||
html: `<code class="inlinecode">${configuration}</code> is valid 👍`,
|
||||
displayLength: 5000,
|
||||
});
|
||||
} else {
|
||||
M.toast({
|
||||
html: `<code class="inlinecode">${configuration}</code> is invalid 😕`,
|
||||
displayLength: 5000,
|
||||
});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const compileModalElem = document.getElementById("modal-compile");
|
||||
const downloadButton = compileModalElem.querySelector('.download-binary');
|
||||
|
||||
document.querySelectorAll(".action-compile").forEach((upload) => {
|
||||
upload.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(compileModalElem);
|
||||
const log = compileModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = compileModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
downloadButton.classList.add('disabled');
|
||||
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = compileModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/compile");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
downloadButton.classList.remove('disabled');
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
downloadButton.addEventListener('click', () => {
|
||||
const link = document.createElement("a");
|
||||
link.download = name;
|
||||
link.href = '/download.bin?configuration=' + encodeURIComponent(configuration);
|
||||
link.click();
|
||||
});
|
||||
|
||||
const cleanMqttModalElem = document.getElementById("modal-clean-mqtt");
|
||||
|
||||
document.querySelectorAll(".action-clean-mqtt").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(cleanMqttModalElem);
|
||||
const log = cleanMqttModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = cleanMqttModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = cleanMqttModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/clean-mqtt");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const cleanModalElem = document.getElementById("modal-clean");
|
||||
|
||||
document.querySelectorAll(".action-clean").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(cleanModalElem);
|
||||
const log = cleanModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = cleanModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = cleanModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/clean");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
downloadButton.classList.remove('disabled');
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const hassConfigModalElem = document.getElementById("modal-hass-config");
|
||||
|
||||
document.querySelectorAll(".action-hass-config").forEach((btn) => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
configuration = e.target.getAttribute('data-node');
|
||||
const modalInstance = M.Modal.getInstance(hassConfigModalElem);
|
||||
const log = hassConfigModalElem.querySelector(".log");
|
||||
log.innerHTML = "";
|
||||
const stopLogsButton = hassConfigModalElem.querySelector(".stop-logs");
|
||||
let stopped = false;
|
||||
stopLogsButton.innerHTML = "Stop";
|
||||
modalInstance.open();
|
||||
|
||||
const filenameField = hassConfigModalElem.querySelector('.filename');
|
||||
filenameField.innerHTML = configuration;
|
||||
|
||||
const logSocket = new WebSocket(wsUrl + "/hass-config");
|
||||
logSocket.addEventListener('message', (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === "line") {
|
||||
const msg = data.data;
|
||||
log.innerHTML += colorReplace(msg);
|
||||
} else if (data.event === "exit") {
|
||||
if (data.code === 0) {
|
||||
M.toast({html: "Program exited successfully."});
|
||||
downloadButton.classList.remove('disabled');
|
||||
} else {
|
||||
M.toast({html: `Program failed with code ${data.code}`});
|
||||
}
|
||||
stopLogsButton.innerHTML = "Close";
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
logSocket.addEventListener('open', () => {
|
||||
const msg = JSON.stringify({configuration: configuration});
|
||||
logSocket.send(msg);
|
||||
});
|
||||
logSocket.addEventListener('close', () => {
|
||||
if (!stopped) {
|
||||
M.toast({html: 'Terminated process.'});
|
||||
}
|
||||
});
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
logSocket.close();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const modalSetupElem = document.getElementById("modal-wizard");
|
||||
const setupWizardStart = document.getElementById('setup-wizard-start');
|
||||
const startWizard = () => {
|
||||
const modalInstance = M.Modal.getInstance(modalSetupElem);
|
||||
modalInstance.open();
|
||||
|
||||
modalInstance.options.onCloseStart = () => {
|
||||
|
||||
};
|
||||
|
||||
$('.stepper').activateStepper({
|
||||
linearStepsNavigation: false,
|
||||
autoFocusInput: true,
|
||||
autoFormCreation: true,
|
||||
showFeedbackLoader: true,
|
||||
parallel: false
|
||||
});
|
||||
};
|
||||
setupWizardStart.addEventListener('click', startWizard);
|
||||
</script>
|
||||
|
||||
{% if len(files) == 0 %}
|
||||
{% if len(entries) == 0 %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const tapTargetElem = document.querySelector('.tap-target.setup-wizard');
|
||||
|
||||
74
esphomeyaml/dashboard/templates/login.html
Normal file
74
esphomeyaml/dashboard/templates/login.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>esphomeyaml Dashboard</title>
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/static/materialize.min.css?v=1">
|
||||
<link rel="stylesheet" href="/static/esphomeyaml.css?v=1">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico?v=1">
|
||||
|
||||
<script src="/static/materialize.min.js?v=1"></script>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<nav>
|
||||
<div class="nav-wrapper indigo">
|
||||
<a href="#" class="brand-logo left">esphomeyaml Dashboard</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="ribbon"></div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col card s10 offset-s1 m10 offset-m1 l8 offset-l2">
|
||||
<form action="/login" method="post">
|
||||
<div class="card-content">
|
||||
<span class="card-title">Enter credentials</span>
|
||||
<p>
|
||||
Please login using your Home Assistant credentials.
|
||||
</p>
|
||||
{% if error is not None %}
|
||||
<p>
|
||||
{{ escape(error) }}
|
||||
</p>
|
||||
{% end %}
|
||||
<div class="row">
|
||||
<div class="input-field col s12">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" class="validate" name="username" id="username" />
|
||||
</div>
|
||||
<div class="input-field col s12">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" class="validate" name="password" id="password" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action right-align">
|
||||
<button class="btn indigo waves-effect waves-light" type="submit" name="action">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="page-footer indigo darken-1">
|
||||
<div class="container">
|
||||
|
||||
</div>
|
||||
<div class="footer-copyright">
|
||||
<div class="container">
|
||||
© 2018 Copyright Otto Winter, Made with <a class="grey-text text-lighten-4" href="https://materializecss.com/" target="_blank">Materialize</a>
|
||||
<a class="grey-text text-lighten-4 right" href="{{ docs_link }}" target="_blank">esphomeyaml {{ version }} Documentation</a>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,7 +4,7 @@ import random
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.core import EsphomeyamlError
|
||||
|
||||
RESPONSE_OK = 0
|
||||
RESPONSE_REQUEST_AUTH = 1
|
||||
@@ -29,29 +29,35 @@ OTA_VERSION_1_0 = 1
|
||||
MAGIC_BYTES = [0x6C, 0x26, 0xF7, 0x5C, 0x45]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
LAST_PROGRESS = -1
|
||||
|
||||
|
||||
def update_progress(progress):
|
||||
global LAST_PROGRESS
|
||||
class ProgressBar(object):
|
||||
def __init__(self):
|
||||
self.last_progress = None
|
||||
|
||||
bar_length = 60
|
||||
status = ""
|
||||
if progress >= 1:
|
||||
progress = 1
|
||||
status = "Done...\r\n"
|
||||
new_progress = int(progress * 100)
|
||||
if new_progress == LAST_PROGRESS:
|
||||
return
|
||||
LAST_PROGRESS = new_progress
|
||||
block = int(round(bar_length * progress))
|
||||
text = "\rUploading: [{0}] {1}% {2}".format("=" * block + " " * (bar_length - block),
|
||||
new_progress, status)
|
||||
sys.stderr.write(text)
|
||||
sys.stderr.flush()
|
||||
def update(self, progress):
|
||||
bar_length = 60
|
||||
status = ""
|
||||
if progress >= 1:
|
||||
progress = 1
|
||||
status = "Done...\r\n"
|
||||
new_progress = int(progress * 100)
|
||||
if new_progress == self.last_progress:
|
||||
return
|
||||
self.last_progress = new_progress
|
||||
block = int(round(bar_length * progress))
|
||||
text = "\rUploading: [{0}] {1}% {2}".format("=" * block + " " * (bar_length - block),
|
||||
new_progress, status)
|
||||
sys.stderr.write(text)
|
||||
sys.stderr.flush()
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def done(self):
|
||||
sys.stderr.write('\n')
|
||||
sys.stderr.flush()
|
||||
|
||||
|
||||
class OTAError(ESPHomeYAMLError):
|
||||
class OTAError(EsphomeyamlError):
|
||||
pass
|
||||
|
||||
|
||||
@@ -188,7 +194,7 @@ def perform_ota(sock, password, file_handle, filename):
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8192)
|
||||
|
||||
offset = 0
|
||||
update_progress(0.0)
|
||||
progress = ProgressBar()
|
||||
while True:
|
||||
chunk = file_handle.read(1024)
|
||||
if not chunk:
|
||||
@@ -201,12 +207,12 @@ def perform_ota(sock, password, file_handle, filename):
|
||||
sys.stderr.write('\n')
|
||||
raise OTAError("Error sending data: {}".format(err))
|
||||
|
||||
update_progress(offset / float(file_size))
|
||||
progress.update(offset / float(file_size))
|
||||
progress.done()
|
||||
|
||||
# Enable nodelay for last checks
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
|
||||
sys.stderr.write('\n')
|
||||
_LOGGER.info("Waiting for result...")
|
||||
|
||||
receive_exactly(sock, 1, 'receive OK', RESPONSE_RECEIVE_OK)
|
||||
@@ -257,7 +263,7 @@ def resolve_ip_address(host):
|
||||
return ip
|
||||
|
||||
|
||||
def run_ota(remote_host, remote_port, password, filename):
|
||||
def run_ota_impl_(remote_host, remote_port, password, filename):
|
||||
ip = resolve_ip_address(remote_host)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(10.0)
|
||||
@@ -281,6 +287,14 @@ def run_ota(remote_host, remote_port, password, filename):
|
||||
return 0
|
||||
|
||||
|
||||
def run_ota(remote_host, remote_port, password, filename):
|
||||
try:
|
||||
return run_ota_impl_(remote_host, remote_port, password, filename)
|
||||
except OTAError as err:
|
||||
_LOGGER.error(err)
|
||||
return 1
|
||||
|
||||
|
||||
def run_legacy_ota(verbose, host_port, remote_host, remote_port, password, filename):
|
||||
from esphomeyaml import espota
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from collections import OrderedDict, deque
|
||||
import inspect
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, \
|
||||
CONF_INVERTED, \
|
||||
CONF_MODE, CONF_NUMBER, CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_PCF8574, \
|
||||
CONF_RETAIN, CONF_STATE_TOPIC, CONF_TOPIC, CONF_SETUP_PRIORITY
|
||||
from esphomeyaml.core import ESPHomeYAMLError, HexInt, Lambda, TimePeriodMicroseconds, \
|
||||
TimePeriodMilliseconds, TimePeriodSeconds
|
||||
import subprocess
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -44,206 +36,6 @@ def indent(text, padding=u' '):
|
||||
return u'\n'.join(indent_list(text, padding))
|
||||
|
||||
|
||||
class Expression(object):
|
||||
def __init__(self):
|
||||
self.requires = []
|
||||
self.required = False
|
||||
|
||||
def __str__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def require(self):
|
||||
self.required = True
|
||||
for require in self.requires:
|
||||
if require.required:
|
||||
continue
|
||||
require.require()
|
||||
|
||||
def has_side_effects(self):
|
||||
return self.required
|
||||
|
||||
|
||||
class RawExpression(Expression):
|
||||
def __init__(self, text):
|
||||
super(RawExpression, self).__init__()
|
||||
self.text = text
|
||||
|
||||
def __str__(self):
|
||||
return str(self.text)
|
||||
|
||||
|
||||
# pylint: disable=redefined-builtin
|
||||
class AssignmentExpression(Expression):
|
||||
def __init__(self, type, modifier, name, rhs, obj):
|
||||
super(AssignmentExpression, self).__init__()
|
||||
self.type = type
|
||||
self.modifier = modifier
|
||||
self.name = name
|
||||
self.rhs = safe_exp(rhs)
|
||||
self.requires.append(self.rhs)
|
||||
self.obj = obj
|
||||
|
||||
def __str__(self):
|
||||
type_ = self.type
|
||||
return u"{} {}{} = {}".format(type_, self.modifier, self.name, self.rhs)
|
||||
|
||||
def has_side_effects(self):
|
||||
return self.rhs.has_side_effects()
|
||||
|
||||
|
||||
class ExpressionList(Expression):
|
||||
def __init__(self, *args):
|
||||
super(ExpressionList, self).__init__()
|
||||
# Remove every None on end
|
||||
args = list(args)
|
||||
while args and args[-1] is None:
|
||||
args.pop()
|
||||
self.args = []
|
||||
for arg in args:
|
||||
exp = safe_exp(arg)
|
||||
self.requires.append(exp)
|
||||
self.args.append(exp)
|
||||
|
||||
def __str__(self):
|
||||
text = u", ".join(unicode(x) for x in self.args)
|
||||
return indent_all_but_first_and_last(text)
|
||||
|
||||
|
||||
class TemplateArguments(Expression):
|
||||
def __init__(self, *args):
|
||||
super(TemplateArguments, self).__init__()
|
||||
self.args = ExpressionList(*args)
|
||||
self.requires.append(self.args)
|
||||
|
||||
def __str__(self):
|
||||
return u'<{}>'.format(self.args)
|
||||
|
||||
|
||||
class CallExpression(Expression):
|
||||
def __init__(self, base, *args):
|
||||
super(CallExpression, self).__init__()
|
||||
self.base = base
|
||||
if args and isinstance(args[0], TemplateArguments):
|
||||
self.template_args = args[0]
|
||||
self.requires.append(self.template_args)
|
||||
args = args[1:]
|
||||
else:
|
||||
self.template_args = None
|
||||
self.args = ExpressionList(*args)
|
||||
self.requires.append(self.args)
|
||||
|
||||
def __str__(self):
|
||||
if self.template_args is not None:
|
||||
return u'{}{}({})'.format(self.base, self.template_args, self.args)
|
||||
return u'{}({})'.format(self.base, self.args)
|
||||
|
||||
|
||||
class StructInitializer(Expression):
|
||||
def __init__(self, base, *args):
|
||||
super(StructInitializer, self).__init__()
|
||||
self.base = base
|
||||
if isinstance(base, Expression):
|
||||
self.requires.append(base)
|
||||
if not isinstance(args, OrderedDict):
|
||||
args = OrderedDict(args)
|
||||
self.args = OrderedDict()
|
||||
for key, value in args.iteritems():
|
||||
if value is None:
|
||||
continue
|
||||
exp = safe_exp(value)
|
||||
self.args[key] = exp
|
||||
self.requires.append(exp)
|
||||
|
||||
def __str__(self):
|
||||
cpp = u'{}{{\n'.format(self.base)
|
||||
for key, value in self.args.iteritems():
|
||||
cpp += u' .{} = {},\n'.format(key, value)
|
||||
cpp += u'}'
|
||||
return cpp
|
||||
|
||||
|
||||
class ArrayInitializer(Expression):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ArrayInitializer, self).__init__()
|
||||
self.multiline = kwargs.get('multiline', True)
|
||||
self.args = []
|
||||
for arg in args:
|
||||
if arg is None:
|
||||
continue
|
||||
exp = safe_exp(arg)
|
||||
self.args.append(exp)
|
||||
self.requires.append(exp)
|
||||
|
||||
def __str__(self):
|
||||
if not self.args:
|
||||
return u'{}'
|
||||
if self.multiline:
|
||||
cpp = u'{\n'
|
||||
for arg in self.args:
|
||||
cpp += u' {},\n'.format(arg)
|
||||
cpp += u'}'
|
||||
else:
|
||||
cpp = u'{' + u', '.join(str(arg) for arg in self.args) + u'}'
|
||||
return cpp
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class ParameterExpression(Expression):
|
||||
def __init__(self, type, id):
|
||||
super(ParameterExpression, self).__init__()
|
||||
self.type = type
|
||||
self.id = id
|
||||
|
||||
def __str__(self):
|
||||
return u"{} {}".format(self.type, self.id)
|
||||
|
||||
|
||||
class ParameterListExpression(Expression):
|
||||
def __init__(self, *parameters):
|
||||
super(ParameterListExpression, self).__init__()
|
||||
self.parameters = []
|
||||
for parameter in parameters:
|
||||
if not isinstance(parameter, ParameterExpression):
|
||||
parameter = ParameterExpression(*parameter)
|
||||
self.parameters.append(parameter)
|
||||
self.requires.append(parameter)
|
||||
|
||||
def __str__(self):
|
||||
return u", ".join(unicode(x) for x in self.parameters)
|
||||
|
||||
|
||||
class LambdaExpression(Expression):
|
||||
def __init__(self, parts, parameters, capture='=', return_type=None):
|
||||
super(LambdaExpression, self).__init__()
|
||||
self.parts = parts
|
||||
if not isinstance(parameters, ParameterListExpression):
|
||||
parameters = ParameterListExpression(*parameters)
|
||||
self.parameters = parameters
|
||||
self.requires.append(self.parameters)
|
||||
self.capture = capture
|
||||
self.return_type = return_type
|
||||
if return_type is not None:
|
||||
self.requires.append(return_type)
|
||||
for i in range(1, len(parts), 3):
|
||||
self.requires.append(parts[i])
|
||||
|
||||
def __str__(self):
|
||||
cpp = u'[{}]({})'.format(self.capture, self.parameters)
|
||||
if self.return_type is not None:
|
||||
cpp += u' -> {}'.format(self.return_type)
|
||||
cpp += u' {{\n{}\n}}'.format(self.content)
|
||||
return indent_all_but_first_and_last(cpp)
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
return u''.join(unicode(part) for part in self.parts)
|
||||
|
||||
|
||||
class Literal(Expression):
|
||||
def __str__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
# From https://stackoverflow.com/a/14945195/8924614
|
||||
def cpp_string_escape(string, encoding='utf-8'):
|
||||
if isinstance(string, unicode):
|
||||
@@ -257,477 +49,29 @@ def cpp_string_escape(string, encoding='utf-8'):
|
||||
return '"' + result + '"'
|
||||
|
||||
|
||||
class StringLiteral(Literal):
|
||||
def __init__(self, string):
|
||||
super(StringLiteral, self).__init__()
|
||||
self.string = string
|
||||
|
||||
def __str__(self):
|
||||
return u'{}'.format(cpp_string_escape(self.string))
|
||||
|
||||
|
||||
class IntLiteral(Literal):
|
||||
def __init__(self, i):
|
||||
super(IntLiteral, self).__init__()
|
||||
self.i = i
|
||||
|
||||
def __str__(self):
|
||||
if self.i > 4294967295:
|
||||
return u'{}ULL'.format(self.i)
|
||||
if self.i > 2147483647:
|
||||
return u'{}UL'.format(self.i)
|
||||
if self.i < -2147483648:
|
||||
return u'{}LL'.format(self.i)
|
||||
return unicode(self.i)
|
||||
|
||||
|
||||
class BoolLiteral(Literal):
|
||||
def __init__(self, binary):
|
||||
super(BoolLiteral, self).__init__()
|
||||
self.binary = binary
|
||||
|
||||
def __str__(self):
|
||||
return u"true" if self.binary else u"false"
|
||||
|
||||
|
||||
class HexIntLiteral(Literal):
|
||||
def __init__(self, i):
|
||||
super(HexIntLiteral, self).__init__()
|
||||
self.i = HexInt(i)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.i)
|
||||
|
||||
|
||||
class FloatLiteral(Literal):
|
||||
def __init__(self, value):
|
||||
super(FloatLiteral, self).__init__()
|
||||
self.float_ = value
|
||||
|
||||
def __str__(self):
|
||||
return u"{:f}f".format(self.float_)
|
||||
|
||||
|
||||
def safe_exp(obj):
|
||||
if isinstance(obj, Expression):
|
||||
return obj
|
||||
elif isinstance(obj, bool):
|
||||
return BoolLiteral(obj)
|
||||
elif isinstance(obj, (str, unicode)):
|
||||
return StringLiteral(obj)
|
||||
elif isinstance(obj, HexInt):
|
||||
return HexIntLiteral(obj)
|
||||
elif isinstance(obj, (int, long)):
|
||||
return IntLiteral(obj)
|
||||
elif isinstance(obj, float):
|
||||
return FloatLiteral(obj)
|
||||
elif isinstance(obj, TimePeriodMicroseconds):
|
||||
return IntLiteral(int(obj.total_microseconds))
|
||||
elif isinstance(obj, TimePeriodMilliseconds):
|
||||
return IntLiteral(int(obj.total_milliseconds))
|
||||
elif isinstance(obj, TimePeriodSeconds):
|
||||
return IntLiteral(int(obj.total_seconds))
|
||||
raise ValueError(u"Object is not an expression", obj)
|
||||
|
||||
|
||||
class Statement(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class RawStatement(Statement):
|
||||
def __init__(self, text):
|
||||
super(RawStatement, self).__init__()
|
||||
self.text = text
|
||||
|
||||
def __str__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
class ExpressionStatement(Statement):
|
||||
def __init__(self, expression):
|
||||
super(ExpressionStatement, self).__init__()
|
||||
self.expression = safe_exp(expression)
|
||||
|
||||
def __str__(self):
|
||||
return u"{};".format(self.expression)
|
||||
|
||||
|
||||
def statement(expression):
|
||||
if isinstance(expression, Statement):
|
||||
return expression
|
||||
return ExpressionStatement(expression)
|
||||
|
||||
|
||||
def register_variable(id, obj):
|
||||
_LOGGER.debug("Registered variable %s of type %s", id.id, id.type)
|
||||
_VARIABLES[id] = obj
|
||||
|
||||
|
||||
# pylint: disable=redefined-builtin, invalid-name
|
||||
def variable(id, rhs, type=None):
|
||||
rhs = safe_exp(rhs)
|
||||
obj = MockObj(id, u'.')
|
||||
id.type = type or id.type
|
||||
assignment = AssignmentExpression(id.type, '', id, rhs, obj)
|
||||
add(assignment)
|
||||
register_variable(id, obj)
|
||||
obj.requires.append(assignment)
|
||||
return obj
|
||||
|
||||
|
||||
def Pvariable(id, rhs, has_side_effects=True, type=None):
|
||||
rhs = safe_exp(rhs)
|
||||
if not has_side_effects and hasattr(rhs, '_has_side_effects'):
|
||||
# pylint: disable=attribute-defined-outside-init, protected-access
|
||||
rhs._has_side_effects = False
|
||||
obj = MockObj(id, u'->', has_side_effects=has_side_effects)
|
||||
id.type = type or id.type
|
||||
assignment = AssignmentExpression(id.type, '*', id, rhs, obj)
|
||||
add(assignment)
|
||||
register_variable(id, obj)
|
||||
obj.requires.append(assignment)
|
||||
return obj
|
||||
|
||||
|
||||
_TASKS = deque()
|
||||
_VARIABLES = {}
|
||||
_EXPRESSIONS = []
|
||||
|
||||
|
||||
def get_variable(id):
|
||||
while True:
|
||||
if id in _VARIABLES:
|
||||
yield _VARIABLES[id]
|
||||
return
|
||||
_LOGGER.debug("Waiting for variable %s", id)
|
||||
yield None
|
||||
|
||||
|
||||
def get_variable_with_full_id(id):
|
||||
while True:
|
||||
for k, v in _VARIABLES.iteritems():
|
||||
if k == id:
|
||||
yield (k, v)
|
||||
return
|
||||
_LOGGER.debug("Waiting for variable %s", id)
|
||||
yield None, None
|
||||
|
||||
|
||||
def process_lambda(value, parameters, capture='=', return_type=None):
|
||||
from esphomeyaml.components.globals import GlobalVariableComponent
|
||||
|
||||
if value is None:
|
||||
yield
|
||||
return
|
||||
parts = value.parts[:]
|
||||
for i, id in enumerate(value.requires_ids):
|
||||
for full_id, var in get_variable_with_full_id(id):
|
||||
yield
|
||||
if full_id is not None and isinstance(full_id.type, MockObjClass) and \
|
||||
full_id.type.inherits_from(GlobalVariableComponent):
|
||||
parts[i * 3 + 1] = var.value()
|
||||
continue
|
||||
|
||||
if parts[i * 3 + 2] == '.':
|
||||
parts[i * 3 + 1] = var._
|
||||
else:
|
||||
parts[i * 3 + 1] = var
|
||||
parts[i * 3 + 2] = ''
|
||||
yield LambdaExpression(parts, parameters, capture, return_type)
|
||||
|
||||
|
||||
def templatable(value, input_type, output_type):
|
||||
if isinstance(value, Lambda):
|
||||
lambda_ = None
|
||||
for lambda_ in process_lambda(value, [(input_type, 'x')], return_type=output_type):
|
||||
yield None
|
||||
yield lambda_
|
||||
else:
|
||||
yield value
|
||||
|
||||
|
||||
def add_job(func, *args, **kwargs):
|
||||
domain = kwargs.get('domain')
|
||||
if inspect.isgeneratorfunction(func):
|
||||
def func_():
|
||||
yield
|
||||
for _ in func(*args):
|
||||
yield
|
||||
else:
|
||||
def func_():
|
||||
yield
|
||||
func(*args)
|
||||
gen = func_()
|
||||
_TASKS.append((gen, domain))
|
||||
return gen
|
||||
|
||||
|
||||
def flush_tasks():
|
||||
i = 0
|
||||
while _TASKS:
|
||||
i += 1
|
||||
if i > 1000000:
|
||||
raise ESPHomeYAMLError("Circular dependency detected!")
|
||||
|
||||
task, domain = _TASKS.popleft()
|
||||
_LOGGER.debug("Executing task for domain=%s", domain)
|
||||
try:
|
||||
task.next()
|
||||
_TASKS.append((task, domain))
|
||||
except StopIteration:
|
||||
_LOGGER.debug(" -> %s finished", domain)
|
||||
|
||||
|
||||
def add(expression, require=True):
|
||||
if require and isinstance(expression, Expression):
|
||||
expression.require()
|
||||
_EXPRESSIONS.append(expression)
|
||||
_LOGGER.debug("Adding: %s", statement(expression))
|
||||
return expression
|
||||
|
||||
|
||||
class MockObj(Expression):
|
||||
def __init__(self, base, op=u'.', has_side_effects=True):
|
||||
self.base = base
|
||||
self.op = op
|
||||
self._has_side_effects = has_side_effects
|
||||
super(MockObj, self).__init__()
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr == u'_':
|
||||
obj = MockObj(u'{}{}'.format(self.base, self.op))
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
if attr == u'new':
|
||||
obj = MockObj(u'new {}'.format(self.base), u'->')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
next_op = u'.'
|
||||
if attr.startswith(u'P') and self.op not in ['::', '']:
|
||||
attr = attr[1:]
|
||||
next_op = u'->'
|
||||
if attr.startswith(u'_'):
|
||||
attr = attr[1:]
|
||||
obj = MockObj(u'{}{}{}'.format(self.base, self.op, attr), next_op)
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
call = CallExpression(self.base, *args)
|
||||
obj = MockObj(call, self.op)
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(call)
|
||||
return obj
|
||||
|
||||
def __str__(self):
|
||||
return unicode(self.base)
|
||||
|
||||
def require(self):
|
||||
self.required = True
|
||||
for require in self.requires:
|
||||
if require.required:
|
||||
continue
|
||||
require.require()
|
||||
|
||||
def template(self, args):
|
||||
if not isinstance(args, TemplateArguments):
|
||||
args = TemplateArguments(args)
|
||||
obj = MockObj(u'{}{}'.format(self.base, args))
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(args)
|
||||
return obj
|
||||
|
||||
def namespace(self, name):
|
||||
obj = MockObj(u'{}{}{}'.format(self.base, self.op, name), u'::')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
|
||||
def class_(self, name, *parents):
|
||||
obj = MockObjClass(u'{}::{}'.format(self.base, name), u'.', parents=parents)
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
|
||||
def struct(self, name):
|
||||
return self.class_(name)
|
||||
|
||||
def enum(self, name, is_class=False):
|
||||
if is_class:
|
||||
return self.namespace(name)
|
||||
|
||||
return self
|
||||
|
||||
def operator(self, name):
|
||||
if name == 'ref':
|
||||
obj = MockObj(u'{} &'.format(self.base), u'')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
if name == "const":
|
||||
obj = MockObj(u'const {}'.format(self.base), u'')
|
||||
obj.requires.append(self)
|
||||
return obj
|
||||
raise NotImplementedError()
|
||||
|
||||
def has_side_effects(self):
|
||||
return self._has_side_effects
|
||||
|
||||
def __getitem__(self, item):
|
||||
next_op = u'.'
|
||||
if isinstance(item, str) and item.startswith(u'P'):
|
||||
item = item[1:]
|
||||
next_op = u'->'
|
||||
obj = MockObj(u'{}[{}]'.format(self.base, item), next_op)
|
||||
obj.requires.append(self)
|
||||
if isinstance(item, Expression):
|
||||
obj.requires.append(item)
|
||||
return obj
|
||||
|
||||
|
||||
class MockObjClass(MockObj):
|
||||
def __init__(self, *args, **kwargs):
|
||||
parens = kwargs.pop('parents')
|
||||
MockObj.__init__(self, *args, **kwargs)
|
||||
self._parents = []
|
||||
for paren in parens:
|
||||
if not isinstance(paren, MockObjClass):
|
||||
raise ValueError
|
||||
self._parents.append(paren)
|
||||
# pylint: disable=protected-access
|
||||
self._parents += paren._parents
|
||||
|
||||
def inherits_from(self, other):
|
||||
if self == other:
|
||||
return True
|
||||
for parent in self._parents:
|
||||
if parent == other:
|
||||
return True
|
||||
return False
|
||||
|
||||
def template(self, args):
|
||||
if not isinstance(args, TemplateArguments):
|
||||
args = TemplateArguments(args)
|
||||
new_parents = self._parents[:]
|
||||
new_parents.append(self)
|
||||
obj = MockObjClass(u'{}{}'.format(self.base, args), parents=new_parents)
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(args)
|
||||
return obj
|
||||
|
||||
|
||||
global_ns = MockObj('', '')
|
||||
float_ = global_ns.namespace('float')
|
||||
bool_ = global_ns.namespace('bool')
|
||||
std_ns = global_ns.namespace('std')
|
||||
std_string = std_ns.string
|
||||
uint8 = global_ns.namespace('uint8_t')
|
||||
uint16 = global_ns.namespace('uint16_t')
|
||||
uint32 = global_ns.namespace('uint32_t')
|
||||
int32 = global_ns.namespace('int32_t')
|
||||
const_char_p = global_ns.namespace('const char *')
|
||||
NAN = global_ns.namespace('NAN')
|
||||
esphomelib_ns = global_ns # using namespace esphomelib;
|
||||
NoArg = esphomelib_ns.NoArg
|
||||
App = esphomelib_ns.App
|
||||
io_ns = esphomelib_ns.namespace('io')
|
||||
Nameable = esphomelib_ns.class_('Nameable')
|
||||
Trigger = esphomelib_ns.class_('Trigger')
|
||||
Action = esphomelib_ns.class_('Action')
|
||||
Component = esphomelib_ns.class_('Component')
|
||||
PollingComponent = esphomelib_ns.class_('PollingComponent', Component)
|
||||
Application = esphomelib_ns.class_('Application')
|
||||
optional = esphomelib_ns.class_('optional')
|
||||
arduino_json_ns = global_ns.namespace('ArduinoJson')
|
||||
JsonObject = arduino_json_ns.class_('JsonObject')
|
||||
JsonObjectRef = JsonObject.operator('ref')
|
||||
JsonObjectConstRef = JsonObjectRef.operator('const')
|
||||
Controller = esphomelib_ns.class_('Controller')
|
||||
StoringController = esphomelib_ns.class_('StoringController', Controller)
|
||||
|
||||
GPIOPin = esphomelib_ns.class_('GPIOPin')
|
||||
GPIOOutputPin = esphomelib_ns.class_('GPIOOutputPin', GPIOPin)
|
||||
GPIOInputPin = esphomelib_ns.class_('GPIOInputPin', GPIOPin)
|
||||
|
||||
|
||||
def get_gpio_pin_number(conf):
|
||||
if isinstance(conf, int):
|
||||
return conf
|
||||
return conf[CONF_NUMBER]
|
||||
|
||||
|
||||
def generic_gpio_pin_expression_(conf, mock_obj, default_mode):
|
||||
if conf is None:
|
||||
return
|
||||
number = conf[CONF_NUMBER]
|
||||
inverted = conf.get(CONF_INVERTED)
|
||||
if CONF_PCF8574 in conf:
|
||||
hub = None
|
||||
for hub in get_variable(conf[CONF_PCF8574]):
|
||||
yield None
|
||||
if default_mode == u'INPUT':
|
||||
mode = conf.get(CONF_MODE, u'INPUT')
|
||||
yield hub.make_input_pin(number,
|
||||
RawExpression('PCF8574_' + mode),
|
||||
inverted)
|
||||
return
|
||||
elif default_mode == u'OUTPUT':
|
||||
yield hub.make_output_pin(number, inverted)
|
||||
return
|
||||
else:
|
||||
raise ESPHomeYAMLError(u"Unknown default mode {}".format(default_mode))
|
||||
if len(conf) == 1:
|
||||
yield IntLiteral(number)
|
||||
return
|
||||
mode = RawExpression(conf.get(CONF_MODE, default_mode))
|
||||
yield mock_obj(number, mode, inverted)
|
||||
|
||||
|
||||
def gpio_output_pin_expression(conf):
|
||||
exp = None
|
||||
for exp in generic_gpio_pin_expression_(conf, GPIOOutputPin, 'OUTPUT'):
|
||||
yield None
|
||||
yield exp
|
||||
|
||||
|
||||
def gpio_input_pin_expression(conf):
|
||||
exp = None
|
||||
for exp in generic_gpio_pin_expression_(conf, GPIOInputPin, 'INPUT'):
|
||||
yield None
|
||||
yield exp
|
||||
|
||||
|
||||
def setup_mqtt_component(obj, config):
|
||||
if CONF_RETAIN in config:
|
||||
add(obj.set_retain(config[CONF_RETAIN]))
|
||||
if not config.get(CONF_DISCOVERY, True):
|
||||
add(obj.disable_discovery())
|
||||
if CONF_STATE_TOPIC in config:
|
||||
add(obj.set_custom_state_topic(config[CONF_STATE_TOPIC]))
|
||||
if CONF_COMMAND_TOPIC in config:
|
||||
add(obj.set_custom_command_topic(config[CONF_COMMAND_TOPIC]))
|
||||
if CONF_AVAILABILITY in config:
|
||||
availability = config[CONF_AVAILABILITY]
|
||||
if not availability:
|
||||
add(obj.disable_availability())
|
||||
else:
|
||||
add(obj.set_availability(availability[CONF_TOPIC], availability[CONF_PAYLOAD_AVAILABLE],
|
||||
availability[CONF_PAYLOAD_NOT_AVAILABLE]))
|
||||
|
||||
|
||||
def setup_component(obj, config):
|
||||
if CONF_SETUP_PRIORITY in config:
|
||||
add(obj.set_setup_priority(config[CONF_SETUP_PRIORITY]))
|
||||
|
||||
|
||||
def color(the_color, message='', reset=None):
|
||||
"""Color helper."""
|
||||
def color(the_color, message=''):
|
||||
from colorlog.escape_codes import escape_codes, parse_colors
|
||||
|
||||
if not message:
|
||||
return parse_colors(the_color)
|
||||
return parse_colors(the_color) + message + escape_codes[reset or 'reset']
|
||||
res = parse_colors(the_color)
|
||||
else:
|
||||
res = parse_colors(the_color) + message + escape_codes['reset']
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def relative_path(path):
|
||||
return os.path.join(os.path.dirname(core.CONFIG_PATH), os.path.expanduser(path))
|
||||
def run_system_command(*args):
|
||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
rc = p.returncode
|
||||
return rc, stdout, stderr
|
||||
|
||||
|
||||
def mkdir_p(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EEXIST and os.path.isdir(path):
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from datetime import datetime
|
||||
import hashlib
|
||||
import logging
|
||||
import socket
|
||||
import ssl
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.const import CONF_BROKER, CONF_DISCOVERY_PREFIX, CONF_ESPHOMEYAML, \
|
||||
CONF_LOG_TOPIC, \
|
||||
CONF_MQTT, CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_TOPIC_PREFIX, \
|
||||
CONF_USERNAME, CONF_TOPIC, CONF_SSL_FINGERPRINTS
|
||||
CONF_LOG_TOPIC, CONF_MQTT, CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_SSL_FINGERPRINTS, \
|
||||
CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_USERNAME
|
||||
from esphomeyaml.core import CORE, EsphomeyamlError
|
||||
from esphomeyaml.helpers import color
|
||||
from esphomeyaml.util import safe_print
|
||||
|
||||
@@ -24,9 +25,30 @@ def initialize(config, subscriptions, on_message, username, password, client_id)
|
||||
for topic in subscriptions:
|
||||
client.subscribe(topic)
|
||||
|
||||
def on_disconnect(client, userdata, result_code):
|
||||
if result_code == 0:
|
||||
return
|
||||
|
||||
tries = 0
|
||||
while True:
|
||||
try:
|
||||
if client.reconnect() == 0:
|
||||
_LOGGER.info("Successfully reconnected to the MQTT server")
|
||||
break
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
wait_time = min(2**tries, 300)
|
||||
_LOGGER.warning(
|
||||
"Disconnected from MQTT (%s). Trying to reconnect in %s s",
|
||||
result_code, wait_time)
|
||||
time.sleep(wait_time)
|
||||
tries += 1
|
||||
|
||||
client = mqtt.Client(client_id or u'')
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.on_disconnect = on_disconnect
|
||||
if username is None:
|
||||
if config[CONF_MQTT].get(CONF_USERNAME):
|
||||
client.username_pw_set(config[CONF_MQTT][CONF_USERNAME],
|
||||
@@ -41,7 +63,11 @@ def initialize(config, subscriptions, on_message, username, password, client_id)
|
||||
tls_version = ssl.PROTOCOL_SSLv23
|
||||
client.tls_set(ca_certs=None, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED,
|
||||
tls_version=tls_version, ciphers=None)
|
||||
client.connect(config[CONF_MQTT][CONF_BROKER], config[CONF_MQTT][CONF_PORT])
|
||||
|
||||
try:
|
||||
client.connect(config[CONF_MQTT][CONF_BROKER], config[CONF_MQTT][CONF_PORT])
|
||||
except socket.error as err:
|
||||
raise EsphomeyamlError("Cannot connect to MQTT broker: {}".format(err))
|
||||
|
||||
try:
|
||||
client.loop_forever()
|
||||
@@ -50,7 +76,7 @@ def initialize(config, subscriptions, on_message, username, password, client_id)
|
||||
return 0
|
||||
|
||||
|
||||
def show_logs(config, topic=None, username=None, password=None, client_id=None, escape=False):
|
||||
def show_logs(config, topic=None, username=None, password=None, client_id=None):
|
||||
if topic is not None:
|
||||
pass # already have topic
|
||||
elif CONF_MQTT in config:
|
||||
@@ -67,10 +93,8 @@ def show_logs(config, topic=None, username=None, password=None, client_id=None,
|
||||
_LOGGER.info(u"Starting log output from %s", topic)
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
time = datetime.now().time().strftime(u'[%H:%M:%S]')
|
||||
message = time + msg.payload
|
||||
if escape:
|
||||
message = message.replace('\033', '\\033')
|
||||
time_ = datetime.now().time().strftime(u'[%H:%M:%S]')
|
||||
message = time_ + msg.payload
|
||||
safe_print(message)
|
||||
|
||||
return initialize(config, [topic], on_message, username, password, client_id)
|
||||
@@ -113,5 +137,5 @@ def get_fingerprint(config):
|
||||
|
||||
safe_print(u"SHA1 Fingerprint: " + color('cyan', sha1))
|
||||
safe_print(u"Copy the string above into mqtt.ssl_fingerprints section of {}"
|
||||
u"".format(core.CONFIG_PATH))
|
||||
u"".format(CORE.config_path))
|
||||
return 0
|
||||
|
||||
@@ -2,11 +2,10 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import core
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_INVERTED, CONF_MODE, CONF_NUMBER, CONF_PCF8574, \
|
||||
ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.helpers import Component, esphomelib_ns, io_ns
|
||||
from esphomeyaml.const import CONF_INVERTED, CONF_MODE, CONF_NUMBER, CONF_PCF8574
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_types import Component, esphomelib_ns, io_ns
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -147,18 +146,18 @@ ESP32_BOARD_PINS = {
|
||||
}
|
||||
|
||||
|
||||
def _lookup_pin(platform, board, value):
|
||||
if platform == ESP_PLATFORM_ESP8266:
|
||||
board_pins = ESP8266_BOARD_PINS.get(board, {})
|
||||
def _lookup_pin(value):
|
||||
if CORE.is_esp8266:
|
||||
board_pins = ESP8266_BOARD_PINS.get(CORE.board, {})
|
||||
base_pins = ESP8266_BASE_PINS
|
||||
elif platform == ESP_PLATFORM_ESP32:
|
||||
board_pins = ESP32_BOARD_PINS.get(board, {})
|
||||
elif CORE.is_esp32:
|
||||
board_pins = ESP32_BOARD_PINS.get(CORE.board, {})
|
||||
base_pins = ESP32_BASE_PINS
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
if isinstance(board_pins, str):
|
||||
return _lookup_pin(platform, board_pins, value)
|
||||
while isinstance(board_pins, str):
|
||||
board_pins = ESP8266_BOARD_PINS.get(board_pins, {})
|
||||
if value in board_pins:
|
||||
return board_pins[value]
|
||||
if value in base_pins:
|
||||
@@ -178,12 +177,12 @@ def _translate_pin(value):
|
||||
pass
|
||||
if value.startswith('GPIO'):
|
||||
return vol.Coerce(int)(value[len('GPIO'):].strip())
|
||||
return _lookup_pin(core.ESP_PLATFORM, core.BOARD, value)
|
||||
return _lookup_pin(value)
|
||||
|
||||
|
||||
def validate_gpio_pin(value):
|
||||
value = _translate_pin(value)
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
if CORE.is_esp32:
|
||||
if value < 0 or value > 39:
|
||||
raise vol.Invalid(u"ESP32: Invalid pin number: {}".format(value))
|
||||
if 6 <= value <= 11:
|
||||
@@ -193,53 +192,60 @@ def validate_gpio_pin(value):
|
||||
_LOGGER.warning(u"ESP32: Pin %s (20, 24, 28-31) can usually not be used. "
|
||||
u"Be warned.", value)
|
||||
return value
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
elif CORE.is_esp8266:
|
||||
if 6 <= value <= 11:
|
||||
_LOGGER.warning(u"ESP8266: Pin %s (6-11) might already be used by the "
|
||||
u"flash interface. Be warned.", value)
|
||||
if value < 0 or value > 17:
|
||||
raise vol.Invalid(u"ESP8266: Invalid pin number: {}".format(value))
|
||||
return value
|
||||
raise vol.Invalid(u"Invalid ESP platform.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def input_pin(value):
|
||||
value = validate_gpio_pin(value)
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
return validate_gpio_pin(value)
|
||||
|
||||
|
||||
def input_pullup_pin(value):
|
||||
value = input_pin(value)
|
||||
if CORE.is_esp32:
|
||||
return output_pin(value)
|
||||
elif CORE.is_esp8266:
|
||||
if value == 0:
|
||||
raise vol.Invalid("GPIO Pin 0 does not support pullup pin mode. "
|
||||
"Please choose another pin.")
|
||||
return value
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
return value
|
||||
raise vol.Invalid(u"Invalid ESP platform.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def output_pin(value):
|
||||
value = validate_gpio_pin(value)
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
if CORE.is_esp32:
|
||||
if 34 <= value <= 39:
|
||||
raise vol.Invalid(u"ESP32: Pin {} (34-39) can only be used as "
|
||||
u"input pins.".format(value))
|
||||
raise vol.Invalid(u"ESP32: GPIO{} (34-39) can only be used as an "
|
||||
u"input pin.".format(value))
|
||||
return value
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
elif CORE.is_esp8266:
|
||||
return value
|
||||
raise vol.Invalid("Invalid ESP platform.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def analog_pin(value):
|
||||
value = validate_gpio_pin(value)
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
if CORE.is_esp32:
|
||||
if 32 <= value <= 39: # ADC1
|
||||
return value
|
||||
raise vol.Invalid(u"ESP32: Only pins 32 though 39 support ADC.")
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
elif CORE.is_esp8266:
|
||||
if value == 17: # A0
|
||||
return value
|
||||
raise vol.Invalid(u"ESP8266: Only pin A0 (17) supports ADC.")
|
||||
raise vol.Invalid(u"Invalid ESP platform.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
input_output_pin = vol.All(input_pin, output_pin)
|
||||
gpio_pin = vol.Any(input_pin, output_pin)
|
||||
|
||||
|
||||
PIN_MODES_ESP8266 = [
|
||||
'INPUT', 'OUTPUT', 'INPUT_PULLUP', 'OUTPUT_OPEN_DRAIN', 'SPECIAL', 'FUNCTION_1',
|
||||
'FUNCTION_2', 'FUNCTION_3', 'FUNCTION_4',
|
||||
@@ -254,11 +260,11 @@ PIN_MODES_ESP32 = [
|
||||
|
||||
|
||||
def pin_mode(value):
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
if CORE.is_esp32:
|
||||
return cv.one_of(*PIN_MODES_ESP32, upper=True)(value)
|
||||
elif core.ESP_PLATFORM == ESP_PLATFORM_ESP8266:
|
||||
elif CORE.is_esp8266:
|
||||
return cv.one_of(*PIN_MODES_ESP8266, upper=True)(value)
|
||||
raise vol.Invalid(u"Invalid ESP platform.")
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
GPIO_FULL_OUTPUT_PIN_SCHEMA = vol.Schema({
|
||||
@@ -284,6 +290,11 @@ def shorthand_input_pin(value):
|
||||
return {CONF_NUMBER: value}
|
||||
|
||||
|
||||
def shorthand_input_pullup_pin(value):
|
||||
value = input_pullup_pin(value)
|
||||
return {CONF_NUMBER: value}
|
||||
|
||||
|
||||
I2CDevice = esphomelib_ns.class_('I2CDevice')
|
||||
PCF8574Component = io_ns.class_('PCF8574Component', Component, I2CDevice)
|
||||
|
||||
@@ -306,11 +317,9 @@ def internal_gpio_output_pin_schema(value):
|
||||
|
||||
|
||||
def gpio_output_pin_schema(value):
|
||||
if isinstance(value, dict):
|
||||
if CONF_PCF8574 in value:
|
||||
return PCF8574_OUTPUT_PIN_SCHEMA(value)
|
||||
return GPIO_FULL_OUTPUT_PIN_SCHEMA(value)
|
||||
return shorthand_output_pin(value)
|
||||
if isinstance(value, dict) and CONF_PCF8574 in value:
|
||||
return PCF8574_OUTPUT_PIN_SCHEMA(value)
|
||||
return internal_gpio_output_pin_schema(value)
|
||||
|
||||
|
||||
def internal_gpio_input_pin_schema(value):
|
||||
@@ -320,8 +329,18 @@ def internal_gpio_input_pin_schema(value):
|
||||
|
||||
|
||||
def gpio_input_pin_schema(value):
|
||||
if isinstance(value, dict) and CONF_PCF8574 in value:
|
||||
return PCF8574_INPUT_PIN_SCHEMA(value)
|
||||
return internal_gpio_input_pin_schema(value)
|
||||
|
||||
|
||||
def internal_gpio_input_pullup_pin_schema(value):
|
||||
if isinstance(value, dict):
|
||||
if CONF_PCF8574 in value:
|
||||
return PCF8574_INPUT_PIN_SCHEMA(value)
|
||||
return GPIO_FULL_INPUT_PIN_SCHEMA(value)
|
||||
return shorthand_input_pin(value)
|
||||
return shorthand_input_pullup_pin(value)
|
||||
|
||||
|
||||
def gpio_input_pullup_pin_schema(value):
|
||||
if isinstance(value, dict) and CONF_PCF8574 in value:
|
||||
return PCF8574_INPUT_PIN_SCHEMA(value)
|
||||
return internal_gpio_input_pin_schema(value)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from esphomeyaml.const import CONF_BUILD_PATH, CONF_ESPHOMEYAML
|
||||
from esphomeyaml.helpers import relative_path
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.util import run_external_command
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -13,14 +15,14 @@ _LOGGER = logging.getLogger(__name__)
|
||||
def run_platformio_cli(*args, **kwargs):
|
||||
import platformio.__main__
|
||||
|
||||
os.environ["PLATFORMIO_FORCE_COLOR"] = "true"
|
||||
cmd = ['platformio'] + list(args)
|
||||
return run_external_command(platformio.__main__.main,
|
||||
*cmd, **kwargs)
|
||||
|
||||
|
||||
def run_platformio_cli_run(config, verbose, *args, **kwargs):
|
||||
build_path = relative_path(config[CONF_ESPHOMEYAML][CONF_BUILD_PATH])
|
||||
command = ['run', '-d', build_path]
|
||||
command = ['run', '-d', CORE.build_path]
|
||||
if verbose:
|
||||
command += ['-v']
|
||||
command += list(args)
|
||||
|
||||
296
esphomeyaml/storage_json.py
Normal file
296
esphomeyaml/storage_json.py
Normal file
@@ -0,0 +1,296 @@
|
||||
import binascii
|
||||
import codecs
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
|
||||
from esphomeyaml import const
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.helpers import mkdir_p
|
||||
|
||||
# pylint: disable=unused-import, wrong-import-order
|
||||
from esphomeyaml.core import CoreType # noqa
|
||||
from typing import Any, Dict, Optional # noqa
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def storage_path(): # type: () -> str
|
||||
return CORE.relative_path('.esphomeyaml', '{}.json'.format(CORE.config_filename))
|
||||
|
||||
|
||||
def ext_storage_path(base_path, config_filename): # type: (str, str) -> str
|
||||
return os.path.join(base_path, '.esphomeyaml', '{}.json'.format(config_filename))
|
||||
|
||||
|
||||
def esphomeyaml_storage_path(base_path): # type: (str) -> str
|
||||
return os.path.join(base_path, '.esphomeyaml', 'esphomeyaml.json')
|
||||
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
class StorageJSON(object):
|
||||
def __init__(self, storage_version, name, esphomelib_version, esphomeyaml_version,
|
||||
src_version, arduino_version, address, esp_platform, board, build_path,
|
||||
firmware_bin_path, use_legacy_ota):
|
||||
# Version of the storage JSON schema
|
||||
assert storage_version is None or isinstance(storage_version, int)
|
||||
self.storage_version = storage_version # type: int
|
||||
# The name of the node
|
||||
self.name = name # type: str
|
||||
# The esphomelib version in use
|
||||
assert esphomelib_version is None or isinstance(esphomelib_version, dict)
|
||||
self.esphomelib_version = esphomelib_version # type: Dict[str, str]
|
||||
# The esphomeyaml version this was compiled with
|
||||
self.esphomeyaml_version = esphomeyaml_version # type: str
|
||||
# The version of the file in src/main.cpp - Used to migrate the file
|
||||
assert src_version is None or isinstance(src_version, int)
|
||||
self.src_version = src_version # type: int
|
||||
# The version of the Arduino framework, the build files need to be cleared each time
|
||||
# this changes
|
||||
self.arduino_version = arduino_version # type: str
|
||||
# Address of the ESP, for example livingroom.local or a static IP
|
||||
self.address = address # type: str
|
||||
# The type of ESP in use, either ESP32 or ESP8266
|
||||
self.esp_platform = esp_platform # type: str
|
||||
# The ESP board used, for example nodemcuv2
|
||||
self.board = board # type: str
|
||||
# The absolute path to the platformio project
|
||||
self.build_path = build_path # type: str
|
||||
# The absolute path to the firmware binary
|
||||
self.firmware_bin_path = firmware_bin_path # type: str
|
||||
# Whether to use legacy OTA, will be off after the first successful flash
|
||||
self.use_legacy_ota = use_legacy_ota
|
||||
|
||||
def as_dict(self):
|
||||
return {
|
||||
'storage_version': self.storage_version,
|
||||
'name': self.name,
|
||||
'esphomelib_version': self.esphomelib_version,
|
||||
'esphomeyaml_version': self.esphomeyaml_version,
|
||||
'src_version': self.src_version,
|
||||
'arduino_version': self.arduino_version,
|
||||
'address': self.address,
|
||||
'esp_platform': self.esp_platform,
|
||||
'board': self.board,
|
||||
'build_path': self.build_path,
|
||||
'firmware_bin_path': self.firmware_bin_path,
|
||||
'use_legacy_ota': self.use_legacy_ota,
|
||||
}
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.as_dict(), indent=2) + u'\n'
|
||||
|
||||
def save(self, path):
|
||||
mkdir_p(os.path.dirname(path))
|
||||
with codecs.open(path, 'w', encoding='utf-8') as f_handle:
|
||||
f_handle.write(self.to_json())
|
||||
|
||||
@staticmethod
|
||||
def from_esphomeyaml_core(esph, old): # type: (CoreType, Optional[StorageJSON]) -> StorageJSON
|
||||
return StorageJSON(
|
||||
storage_version=1,
|
||||
name=esph.name,
|
||||
esphomelib_version=esph.esphomelib_version,
|
||||
esphomeyaml_version=const.__version__,
|
||||
src_version=1,
|
||||
arduino_version=esph.arduino_version,
|
||||
address=esph.address,
|
||||
esp_platform=esph.esp_platform,
|
||||
board=esph.board,
|
||||
build_path=esph.build_path,
|
||||
firmware_bin_path=esph.firmware_bin,
|
||||
use_legacy_ota=True if old is None else old.use_legacy_ota,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_wizard(name, address, esp_platform, board):
|
||||
# type: (str, str, str, str) -> StorageJSON
|
||||
return StorageJSON(
|
||||
storage_version=1,
|
||||
name=name,
|
||||
esphomelib_version=None,
|
||||
esphomeyaml_version=const.__version__,
|
||||
src_version=1,
|
||||
arduino_version=None,
|
||||
address=address,
|
||||
esp_platform=esp_platform,
|
||||
board=board,
|
||||
build_path=None,
|
||||
firmware_bin_path=None,
|
||||
use_legacy_ota=False,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _load_impl(path): # type: (str) -> Optional[StorageJSON]
|
||||
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
||||
text = f_handle.read()
|
||||
storage = json.loads(text, encoding='utf-8')
|
||||
storage_version = storage['storage_version']
|
||||
name = storage.get('name')
|
||||
esphomelib_version = storage.get('esphomelib_version')
|
||||
esphomeyaml_version = storage.get('esphomeyaml_version')
|
||||
src_version = storage.get('src_version')
|
||||
arduino_version = storage.get('arduino_version')
|
||||
address = storage.get('address')
|
||||
esp_platform = storage.get('esp_platform')
|
||||
board = storage.get('board')
|
||||
build_path = storage.get('build_path')
|
||||
firmware_bin_path = storage.get('firmware_bin_path')
|
||||
use_legacy_ota = storage.get('use_legacy_ota')
|
||||
return StorageJSON(storage_version, name, esphomelib_version, esphomeyaml_version,
|
||||
src_version, arduino_version, address, esp_platform, board, build_path,
|
||||
firmware_bin_path, use_legacy_ota)
|
||||
|
||||
@staticmethod
|
||||
def load(path): # type: (str) -> Optional[StorageJSON]
|
||||
try:
|
||||
return StorageJSON._load_impl(path)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
def __eq__(self, o): # type: (Any) -> bool
|
||||
return isinstance(o, StorageJSON) and self.as_dict() == o.as_dict()
|
||||
|
||||
|
||||
class EsphomeyamlStorageJSON(object):
|
||||
def __init__(self, storage_version, cookie_secret, last_update_check,
|
||||
remote_version):
|
||||
# Version of the storage JSON schema
|
||||
assert storage_version is None or isinstance(storage_version, int)
|
||||
self.storage_version = storage_version # type: int
|
||||
# The cookie secret for the dashboard
|
||||
self.cookie_secret = cookie_secret # type: str
|
||||
# The last time esphomeyaml checked for an update as an isoformat encoded str
|
||||
self.last_update_check_str = last_update_check # type: str
|
||||
# Cache of the version gotten in the last version check
|
||||
self.remote_version = remote_version # type: Optional[str]
|
||||
|
||||
def as_dict(self): # type: () -> dict
|
||||
return {
|
||||
'storage_version': self.storage_version,
|
||||
'cookie_secret': self.cookie_secret,
|
||||
'last_update_check': self.last_update_check_str,
|
||||
'remote_version': self.remote_version,
|
||||
}
|
||||
|
||||
@property
|
||||
def last_update_check(self): # type: () -> Optional[datetime]
|
||||
try:
|
||||
return datetime.strptime(self.last_update_check_str, "%Y-%m-%dT%H:%M:%S")
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
@last_update_check.setter
|
||||
def last_update_check(self, new): # type: (datetime) -> None
|
||||
self.last_update_check_str = new.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
|
||||
def to_json(self): # type: () -> dict
|
||||
return json.dumps(self.as_dict(), indent=2) + u'\n'
|
||||
|
||||
def save(self, path): # type: (str) -> None
|
||||
mkdir_p(os.path.dirname(path))
|
||||
with codecs.open(path, 'w', encoding='utf-8') as f_handle:
|
||||
f_handle.write(self.to_json())
|
||||
|
||||
@staticmethod
|
||||
def _load_impl(path): # type: (str) -> Optional[EsphomeyamlStorageJSON]
|
||||
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
||||
text = f_handle.read()
|
||||
storage = json.loads(text, encoding='utf-8')
|
||||
storage_version = storage['storage_version']
|
||||
cookie_secret = storage.get('cookie_secret')
|
||||
last_update_check = storage.get('last_update_check')
|
||||
remote_version = storage.get('remote_version')
|
||||
return EsphomeyamlStorageJSON(storage_version, cookie_secret, last_update_check,
|
||||
remote_version)
|
||||
|
||||
@staticmethod
|
||||
def load(path): # type: (str) -> Optional[EsphomeyamlStorageJSON]
|
||||
try:
|
||||
return EsphomeyamlStorageJSON._load_impl(path)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_default(): # type: () -> EsphomeyamlStorageJSON
|
||||
return EsphomeyamlStorageJSON(
|
||||
storage_version=1,
|
||||
cookie_secret=binascii.hexlify(os.urandom(64)),
|
||||
last_update_check=None,
|
||||
remote_version=None,
|
||||
)
|
||||
|
||||
def __eq__(self, o): # type: (Any) -> bool
|
||||
return isinstance(o, EsphomeyamlStorageJSON) and self.as_dict() == o.as_dict()
|
||||
|
||||
@property
|
||||
def should_do_esphomeyaml_update_check(self): # type: () -> bool
|
||||
if self.last_update_check is None:
|
||||
return True
|
||||
return self.last_update_check + timedelta(days=3) < datetime.utcnow()
|
||||
|
||||
|
||||
class CheckForUpdateThread(threading.Thread):
|
||||
def __init__(self, path):
|
||||
threading.Thread.__init__(self)
|
||||
self._path = path
|
||||
|
||||
@property
|
||||
def docs_base(self):
|
||||
return 'https://beta.esphomelib.com' if 'b' in const.__version__ else \
|
||||
'https://esphomelib.com'
|
||||
|
||||
def fetch_remote_version(self):
|
||||
import requests
|
||||
|
||||
storage = EsphomeyamlStorageJSON.load(self._path) or \
|
||||
EsphomeyamlStorageJSON.get_default()
|
||||
if not storage.should_do_esphomeyaml_update_check:
|
||||
return storage
|
||||
|
||||
req = requests.get('{}/_static/version'.format(self.docs_base))
|
||||
req.raise_for_status()
|
||||
storage.remote_version = req.text.strip()
|
||||
storage.last_update_check = datetime.utcnow()
|
||||
storage.save(self._path)
|
||||
return storage
|
||||
|
||||
@staticmethod
|
||||
def format_version(ver):
|
||||
vstr = '.'.join(map(str, ver.version))
|
||||
if ver.prerelease:
|
||||
vstr += ver.prerelease[0] + str(ver.prerelease[1])
|
||||
return vstr
|
||||
|
||||
def cmp_versions(self, storage):
|
||||
# pylint: disable=no-name-in-module, import-error
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
remote_version = StrictVersion(storage.remote_version)
|
||||
self_version = StrictVersion(const.__version__)
|
||||
if remote_version > self_version:
|
||||
_LOGGER.warn("*" * 80)
|
||||
_LOGGER.warn("A new version of esphomeyaml is available: %s (this is %s)",
|
||||
self.format_version(remote_version), self.format_version(self_version))
|
||||
_LOGGER.warn("Changelog: %s/esphomeyaml/changelog/index.html", self.docs_base)
|
||||
_LOGGER.warn("Update Instructions: %s/esphomeyaml/guides/faq.html"
|
||||
"#how-do-i-update-to-the-latest-version", self.docs_base)
|
||||
_LOGGER.warn("*" * 80)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
storage = self.fetch_remote_version()
|
||||
self.cmp_versions(storage)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pass
|
||||
|
||||
|
||||
def start_update_check_thread(path):
|
||||
# dummy call to strptime as python 2.7 has a bug with strptime when importing from threads
|
||||
datetime.strptime('20180101', '%Y%m%d')
|
||||
thread = CheckForUpdateThread(path)
|
||||
thread.start()
|
||||
return thread
|
||||
@@ -6,12 +6,12 @@ import unicodedata
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import mqtt
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import ESP_PLATFORMS, ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266
|
||||
from esphomeyaml.helpers import color
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
from esphomeyaml.pins import ESP32_BOARD_PINS, ESP8266_BOARD_PINS
|
||||
from esphomeyaml.storage_json import StorageJSON, ext_storage_path
|
||||
from esphomeyaml.util import safe_print
|
||||
|
||||
CORE_BIG = """ _____ ____ _____ ______
|
||||
@@ -82,6 +82,20 @@ def wizard_file(**kwargs):
|
||||
return config
|
||||
|
||||
|
||||
def wizard_write(path, **kwargs):
|
||||
name = kwargs['name']
|
||||
board = kwargs['board']
|
||||
if 'platform' not in kwargs:
|
||||
kwargs['platform'] = 'ESP8266' if board in ESP8266_BOARD_PINS else 'ESP32'
|
||||
platform = kwargs['platform']
|
||||
|
||||
with codecs.open(path, 'w') as f_handle:
|
||||
f_handle.write(wizard_file(**kwargs))
|
||||
storage = StorageJSON.from_wizard(name, name + '.local', platform, board)
|
||||
storage_path = ext_storage_path(os.path.dirname(path), os.path.basename(path))
|
||||
storage.save(storage_path)
|
||||
|
||||
|
||||
if os.getenv('ESPHOMEYAML_QUICKWIZARD', False):
|
||||
def sleep(time):
|
||||
pass
|
||||
@@ -249,17 +263,7 @@ def wizard(path):
|
||||
safe_print("Please enter the " + color('green', 'address') + " of your MQTT broker.")
|
||||
safe_print()
|
||||
safe_print("For example \"{}\".".format(color('bold_white', '192.168.178.84')))
|
||||
while True:
|
||||
broker = raw_input(color('bold_white', "(broker): "))
|
||||
try:
|
||||
broker = mqtt.validate_broker(broker)
|
||||
break
|
||||
except vol.Invalid as err:
|
||||
safe_print(color('red', u"The broker address \"{}\" seems to be invalid: {} :("
|
||||
u"".format(broker, err)))
|
||||
safe_print("Please try again.")
|
||||
safe_print()
|
||||
sleep(1)
|
||||
broker = raw_input(color('bold_white', "(broker): "))
|
||||
|
||||
safe_print("Thanks! Now enter the " + color('green', 'username') + " and " +
|
||||
color('green', 'password') +
|
||||
@@ -287,13 +291,10 @@ def wizard(path):
|
||||
safe_print("Press ENTER for no password")
|
||||
ota_password = raw_input(color('bold_white', '(password): '))
|
||||
|
||||
config = wizard_file(name=name, platform=platform, board=board,
|
||||
ssid=ssid, psk=psk, broker=broker,
|
||||
mqtt_username=mqtt_username, mqtt_password=mqtt_password,
|
||||
ota_password=ota_password)
|
||||
|
||||
with codecs.open(path, 'w') as f_handle:
|
||||
f_handle.write(config)
|
||||
wizard_write(path=path, name=name, platform=platform, board=board,
|
||||
ssid=ssid, psk=psk, broker=broker,
|
||||
mqtt_username=mqtt_username, mqtt_password=mqtt_password,
|
||||
ota_password=ota_password)
|
||||
|
||||
safe_print()
|
||||
safe_print(color('cyan', "DONE! I've now written a new configuration file to ") +
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import codecs
|
||||
import errno
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.config import iter_components
|
||||
from esphomeyaml.const import ARDUINO_VERSION_ESP32_DEV, CONF_ARDUINO_VERSION, CONF_BOARD, \
|
||||
CONF_BOARD_FLASH_MODE, CONF_ESPHOMELIB_VERSION, CONF_ESPHOMEYAML, CONF_LOCAL, CONF_NAME, \
|
||||
CONF_USE_CUSTOM_CODE, ESP_PLATFORM_ESP32, CONF_REPOSITORY, CONF_COMMIT, CONF_BRANCH, CONF_TAG
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.core_config import VERSION_REGEX
|
||||
from esphomeyaml.helpers import relative_path
|
||||
from esphomeyaml.const import ARDUINO_VERSION_ESP32_DEV, CONF_ARDUINO_VERSION, \
|
||||
CONF_BOARD_FLASH_MODE, CONF_BRANCH, CONF_COMMIT, CONF_ESPHOMELIB_VERSION, CONF_ESPHOMEYAML, \
|
||||
CONF_LOCAL, CONF_REPOSITORY, CONF_TAG, CONF_USE_CUSTOM_CODE
|
||||
from esphomeyaml.core import CORE, EsphomeyamlError
|
||||
from esphomeyaml.core_config import VERSION_REGEX, LIBRARY_URI_REPO, GITHUB_ARCHIVE_ZIP
|
||||
from esphomeyaml.helpers import mkdir_p, run_system_command
|
||||
from esphomeyaml.storage_json import StorageJSON, storage_path
|
||||
from esphomeyaml.util import safe_print
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CPP_AUTO_GENERATE_BEGIN = u'// ========== AUTO GENERATED CODE BEGIN ==========='
|
||||
CPP_AUTO_GENERATE_END = u'// =========== AUTO GENERATED CODE END ============'
|
||||
CPP_INCLUDE_BEGIN = u'// ========== AUTO GENERATED INCLUDE BLOCK BEGIN ==========='
|
||||
CPP_INCLUDE_END = u'// ========== AUTO GENERATED INCLUDE BLOCK END ==========='
|
||||
INI_AUTO_GENERATE_BEGIN = u'; ========== AUTO GENERATED CODE BEGIN ==========='
|
||||
INI_AUTO_GENERATE_END = u'; =========== AUTO GENERATED CODE END ============'
|
||||
|
||||
CPP_BASE_FORMAT = (u"""// Auto generated code by esphomeyaml
|
||||
#include "esphomelib/application.h"
|
||||
|
||||
using namespace esphomelib;
|
||||
""", u""""
|
||||
|
||||
void setup() {
|
||||
// ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
|
||||
@@ -37,7 +38,6 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
App.loop();
|
||||
delay(16);
|
||||
}
|
||||
""")
|
||||
|
||||
@@ -72,9 +72,9 @@ UPLOAD_SPEED_OVERRIDE = {
|
||||
}
|
||||
|
||||
|
||||
def get_build_flags(config, key):
|
||||
def get_build_flags(key):
|
||||
build_flags = set()
|
||||
for _, component, conf in iter_components(config):
|
||||
for _, component, conf in iter_components(CORE.config):
|
||||
if not hasattr(component, key):
|
||||
continue
|
||||
flags = getattr(component, key)
|
||||
@@ -88,48 +88,143 @@ def get_build_flags(config, key):
|
||||
return build_flags
|
||||
|
||||
|
||||
def get_ini_content(config, path):
|
||||
version_specific_settings = determine_platformio_version_settings()
|
||||
options = {
|
||||
u'env': config[CONF_ESPHOMEYAML][CONF_NAME],
|
||||
u'platform': config[CONF_ESPHOMEYAML][CONF_ARDUINO_VERSION],
|
||||
u'board': config[CONF_ESPHOMEYAML][CONF_BOARD],
|
||||
u'build_flags': u'',
|
||||
u'upload_speed': UPLOAD_SPEED_OVERRIDE.get(core.BOARD, 115200),
|
||||
}
|
||||
build_flags = set()
|
||||
if not config[CONF_ESPHOMEYAML][CONF_USE_CUSTOM_CODE]:
|
||||
build_flags |= get_build_flags(config, 'build_flags')
|
||||
build_flags |= get_build_flags(config, 'BUILD_FLAGS')
|
||||
build_flags.add(u"-DESPHOMEYAML_USE")
|
||||
build_flags.add("-Wno-unused-variable")
|
||||
build_flags.add("-Wno-unused-but-set-variable")
|
||||
build_flags |= get_build_flags(config, 'required_build_flags')
|
||||
build_flags |= get_build_flags(config, 'REQUIRED_BUILD_FLAGS')
|
||||
def get_include_text():
|
||||
include_text = u'#include "esphomelib/application.h"\n' \
|
||||
u'using namespace esphomelib;\n'
|
||||
for _, component, conf in iter_components(CORE.config):
|
||||
if not hasattr(component, 'includes'):
|
||||
continue
|
||||
includes = component.includes
|
||||
if callable(includes):
|
||||
includes = includes(conf)
|
||||
if includes is None:
|
||||
continue
|
||||
if isinstance(includes, list):
|
||||
includes = '\n'.join(includes)
|
||||
if not includes:
|
||||
continue
|
||||
include_text += includes + '\n'
|
||||
return include_text
|
||||
|
||||
# avoid changing build flags order
|
||||
build_flags = sorted(list(build_flags))
|
||||
if build_flags:
|
||||
options[u'build_flags'] = u'\n '.join(build_flags)
|
||||
|
||||
lib_deps = set()
|
||||
def update_esphomelib_repo():
|
||||
if CONF_REPOSITORY not in CORE.esphomelib_version:
|
||||
return
|
||||
|
||||
lib_version = config[CONF_ESPHOMEYAML][CONF_ESPHOMELIB_VERSION]
|
||||
lib_path = os.path.join(path, 'lib')
|
||||
dst_path = os.path.join(lib_path, 'esphomelib')
|
||||
this_version = None
|
||||
if CONF_REPOSITORY in lib_version:
|
||||
tag = next((lib_version[x] for x in (CONF_COMMIT, CONF_BRANCH, CONF_TAG)
|
||||
if x in lib_version), None)
|
||||
this_version = lib_version[CONF_REPOSITORY]
|
||||
if tag is not None:
|
||||
this_version += '#' + tag
|
||||
lib_deps.add(this_version)
|
||||
if os.path.islink(dst_path):
|
||||
os.unlink(dst_path)
|
||||
elif CONF_LOCAL in lib_version:
|
||||
this_version = lib_version[CONF_LOCAL]
|
||||
src_path = relative_path(this_version)
|
||||
if CONF_BRANCH not in CORE.esphomelib_version:
|
||||
# Git commit hash or tag cannot be updated
|
||||
return
|
||||
|
||||
esphomelib_path = CORE.relative_build_path('.piolibdeps', 'esphomelib')
|
||||
|
||||
rc, _, _ = run_system_command('git', '-C', esphomelib_path, '--help')
|
||||
if rc != 0:
|
||||
# git not installed or repo not downloaded yet
|
||||
return
|
||||
rc, _, _ = run_system_command('git', '-C', esphomelib_path, 'diff-index', '--quiet', 'HEAD',
|
||||
'--')
|
||||
if rc != 0:
|
||||
# local changes, cannot update
|
||||
_LOGGER.warn("Local changes in esphomelib copy from git. Will not auto-update.")
|
||||
return
|
||||
_LOGGER.info("Updating esphomelib copy from git (%s)", esphomelib_path)
|
||||
rc, stdout, _ = run_system_command('git', '-c', 'color.ui=always', '-C', esphomelib_path,
|
||||
'pull', '--stat')
|
||||
if rc != 0:
|
||||
_LOGGER.warn("Couldn't auto-update local git copy of esphomelib.")
|
||||
return
|
||||
safe_print(stdout.strip())
|
||||
|
||||
|
||||
def replace_file_content(text, pattern, repl):
|
||||
content_new, count = re.subn(pattern, repl, text, flags=re.M)
|
||||
return content_new, count
|
||||
|
||||
|
||||
def migrate_src_version_0_to_1():
|
||||
main_cpp = CORE.relative_build_path('src', 'main.cpp')
|
||||
if not os.path.isfile(main_cpp):
|
||||
return
|
||||
|
||||
with codecs.open(main_cpp, 'r', encoding='utf-8') as f_handle:
|
||||
content = orig_content = f_handle.read()
|
||||
|
||||
content, count = replace_file_content(content, r'\s*delay\((?:16|20)\);', '')
|
||||
if count != 0:
|
||||
_LOGGER.info("Migration: Removed %s occurrence of 'delay(16);' in %s", count, main_cpp)
|
||||
|
||||
content, count = replace_file_content(content, r'using namespace esphomelib;', '')
|
||||
if count != 0:
|
||||
_LOGGER.info("Migration: Removed %s occurrence of 'using namespace esphomelib;' "
|
||||
"in %s", count, main_cpp)
|
||||
|
||||
if CPP_INCLUDE_BEGIN not in content:
|
||||
content, count = replace_file_content(content, r'#include "esphomelib/application.h"',
|
||||
CPP_INCLUDE_BEGIN + u'\n' + CPP_INCLUDE_END)
|
||||
if count == 0:
|
||||
_LOGGER.error("Migration failed. esphomeyaml 1.10.0 needs to have a new auto-generated "
|
||||
"include section in the %s file. Please remove %s and let it be "
|
||||
"auto-generated again.", main_cpp, main_cpp)
|
||||
_LOGGER.info("Migration: Added include section to %s", main_cpp)
|
||||
|
||||
if orig_content == content:
|
||||
return
|
||||
with codecs.open(main_cpp, 'w', encoding='utf-8') as f_handle:
|
||||
f_handle.write(content)
|
||||
|
||||
|
||||
def migrate_src_version(old, new):
|
||||
if old == new:
|
||||
return
|
||||
if old > new:
|
||||
_LOGGER.warning("The source version rolled backwards! Ignoring.")
|
||||
return
|
||||
|
||||
if old == 0:
|
||||
migrate_src_version_0_to_1()
|
||||
|
||||
|
||||
def storage_should_clean(old, new): # type: (StorageJSON, StorageJSON) -> bool
|
||||
if old is None:
|
||||
return True
|
||||
|
||||
if old.esphomelib_version != new.esphomelib_version:
|
||||
return True
|
||||
if old.esphomeyaml_version != new.esphomeyaml_version:
|
||||
return True
|
||||
if old.src_version != new.src_version:
|
||||
return True
|
||||
if old.arduino_version != new.arduino_version:
|
||||
return True
|
||||
if old.board != new.board:
|
||||
return True
|
||||
if old.build_path != new.build_path:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def update_storage_json():
|
||||
path = storage_path()
|
||||
old = StorageJSON.load(path)
|
||||
new = StorageJSON.from_esphomeyaml_core(CORE, old)
|
||||
if old == new:
|
||||
return
|
||||
|
||||
old_src_version = old.src_version if old is not None else 0
|
||||
migrate_src_version(old_src_version, new.src_version)
|
||||
|
||||
if storage_should_clean(old, new):
|
||||
_LOGGER.info("Core config or version changed, cleaning build files...")
|
||||
clean_build()
|
||||
|
||||
new.save(path)
|
||||
|
||||
|
||||
def symlink_esphomelib_version(esphomelib_version):
|
||||
lib_path = CORE.relative_build_path('lib')
|
||||
dst_path = CORE.relative_build_path('lib', 'esphomelib')
|
||||
if CORE.is_local_esphomelib_copy:
|
||||
src_path = CORE.relative_path(esphomelib_version[CONF_LOCAL])
|
||||
do_write = True
|
||||
if os.path.islink(dst_path):
|
||||
old_path = os.path.join(os.readlink(dst_path), lib_path)
|
||||
@@ -140,7 +235,26 @@ def get_ini_content(config, path):
|
||||
if do_write:
|
||||
mkdir_p(lib_path)
|
||||
os.symlink(src_path, dst_path)
|
||||
else:
|
||||
# Remove symlink when changing back from local version
|
||||
if os.path.islink(dst_path):
|
||||
os.unlink(dst_path)
|
||||
|
||||
|
||||
def gather_lib_deps():
|
||||
lib_deps = set()
|
||||
esphomelib_version = CORE.config[CONF_ESPHOMEYAML][CONF_ESPHOMELIB_VERSION]
|
||||
if CONF_REPOSITORY in esphomelib_version:
|
||||
repo = esphomelib_version[CONF_REPOSITORY]
|
||||
ref = next((esphomelib_version[x] for x in (CONF_COMMIT, CONF_BRANCH, CONF_TAG)
|
||||
if x in esphomelib_version), None)
|
||||
if CONF_TAG in esphomelib_version and repo == LIBRARY_URI_REPO:
|
||||
this_version = GITHUB_ARCHIVE_ZIP.format(ref)
|
||||
elif ref is not None:
|
||||
this_version = repo + '#' + ref
|
||||
lib_deps.add(this_version)
|
||||
elif CORE.is_local_esphomelib_copy:
|
||||
src_path = CORE.relative_path(esphomelib_version[CONF_LOCAL])
|
||||
# Manually add lib_deps because platformio seems to ignore them inside libs/
|
||||
library_json_path = os.path.join(src_path, 'library.json')
|
||||
with codecs.open(library_json_path, 'r', encoding='utf-8') as f_handle:
|
||||
@@ -152,106 +266,109 @@ def get_ini_content(config, path):
|
||||
lib_deps.add(dep['name'] + '@' + dep['version'])
|
||||
else:
|
||||
lib_deps.add(dep['version'])
|
||||
lib_deps.add('esphomelib')
|
||||
else:
|
||||
this_version = lib_version
|
||||
lib_deps.add(lib_version)
|
||||
lib_deps.add(esphomelib_version)
|
||||
|
||||
version_file = os.path.join(path, '.esphomelib_version')
|
||||
version = None
|
||||
if os.path.isfile(version_file):
|
||||
with open(version_file, 'r') as ver_f:
|
||||
version = ver_f.read()
|
||||
|
||||
if version != this_version:
|
||||
_LOGGER.info("Esphomelib version change detected. Cleaning build files...")
|
||||
try:
|
||||
clean_build(path)
|
||||
except OSError as err:
|
||||
_LOGGER.warn("Error deleting build files (%s)! Ignoring...", err)
|
||||
|
||||
with open(version_file, 'w') as ver_f:
|
||||
ver_f.write(this_version)
|
||||
|
||||
lib_deps |= get_build_flags(config, 'LIB_DEPS')
|
||||
lib_deps |= get_build_flags(config, 'lib_deps')
|
||||
if core.ESP_PLATFORM == ESP_PLATFORM_ESP32:
|
||||
lib_deps |= get_build_flags('LIB_DEPS')
|
||||
lib_deps |= get_build_flags('lib_deps')
|
||||
if CORE.is_esp32:
|
||||
lib_deps |= {
|
||||
'Preferences', # Preferences helper
|
||||
}
|
||||
# Manual fix for AsyncTCP
|
||||
if config[CONF_ESPHOMEYAML].get(CONF_ARDUINO_VERSION) == ARDUINO_VERSION_ESP32_DEV:
|
||||
if CORE.config[CONF_ESPHOMEYAML].get(CONF_ARDUINO_VERSION) == ARDUINO_VERSION_ESP32_DEV:
|
||||
lib_deps.add('https://github.com/me-no-dev/AsyncTCP.git#idf-update')
|
||||
# avoid changing build flags order
|
||||
lib_deps = sorted(x for x in lib_deps if x)
|
||||
if lib_deps:
|
||||
options[u'lib_deps'] = u'\n '.join(lib_deps)
|
||||
return sorted(x for x in lib_deps if x)
|
||||
|
||||
|
||||
def gather_build_flags():
|
||||
build_flags = set()
|
||||
if not CORE.config[CONF_ESPHOMEYAML][CONF_USE_CUSTOM_CODE]:
|
||||
build_flags |= get_build_flags('build_flags')
|
||||
build_flags |= get_build_flags('BUILD_FLAGS')
|
||||
build_flags.add('-DESPHOMEYAML_USE')
|
||||
build_flags.add("-Wno-unused-variable")
|
||||
build_flags.add("-Wno-unused-but-set-variable")
|
||||
build_flags |= get_build_flags('required_build_flags')
|
||||
build_flags |= get_build_flags('REQUIRED_BUILD_FLAGS')
|
||||
|
||||
# avoid changing build flags order
|
||||
return sorted(list(build_flags))
|
||||
|
||||
|
||||
def get_ini_content():
|
||||
version_specific_settings = determine_platformio_version_settings()
|
||||
lib_deps = gather_lib_deps()
|
||||
options = {
|
||||
u'env': CORE.name,
|
||||
u'platform': CORE.config[CONF_ESPHOMEYAML][CONF_ARDUINO_VERSION],
|
||||
u'board': CORE.board,
|
||||
u'build_flags': u'\n '.join(gather_build_flags()),
|
||||
u'upload_speed': UPLOAD_SPEED_OVERRIDE.get(CORE.board, 115200),
|
||||
u'lib_deps': u'\n '.join(lib_deps),
|
||||
}
|
||||
content = INI_CONTENT_FORMAT.format(**options)
|
||||
if CONF_BOARD_FLASH_MODE in config[CONF_ESPHOMEYAML]:
|
||||
if CONF_BOARD_FLASH_MODE in CORE.config[CONF_ESPHOMEYAML]:
|
||||
flash_mode_key = version_specific_settings['flash_mode_key']
|
||||
flash_mode = config[CONF_ESPHOMEYAML][CONF_BOARD_FLASH_MODE]
|
||||
flash_mode = CORE.config[CONF_ESPHOMEYAML][CONF_BOARD_FLASH_MODE]
|
||||
content += "{} = {}\n".format(flash_mode_key, flash_mode)
|
||||
return content
|
||||
|
||||
|
||||
def mkdir_p(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as exc: # Python >2.5
|
||||
if exc.errno == errno.EEXIST and os.path.isdir(path):
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
def find_begin_end(text, begin_s, end_s):
|
||||
begin_index = text.find(begin_s)
|
||||
if begin_index == -1:
|
||||
raise ESPHomeYAMLError(u"Could not find auto generated code begin in file, either"
|
||||
raise EsphomeyamlError(u"Could not find auto generated code begin in file, either "
|
||||
u"delete the main sketch file or insert the comment again.")
|
||||
if text.find(begin_s, begin_index + 1) != -1:
|
||||
raise ESPHomeYAMLError(u"Found multiple auto generate code begins, don't know"
|
||||
raise EsphomeyamlError(u"Found multiple auto generate code begins, don't know "
|
||||
u"which to chose, please remove one of them.")
|
||||
end_index = text.find(end_s)
|
||||
if end_index == -1:
|
||||
raise ESPHomeYAMLError(u"Could not find auto generated code end in file, either"
|
||||
raise EsphomeyamlError(u"Could not find auto generated code end in file, either "
|
||||
u"delete the main sketch file or insert the comment again.")
|
||||
if text.find(end_s, end_index + 1) != -1:
|
||||
raise ESPHomeYAMLError(u"Found multiple auto generate code endings, don't know"
|
||||
raise EsphomeyamlError(u"Found multiple auto generate code endings, don't know "
|
||||
u"which to chose, please remove one of them.")
|
||||
|
||||
return text[:begin_index], text[(end_index + len(end_s)):]
|
||||
|
||||
|
||||
def write_platformio_ini(content, path):
|
||||
symlink_esphomelib_version(CORE.esphomelib_version)
|
||||
update_esphomelib_repo()
|
||||
update_storage_json()
|
||||
|
||||
if os.path.isfile(path):
|
||||
try:
|
||||
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
||||
text = f_handle.read()
|
||||
except OSError:
|
||||
raise ESPHomeYAMLError(u"Could not read ini file at {}".format(path))
|
||||
raise EsphomeyamlError(u"Could not read ini file at {}".format(path))
|
||||
prev_file = text
|
||||
content_format = find_begin_end(text, INI_AUTO_GENERATE_BEGIN, INI_AUTO_GENERATE_END)
|
||||
else:
|
||||
prev_file = None
|
||||
content_format = INI_BASE_FORMAT
|
||||
full_file = content_format[0] + INI_AUTO_GENERATE_BEGIN + '\n' + \
|
||||
content + INI_AUTO_GENERATE_END + content_format[1]
|
||||
full_file = content_format[0] + INI_AUTO_GENERATE_BEGIN + '\n' + content
|
||||
full_file += INI_AUTO_GENERATE_END + content_format[1]
|
||||
if prev_file == full_file:
|
||||
return
|
||||
with codecs.open(path, mode='w+', encoding='utf-8') as f_handle:
|
||||
f_handle.write(full_file)
|
||||
|
||||
|
||||
def write_platformio_project(config, path):
|
||||
mkdir_p(path)
|
||||
platformio_ini = os.path.join(path, 'platformio.ini')
|
||||
content = get_ini_content(config, path)
|
||||
if 'esp32_ble_beacon' in config or 'esp32_ble_tracker' in config:
|
||||
def write_platformio_project():
|
||||
mkdir_p(CORE.build_path)
|
||||
|
||||
platformio_ini = CORE.relative_build_path('platformio.ini')
|
||||
content = get_ini_content()
|
||||
if 'esp32_ble_beacon' in CORE.config or 'esp32_ble_tracker' in CORE.config:
|
||||
content += 'board_build.partitions = partitions.csv\n'
|
||||
partitions_csv = os.path.join(path, 'partitions.csv')
|
||||
partitions_csv = CORE.relative_build_path('partitions.csv')
|
||||
if not os.path.isfile(partitions_csv):
|
||||
mkdir_p(path)
|
||||
with open(partitions_csv, "w") as f:
|
||||
f.write("nvs, data, nvs, 0x009000, 0x005000,\n")
|
||||
f.write("otadata, data, ota, 0x00e000, 0x002000,\n")
|
||||
@@ -262,22 +379,28 @@ def write_platformio_project(config, path):
|
||||
write_platformio_ini(content, platformio_ini)
|
||||
|
||||
|
||||
def write_cpp(code_s, path):
|
||||
def write_cpp(code_s):
|
||||
path = CORE.relative_build_path('src', 'main.cpp')
|
||||
if os.path.isfile(path):
|
||||
try:
|
||||
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
||||
text = f_handle.read()
|
||||
except OSError:
|
||||
raise ESPHomeYAMLError(u"Could not read C++ file at {}".format(path))
|
||||
raise EsphomeyamlError(u"Could not read C++ file at {}".format(path))
|
||||
prev_file = text
|
||||
code_format = find_begin_end(text, CPP_AUTO_GENERATE_BEGIN, CPP_AUTO_GENERATE_END)
|
||||
code_format_ = find_begin_end(code_format[0], CPP_INCLUDE_BEGIN, CPP_INCLUDE_END)
|
||||
code_format = (code_format_[0], code_format_[1], code_format[1])
|
||||
else:
|
||||
prev_file = None
|
||||
mkdir_p(os.path.dirname(path))
|
||||
code_format = CPP_BASE_FORMAT
|
||||
|
||||
full_file = code_format[0] + CPP_AUTO_GENERATE_BEGIN + '\n' + \
|
||||
code_s + CPP_AUTO_GENERATE_END + code_format[1]
|
||||
include_s = get_include_text()
|
||||
|
||||
full_file = code_format[0] + CPP_INCLUDE_BEGIN + u'\n' + include_s + CPP_INCLUDE_END
|
||||
full_file += code_format[1] + CPP_AUTO_GENERATE_BEGIN + u'\n' + code_s + CPP_AUTO_GENERATE_END
|
||||
full_file += code_format[2]
|
||||
if prev_file == full_file:
|
||||
return
|
||||
with codecs.open(path, 'w+', encoding='utf-8') as f_handle:
|
||||
@@ -297,9 +420,10 @@ def determine_platformio_version_settings():
|
||||
return settings
|
||||
|
||||
|
||||
def clean_build(build_path):
|
||||
def clean_build():
|
||||
for directory in ('.piolibdeps', '.pioenvs'):
|
||||
dir_path = os.path.join(build_path, directory)
|
||||
if os.path.isdir(dir_path):
|
||||
_LOGGER.info("Deleting %s", dir_path)
|
||||
shutil.rmtree(dir_path)
|
||||
dir_path = CORE.relative_build_path(directory)
|
||||
if not os.path.isdir(dir_path):
|
||||
continue
|
||||
_LOGGER.info("Deleting %s", dir_path)
|
||||
shutil.rmtree(dir_path)
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import codecs
|
||||
from collections import OrderedDict
|
||||
import fnmatch
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
|
||||
import yaml
|
||||
import yaml.constructor
|
||||
|
||||
from esphomeyaml import core
|
||||
from esphomeyaml.core import ESPHomeYAMLError, HexInt, IPAddress, Lambda, MACAddress, TimePeriod
|
||||
from esphomeyaml.core import EsphomeyamlError, HexInt, IPAddress, Lambda, MACAddress, TimePeriod
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,12 +50,12 @@ def load_yaml(fname):
|
||||
with codecs.open(fname, encoding='utf-8') as conf_file:
|
||||
return yaml.load(conf_file, Loader=SafeLineLoader) or OrderedDict()
|
||||
except yaml.YAMLError as exc:
|
||||
raise ESPHomeYAMLError(exc)
|
||||
raise EsphomeyamlError(exc)
|
||||
except IOError as exc:
|
||||
raise ESPHomeYAMLError(u"Error accessing file {}: {}".format(fname, exc))
|
||||
raise EsphomeyamlError(u"Error accessing file {}: {}".format(fname, exc))
|
||||
except UnicodeDecodeError as exc:
|
||||
_LOGGER.error(u"Unable to read file %s: %s", fname, exc)
|
||||
raise ESPHomeYAMLError(exc)
|
||||
raise EsphomeyamlError(exc)
|
||||
|
||||
|
||||
def dump(dict_):
|
||||
@@ -70,7 +70,7 @@ def custom_construct_pairs(loader, node):
|
||||
if isinstance(kv, yaml.ScalarNode):
|
||||
obj = loader.construct_object(kv)
|
||||
if not isinstance(obj, dict):
|
||||
raise ESPHomeYAMLError(
|
||||
raise EsphomeyamlError(
|
||||
"Expected mapping for anchored include tag, got {}".format(type(obj)))
|
||||
for key, value in obj.iteritems():
|
||||
pairs.append((key, value))
|
||||
@@ -153,7 +153,7 @@ def _ordered_dict(loader, node):
|
||||
|
||||
if key in seen:
|
||||
fname = getattr(loader.stream, 'name', '')
|
||||
raise ESPHomeYAMLError(u'YAML file {} contains duplicate key "{}". '
|
||||
raise EsphomeyamlError(u'YAML file {} contains duplicate key "{}". '
|
||||
u'Check lines {} and {}.'.format(fname, key, seen[key], line))
|
||||
seen[key] = line
|
||||
|
||||
@@ -171,7 +171,7 @@ def _add_reference(obj, loader, node):
|
||||
if isinstance(obj, (str, unicode)):
|
||||
obj = NodeStrClass(obj)
|
||||
if isinstance(obj, list):
|
||||
return obj
|
||||
obj = NodeListClass(obj)
|
||||
setattr(obj, '__config_file__', loader.name)
|
||||
setattr(obj, '__line__', node.start_mark.line)
|
||||
return obj
|
||||
@@ -186,7 +186,7 @@ def _env_var_yaml(_, node):
|
||||
return os.getenv(args[0], u' '.join(args[1:]))
|
||||
elif args[0] in os.environ:
|
||||
return os.environ[args[0]]
|
||||
raise ESPHomeYAMLError(u"Environment variable {} not defined.".format(node.value))
|
||||
raise EsphomeyamlError(u"Environment variable {} not defined.".format(node.value))
|
||||
|
||||
|
||||
def _include_yaml(loader, node):
|
||||
@@ -263,7 +263,7 @@ def _secret_yaml(loader, node):
|
||||
secret_path = os.path.join(os.path.dirname(loader.name), SECRET_YAML)
|
||||
secrets = load_yaml(secret_path)
|
||||
if node.value not in secrets:
|
||||
raise ESPHomeYAMLError(u"Secret {} not defined".format(node.value))
|
||||
raise EsphomeyamlError(u"Secret {} not defined".format(node.value))
|
||||
return secrets[node.value]
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ def represent_time_period(dumper, data):
|
||||
|
||||
|
||||
def represent_lambda(_, data):
|
||||
node = yaml.ScalarNode(tag='!lambda', value=data.value, style='>')
|
||||
node = yaml.ScalarNode(tag='!lambda', value=data.value, style='|')
|
||||
return node
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ yaml.SafeDumper.add_representer(
|
||||
yaml.SafeDumper.add_representer(
|
||||
NodeListClass,
|
||||
lambda dumper, value:
|
||||
dumper.represent_sequence(dumper, 'tag:yaml.org,2002:map', value)
|
||||
dumper.represent_sequence('tag:yaml.org,2002:seq', value)
|
||||
)
|
||||
|
||||
yaml.SafeDumper.add_representer(unicode, unicode_representer)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "esphomeyaml HassIO Add-On Repository",
|
||||
"name": "esphomeyaml Hass.io Add-Ons",
|
||||
"url": "https://github.com/OttoWinter/esphomeyaml",
|
||||
"maintainer": "Otto Winter <contact@otto-winter.com>"
|
||||
}
|
||||
|
||||
@@ -5,3 +5,4 @@ paho-mqtt>=1.3.1
|
||||
colorlog>=3.1.2
|
||||
tornado>=5.0.0
|
||||
esptool>=2.3.1
|
||||
typing>=3.0.0
|
||||
|
||||
1
setup.py
1
setup.py
@@ -29,6 +29,7 @@ REQUIRES = [
|
||||
'colorlog>=3.1.2',
|
||||
'tornado>=5.0.0',
|
||||
'esptool>=2.3.1',
|
||||
'typing>=3.0.0',
|
||||
]
|
||||
|
||||
CLASSIFIERS = [
|
||||
|
||||
@@ -2,8 +2,6 @@ esphomeyaml:
|
||||
name: test1
|
||||
platform: ESP32
|
||||
board: nodemcu-32s
|
||||
# Use latest upstream esphomelib git version.
|
||||
esphomelib_version: dev
|
||||
# Use this for testing while developing:
|
||||
# esphomelib_version:
|
||||
# local: ~/path/to/esphomelib
|
||||
@@ -180,7 +178,7 @@ sensor:
|
||||
- lambda: return x * (9.0/5.0) + 32.0;
|
||||
on_value:
|
||||
then:
|
||||
- lambda: >-
|
||||
- lambda: |-
|
||||
ESP_LOGD("main", "Got value %f", x);
|
||||
id(my_sensor).publish_state(42.0);
|
||||
ESP_LOGI("main", "Value of my sensor: %f", id(my_sensor).state);
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
esphomeyaml:
|
||||
name: test2
|
||||
name: $devicename
|
||||
platform: ESP32
|
||||
board: nodemcu-32s
|
||||
# Use latest upstream esphomelib git version.
|
||||
esphomelib_version: dev
|
||||
# Use this for testing while developing:
|
||||
# esphomelib_version:
|
||||
# local: ~/path/to/esphomelib
|
||||
use_custom_code: true
|
||||
build_path: build/test2
|
||||
|
||||
substitutions:
|
||||
devicename: test2
|
||||
|
||||
wifi:
|
||||
ssid: 'MySSID'
|
||||
password: 'password1'
|
||||
@@ -150,7 +151,7 @@ text_sensor:
|
||||
icon: mdi:icon
|
||||
id: version_sensor
|
||||
on_value:
|
||||
- lambda: |-
|
||||
- lambda: !lambda |-
|
||||
ESP_LOGD("main", "The state is %s=%s", x.c_str(), id(version_sensor).state.c_str());
|
||||
- script.execute: my_script
|
||||
- platform: mqtt_subscribe
|
||||
|
||||
Reference in New Issue
Block a user