mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	Compare commits
	
		
			262 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					92a4ee5652 | ||
| 
						 | 
					9fea094b4e | ||
| 
						 | 
					596c334fcb | ||
| 
						 | 
					ca4450858f | ||
| 
						 | 
					f3ec83fe31 | ||
| 
						 | 
					c4ada8c9f0 | ||
| 
						 | 
					23df5d8af7 | ||
| 
						 | 
					289acade1e | ||
| 
						 | 
					a99f99779a | ||
| 
						 | 
					5c14ca030a | ||
| 
						 | 
					0fc6a027a7 | ||
| 
						 | 
					3c0d97ef69 | ||
| 
						 | 
					5b4f98d414 | ||
| 
						 | 
					7ebfcd3807 | ||
| 
						 | 
					3ef0634dd2 | ||
| 
						 | 
					0928c9739f | ||
| 
						 | 
					e009f21a72 | ||
| 
						 | 
					606c412616 | ||
| 
						 | 
					975b5127d6 | ||
| 
						 | 
					60c9ffef30 | ||
| 
						 | 
					99861259d7 | ||
| 
						 | 
					067ec30c56 | ||
| 
						 | 
					5a102c2ab7 | ||
| 
						 | 
					4b017e2096 | ||
| 
						 | 
					8495ce96a3 | ||
| 
						 | 
					55caf4f648 | ||
| 
						 | 
					c123f0091d | ||
| 
						 | 
					7c65d44976 | ||
| 
						 | 
					5b8d12a80c | ||
| 
						 | 
					3951a2b22a | ||
| 
						 | 
					69a74a30e8 | ||
| 
						 | 
					f3ee5b55e9 | ||
| 
						 | 
					f6cc9f7caa | ||
| 
						 | 
					a5d0ecdb13 | ||
| 
						 | 
					71cbc9cfb0 | ||
| 
						 | 
					88625c656d | ||
| 
						 | 
					971b15ac67 | ||
| 
						 | 
					a4edcc48ca | ||
| 
						 | 
					1778dd4df9 | ||
| 
						 | 
					311e837196 | ||
| 
						 | 
					3b00cfd6c4 | ||
| 
						 | 
					1c7ca4bc6f | ||
| 
						 | 
					38e7b597d6 | ||
| 
						 | 
					808ee19180 | ||
| 
						 | 
					c2a0c22bd9 | ||
| 
						 | 
					e785ad5401 | ||
| 
						 | 
					bacddc3673 | ||
| 
						 | 
					7dd0dabaf5 | ||
| 
						 | 
					92f8b043ce | ||
| 
						 | 
					2e5fd7e90d | ||
| 
						 | 
					407c46cb03 | ||
| 
						 | 
					12ce448f2d | ||
| 
						 | 
					340530566c | ||
| 
						 | 
					f4a55eafd7 | ||
| 
						 | 
					fc8f270a9f | ||
| 
						 | 
					e7ce8f7a13 | ||
| 
						 | 
					3d1cce2a29 | ||
| 
						 | 
					6be47488a4 | ||
| 
						 | 
					5b94bb894e | ||
| 
						 | 
					26aa399bea | ||
| 
						 | 
					af0c213024 | ||
| 
						 | 
					88e036ddb2 | ||
| 
						 | 
					8012de3ba4 | ||
| 
						 | 
					e2b1d5438d | ||
| 
						 | 
					fe66f93a01 | ||
| 
						 | 
					581dffe2d4 | ||
| 
						 | 
					6f22006bf7 | ||
| 
						 | 
					fe54700687 | ||
| 
						 | 
					f0c0131ed1 | ||
| 
						 | 
					52750d933b | ||
| 
						 | 
					7e7a85abfd | ||
| 
						 | 
					c1b8107aaf | ||
| 
						 | 
					0bdcce609f | ||
| 
						 | 
					6b702f8014 | ||
| 
						 | 
					078ab26fd2 | ||
| 
						 | 
					efe81e0856 | ||
| 
						 | 
					41d637affe | ||
| 
						 | 
					10cc11bab1 | ||
| 
						 | 
					34ca5d6d8a | ||
| 
						 | 
					b27c778cb7 | ||
| 
						 | 
					f311a1bb30 | ||
| 
						 | 
					7a450ed41c | ||
| 
						 | 
					944f0169cb | ||
| 
						 | 
					4da0e0c223 | ||
| 
						 | 
					52c0b45f41 | ||
| 
						 | 
					fcef3be5c7 | ||
| 
						 | 
					ef7b936d60 | ||
| 
						 | 
					e0eac6ba25 | ||
| 
						 | 
					50af0da13f | ||
| 
						 | 
					a8d87a1fee | ||
| 
						 | 
					a66ed437d6 | ||
| 
						 | 
					b95f53a7c7 | ||
| 
						 | 
					d7eacb2a2f | ||
| 
						 | 
					41ec337ba0 | ||
| 
						 | 
					5e61014e98 | ||
| 
						 | 
					0a4d49accb | ||
| 
						 | 
					3d9301a0f7 | ||
| 
						 | 
					1b8d242505 | ||
| 
						 | 
					463ad6f94b | ||
| 
						 | 
					e4e315f723 | ||
| 
						 | 
					7fecec128f | ||
| 
						 | 
					a15b647d13 | ||
| 
						 | 
					feab956ea9 | ||
| 
						 | 
					4b7a41922c | ||
| 
						 | 
					61762bf299 | ||
| 
						 | 
					6eb769e6d5 | ||
| 
						 | 
					4c8bd7a70c | ||
| 
						 | 
					d9cf91210e | ||
| 
						 | 
					fcf5da66c0 | ||
| 
						 | 
					b6edbf9d0b | ||
| 
						 | 
					596f995af8 | ||
| 
						 | 
					8ce176aaba | ||
| 
						 | 
					f185ba7a21 | ||
| 
						 | 
					7c28eca6de | ||
| 
						 | 
					9fa95a9a21 | ||
| 
						 | 
					6ccb68aaf1 | ||
| 
						 | 
					6a76a3642e | ||
| 
						 | 
					a50eb3579a | ||
| 
						 | 
					4a74027848 | ||
| 
						 | 
					98bdfc821e | ||
| 
						 | 
					176c712eeb | ||
| 
						 | 
					7b26ecc0dc | ||
| 
						 | 
					92e909568c | ||
| 
						 | 
					e3f7e0d14a | ||
| 
						 | 
					5fcda34c45 | ||
| 
						 | 
					bd23584073 | ||
| 
						 | 
					6d6876ca39 | ||
| 
						 | 
					9ebf6439b2 | ||
| 
						 | 
					1404d39ffe | ||
| 
						 | 
					7153c7a941 | ||
| 
						 | 
					3437e23c8e | ||
| 
						 | 
					eb39add6fc | ||
| 
						 | 
					e13bffbb2f | ||
| 
						 | 
					e347cb538d | ||
| 
						 | 
					d799c03f0c | ||
| 
						 | 
					c86675f644 | ||
| 
						 | 
					a00fe09c66 | ||
| 
						 | 
					e0fe0a2835 | ||
| 
						 | 
					e1f48b5028 | ||
| 
						 | 
					e4a2677de4 | ||
| 
						 | 
					ab40156c16 | ||
| 
						 | 
					804a1ed7b3 | ||
| 
						 | 
					4de98fd782 | ||
| 
						 | 
					d8fd5e9bb4 | ||
| 
						 | 
					8424f9c34b | ||
| 
						 | 
					70016d7641 | ||
| 
						 | 
					7ced977f2a | ||
| 
						 | 
					5ac9b8d545 | ||
| 
						 | 
					a683108b5d | ||
| 
						 | 
					54dd9e94ab | ||
| 
						 | 
					4f5389998f | ||
| 
						 | 
					8a61c21051 | ||
| 
						 | 
					b71b14cd06 | ||
| 
						 | 
					9b2b7dabd1 | ||
| 
						 | 
					145e7b00ee | ||
| 
						 | 
					07c80dfcda | ||
| 
						 | 
					0e52c9a778 | ||
| 
						 | 
					94bd179256 | ||
| 
						 | 
					11c38ca4e8 | ||
| 
						 | 
					dc71d11a21 | ||
| 
						 | 
					86130b2954 | ||
| 
						 | 
					c2787c1ce5 | ||
| 
						 | 
					e81338b4f5 | ||
| 
						 | 
					40ab2d5e5a | ||
| 
						 | 
					7a703d10f4 | ||
| 
						 | 
					e385c8435b | ||
| 
						 | 
					4c5f908e3a | ||
| 
						 | 
					13eca6012d | ||
| 
						 | 
					27e1294630 | ||
| 
						 | 
					cb3e3e024d | ||
| 
						 | 
					79bdec32b8 | ||
| 
						 | 
					c2fb71c41f | ||
| 
						 | 
					c153dba5bc | ||
| 
						 | 
					fa2c2917c1 | ||
| 
						 | 
					7685b32ac0 | ||
| 
						 | 
					2a06f4dbf4 | ||
| 
						 | 
					49b618bb0c | ||
| 
						 | 
					20ec3900be | ||
| 
						 | 
					605be1a6ec | ||
| 
						 | 
					33b67de32e | ||
| 
						 | 
					5a1e806d14 | ||
| 
						 | 
					cf73d777db | ||
| 
						 | 
					47231977d7 | ||
| 
						 | 
					d29b280d82 | ||
| 
						 | 
					77514c0a06 | ||
| 
						 | 
					1ffedb291c | ||
| 
						 | 
					341a27e56b | ||
| 
						 | 
					8f251848ef | ||
| 
						 | 
					739b7bfc05 | ||
| 
						 | 
					01b49e8d59 | ||
| 
						 | 
					52dbd35118 | ||
| 
						 | 
					92439abeb4 | ||
| 
						 | 
					9bce35e335 | ||
| 
						 | 
					94cb7bf6bd | ||
| 
						 | 
					cdf53cb3e8 | ||
| 
						 | 
					30bd74cb6c | ||
| 
						 | 
					e72ef9e061 | ||
| 
						 | 
					3f4bba57f4 | ||
| 
						 | 
					38c24fd100 | ||
| 
						 | 
					c6ed88579f | ||
| 
						 | 
					7f9462ebf3 | ||
| 
						 | 
					4e44081fdf | ||
| 
						 | 
					3cd1c2d723 | ||
| 
						 | 
					907be3025c | ||
| 
						 | 
					815da05b29 | ||
| 
						 | 
					a2083fc901 | ||
| 
						 | 
					06cb7497c8 | ||
| 
						 | 
					1e12cba176 | ||
| 
						 | 
					1d0c812e44 | ||
| 
						 | 
					4948ad95b0 | ||
| 
						 | 
					dd801636af | ||
| 
						 | 
					a110911371 | ||
| 
						 | 
					22fd4ec722 | ||
| 
						 | 
					5db70bea3c | ||
| 
						 | 
					00ff99cc7d | ||
| 
						 | 
					a51eaa93b5 | ||
| 
						 | 
					eddaee3a80 | ||
| 
						 | 
					2b432ea829 | ||
| 
						 | 
					09ab55b85d | ||
| 
						 | 
					183e0f4d23 | ||
| 
						 | 
					a8c17e5d05 | ||
| 
						 | 
					2e65d6c02c | ||
| 
						 | 
					07da8950c4 | ||
| 
						 | 
					c206846816 | ||
| 
						 | 
					6aac4191f8 | ||
| 
						 | 
					5a7b66e207 | ||
| 
						 | 
					da2821ab36 | ||
| 
						 | 
					7556845079 | ||
| 
						 | 
					e646f02e27 | ||
| 
						 | 
					39ead80df3 | ||
| 
						 | 
					71e221f6ec | ||
| 
						 | 
					7c7032c59e | ||
| 
						 | 
					2b88c987da | ||
| 
						 | 
					3d49ffa134 | ||
| 
						 | 
					5ed987adcd | ||
| 
						 | 
					a463c59733 | ||
| 
						 | 
					1726c4237b | ||
| 
						 | 
					f2f869db89 | ||
| 
						 | 
					e37e986276 | ||
| 
						 | 
					f1241af91d | ||
| 
						 | 
					7ae6777fd6 | ||
| 
						 | 
					a169d37557 | ||
| 
						 | 
					5d5529ff15 | ||
| 
						 | 
					db90a7a334 | ||
| 
						 | 
					bb9c1faffa | ||
| 
						 | 
					be21aa786d | ||
| 
						 | 
					9a881100e6 | ||
| 
						 | 
					c2f88776c7 | ||
| 
						 | 
					b4c4dc8cfb | ||
| 
						 | 
					c3b2ab0085 | ||
| 
						 | 
					846fcb8ccd | ||
| 
						 | 
					f087e313d4 | ||
| 
						 | 
					44495c919c | ||
| 
						 | 
					d4ce7699d4 | ||
| 
						 | 
					f88cf99b67 | ||
| 
						 | 
					f394968bd0 | ||
| 
						 | 
					318bb8b254 | ||
| 
						 | 
					70def85ba1 | ||
| 
						 | 
					9a939d2d27 | ||
| 
						 | 
					f51d301d53 | ||
| 
						 | 
					d7d3a4aa36 | ||
| 
						 | 
					6a2e9a8503 | 
							
								
								
									
										49
									
								
								.github/ISSUE_TEMPLATE/bug_report.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										49
									
								
								.github/ISSUE_TEMPLATE/bug_report.md
									
									
									
									
										vendored
									
									
								
							@@ -1,49 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
name: Bug report
 | 
			
		||||
about: Create a report to help esphomelib improve
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<!-- Thanks for reporting a bug for this project. READ THIS FIRST:
 | 
			
		||||
- Please make sure to submit issues in the right GitHub repository, if unsure just post it here:
 | 
			
		||||
  - esphomeyaml [here] - This is mostly for reporting bugs when compiling and when you get a long stack trace while compiling or if a configuration fails to validate.
 | 
			
		||||
  - esphomelib [https://github.com/OttoWinter/esphomelib] - Report bugs there if the ESP is crashing or a feature is not working as expected.
 | 
			
		||||
  - esphomedocs [https://github.com/OttoWinter/esphomedocs] - Report bugs there if the documentation is wrong/outdated.
 | 
			
		||||
- Provide as many details as possible. Paste logs, configuration sample and code into the backticks (```).
 | 
			
		||||
 
 | 
			
		||||
  DO NOT DELETE ANY TEXT from this template! Otherwise the issue may be closed without a comment.
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
**Operating environment (Hass.io/Docker/pip/etc.):**
 | 
			
		||||
<!--
 | 
			
		||||
Please provide details about your environment.
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
**ESP (ESP32/ESP8266/Board/Sonoff):**
 | 
			
		||||
<!--
 | 
			
		||||
Please provide details about which ESP you're using.
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
**Affected component:**
 | 
			
		||||
<!--
 | 
			
		||||
Please add the link to the documentation at https://esphomelib.com/esphomeyaml/index.html of the component in question.
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
**Description of problem:**
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
**Problem-relevant YAML-configuration entries:**
 | 
			
		||||
```yaml
 | 
			
		||||
PASTE YAML FILE HERE
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Traceback (if applicable):**
 | 
			
		||||
<!--
 | 
			
		||||
Please copy the traceback here if compilation is failing. If possible, also connect to the ESP and copy its logs into the backticks.
 | 
			
		||||
-->
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Additional information:**
 | 
			
		||||
							
								
								
									
										21
									
								
								.github/ISSUE_TEMPLATE/feature_request.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								.github/ISSUE_TEMPLATE/feature_request.md
									
									
									
									
										vendored
									
									
								
							@@ -1,21 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
name: Feature request
 | 
			
		||||
about: Suggest an idea for this project
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<!-- READ THIS FIRST:
 | 
			
		||||
 - This is for feature requests only, if you want to have a certain new sensor/module supported, please use the "new integration" template.
 | 
			
		||||
 - Please be as descriptive as possible, especially use-cases that can otherwise not be solved boost the problem's priority.
 | 
			
		||||
 
 | 
			
		||||
   DO NOT DELETE ANY TEXT from this template! Otherwise the issue may be closed without a comment.
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
**Is your feature request related to a problem/use-case? Please describe.**
 | 
			
		||||
<!-- A clear and concise description of what the problem is. -->
 | 
			
		||||
 | 
			
		||||
**Describe the solution you'd like:**
 | 
			
		||||
<!-- A description of what you want to happen. -->
 | 
			
		||||
 | 
			
		||||
**Additional context:**
 | 
			
		||||
<!-- Add any other context about the feature request here. -->
 | 
			
		||||
							
								
								
									
										13
									
								
								.github/ISSUE_TEMPLATE/new-integration.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.github/ISSUE_TEMPLATE/new-integration.md
									
									
									
									
										vendored
									
									
								
							@@ -1,13 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
name: New integration
 | 
			
		||||
about: Suggest a new integration for esphomelib
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
DO NOT POST NEW INTEGRATION REQUESTS HERE!
 | 
			
		||||
 | 
			
		||||
Please post all new integration requests in the esphomelib repository:
 | 
			
		||||
 | 
			
		||||
https://github.com/OttoWinter/esphomelib/issues
 | 
			
		||||
 | 
			
		||||
Thank you!
 | 
			
		||||
							
								
								
									
										4
									
								
								.github/PULL_REQUEST_TEMPLATE.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/PULL_REQUEST_TEMPLATE.md
									
									
									
									
										vendored
									
									
								
							@@ -3,8 +3,8 @@
 | 
			
		||||
 | 
			
		||||
**Related issue (if applicable):** fixes <link to issue>
 | 
			
		||||
 | 
			
		||||
**Pull request in [esphomedocs](https://github.com/OttoWinter/esphomedocs) with documentation (if applicable):** OttoWinter/esphomedocs#<esphomedocs PR number goes here>
 | 
			
		||||
**Pull request in [esphomelib](https://github.com/OttoWinter/esphomelib) with C++ framework changes (if applicable):** OttoWinter/esphomelib#<esphomelib PR number goes here>
 | 
			
		||||
**Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here>
 | 
			
		||||
**Pull request in [esphome-core](https://github.com/esphome/esphome-core) with C++ framework changes (if applicable):** esphome/esphome-core#<esphome-core PR number goes here>
 | 
			
		||||
 | 
			
		||||
## Checklist:
 | 
			
		||||
  - [ ] The code change is tested and works locally.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								.github/issue-close-app.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.github/issue-close-app.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
comment: >-
 | 
			
		||||
  https://github.com/esphome/esphome/issues/430
 | 
			
		||||
issueConfigs:
 | 
			
		||||
- content:
 | 
			
		||||
  - "OTHERWISE THE ISSUE WILL BE CLOSED AUTOMATICALLY"
 | 
			
		||||
 | 
			
		||||
caseInsensitive: false
 | 
			
		||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -105,4 +105,4 @@ venv.bak/
 | 
			
		||||
 | 
			
		||||
config/
 | 
			
		||||
tests/build/
 | 
			
		||||
tests/.esphomeyaml/
 | 
			
		||||
tests/.esphome/
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										521
									
								
								.gitlab-ci.yml
									
									
									
									
									
								
							
							
						
						
									
										521
									
								
								.gitlab-ci.yml
									
									
									
									
									
								
							@@ -2,302 +2,134 @@
 | 
			
		||||
# Based on https://gitlab.com/hassio-addons/addon-node-red/blob/master/.gitlab-ci.yml
 | 
			
		||||
variables:
 | 
			
		||||
  DOCKER_DRIVER: overlay2
 | 
			
		||||
  DOCKER_HOST: tcp://docker:2375/
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
  - lint
 | 
			
		||||
  - test
 | 
			
		||||
  - build
 | 
			
		||||
  - deploy
 | 
			
		||||
 | 
			
		||||
.lint: &lint
 | 
			
		||||
  image: esphome/esphome-base-amd64
 | 
			
		||||
  stage: lint
 | 
			
		||||
  before_script:
 | 
			
		||||
    - pip install -e .
 | 
			
		||||
    - pip install flake8==3.6.0 pylint==1.9.4 pillow
 | 
			
		||||
  tags:
 | 
			
		||||
    - python2.7
 | 
			
		||||
    - esphomeyaml-lint
 | 
			
		||||
    - docker
 | 
			
		||||
 | 
			
		||||
.test: &test
 | 
			
		||||
  image: esphome/esphome-base-amd64
 | 
			
		||||
  stage: test
 | 
			
		||||
  before_script:
 | 
			
		||||
    - pip install -e .
 | 
			
		||||
  tags:
 | 
			
		||||
    - python2.7
 | 
			
		||||
    - esphomeyaml-test
 | 
			
		||||
    - docker
 | 
			
		||||
  variables:
 | 
			
		||||
    TZ: UTC
 | 
			
		||||
 | 
			
		||||
.docker-builder: &docker-builder
 | 
			
		||||
.docker-base: &docker-base
 | 
			
		||||
  image: esphome/esphome-base-builder
 | 
			
		||||
  before_script:
 | 
			
		||||
    - docker info
 | 
			
		||||
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
 | 
			
		||||
    - docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
 | 
			
		||||
  script:
 | 
			
		||||
    - docker run --rm --privileged hassioaddons/qemu-user-static:latest
 | 
			
		||||
    - TAG="${CI_COMMIT_TAG#v}"
 | 
			
		||||
    - TAG="${TAG:-${CI_COMMIT_SHA:0:7}}"
 | 
			
		||||
    - echo "Tag ${TAG}"
 | 
			
		||||
 | 
			
		||||
    - |
 | 
			
		||||
      if [[ "${IS_HASSIO}" == "YES" ]]; then
 | 
			
		||||
        BUILD_FROM=esphome/esphome-hassio-base-${BUILD_ARCH}:1.3.0
 | 
			
		||||
        BUILD_TO=esphome/esphome-hassio-${BUILD_ARCH}
 | 
			
		||||
        DOCKERFILE=docker/Dockerfile.hassio
 | 
			
		||||
      else
 | 
			
		||||
        BUILD_FROM=esphome/esphome-base-${BUILD_ARCH}:1.3.0
 | 
			
		||||
        if [[ "${BUILD_ARCH}" == "amd64" ]]; then
 | 
			
		||||
          BUILD_TO=esphome/esphome
 | 
			
		||||
        else
 | 
			
		||||
          BUILD_TO=esphome/esphome-${BUILD_ARCH}
 | 
			
		||||
        fi
 | 
			
		||||
        DOCKERFILE=docker/Dockerfile
 | 
			
		||||
      fi
 | 
			
		||||
 | 
			
		||||
    - |
 | 
			
		||||
      docker build \
 | 
			
		||||
        --build-arg "BUILD_FROM=${BUILD_FROM}" \
 | 
			
		||||
        --build-arg "BUILD_VERSION=${TAG}" \
 | 
			
		||||
        --tag "${BUILD_TO}:${TAG}" \
 | 
			
		||||
        --file "${DOCKERFILE}" \
 | 
			
		||||
        .
 | 
			
		||||
    - |
 | 
			
		||||
      if [[ "${RELEASE}" = "YES" ]]; then
 | 
			
		||||
        echo "Pushing to ${BUILD_TO}:${TAG}"
 | 
			
		||||
        docker push "${BUILD_TO}:${TAG}"
 | 
			
		||||
      fi
 | 
			
		||||
    - |
 | 
			
		||||
      if [[ "${LATEST}" = "YES" ]]; then
 | 
			
		||||
        echo "Pushing to :latest"
 | 
			
		||||
        docker tag ${BUILD_TO}:${TAG} ${BUILD_TO}:latest
 | 
			
		||||
        docker push ${BUILD_TO}:latest
 | 
			
		||||
      fi
 | 
			
		||||
    - |
 | 
			
		||||
      if [[ "${BETA}" = "YES" ]]; then
 | 
			
		||||
        echo "Pushing to :beta"
 | 
			
		||||
        docker tag \
 | 
			
		||||
          ${BUILD_TO}:${TAG} \
 | 
			
		||||
          ${BUILD_TO}:beta
 | 
			
		||||
        docker push ${BUILD_TO}:beta
 | 
			
		||||
      fi
 | 
			
		||||
    - |
 | 
			
		||||
      if [[ "${DEV}" = "YES" ]]; then
 | 
			
		||||
        echo "Pushing to :dev"
 | 
			
		||||
        docker tag \
 | 
			
		||||
          ${BUILD_TO}:${TAG} \
 | 
			
		||||
          ${BUILD_TO}:dev
 | 
			
		||||
        docker push ${BUILD_TO}:dev
 | 
			
		||||
      fi
 | 
			
		||||
  services:
 | 
			
		||||
    - docker:dind
 | 
			
		||||
  tags:
 | 
			
		||||
    - hassio-builder
 | 
			
		||||
    - docker
 | 
			
		||||
  stage: deploy
 | 
			
		||||
 | 
			
		||||
flake8:
 | 
			
		||||
  <<: *lint
 | 
			
		||||
  script:
 | 
			
		||||
    - flake8 esphomeyaml
 | 
			
		||||
    - flake8 esphome
 | 
			
		||||
 | 
			
		||||
pylint:
 | 
			
		||||
  <<: *lint
 | 
			
		||||
  script:
 | 
			
		||||
    - pylint esphomeyaml
 | 
			
		||||
    - pylint esphome
 | 
			
		||||
 | 
			
		||||
test1:
 | 
			
		||||
  <<: *test
 | 
			
		||||
  script:
 | 
			
		||||
    - esphomeyaml tests/test1.yaml compile
 | 
			
		||||
    - esphome tests/test1.yaml compile
 | 
			
		||||
 | 
			
		||||
test2:
 | 
			
		||||
  <<: *test
 | 
			
		||||
  script:
 | 
			
		||||
    - esphomeyaml tests/test2.yaml compile
 | 
			
		||||
    - esphome tests/test2.yaml compile
 | 
			
		||||
 | 
			
		||||
.build-hassio: &build-hassio
 | 
			
		||||
  <<: *docker-builder
 | 
			
		||||
  stage: build
 | 
			
		||||
test3:
 | 
			
		||||
  <<: *test
 | 
			
		||||
  script:
 | 
			
		||||
    - docker run --rm --privileged hassioaddons/qemu-user-static: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}}"
 | 
			
		||||
    - echo "Build from ${BUILD_FROM}"
 | 
			
		||||
    - echo "Add-on version ${ADDON_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 "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" \
 | 
			
		||||
        .
 | 
			
		||||
    - |
 | 
			
		||||
      if [ "${DO_PUSH:-true}" = true ]; then
 | 
			
		||||
        echo "Pushing to CI registry"
 | 
			
		||||
        docker push ${CI_REGISTRY}/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}
 | 
			
		||||
        docker push ${CI_REGISTRY}/esphomeyaml-hassio-${ADDON_ARCH}:dev
 | 
			
		||||
      fi
 | 
			
		||||
 | 
			
		||||
# Generic deploy template
 | 
			
		||||
.deploy-release: &deploy-release
 | 
			
		||||
  <<: *docker-builder
 | 
			
		||||
  stage: deploy
 | 
			
		||||
  script:
 | 
			
		||||
    - version="${CI_COMMIT_TAG#v}"
 | 
			
		||||
    - echo "Publishing release version ${version}"
 | 
			
		||||
    - docker pull "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}"
 | 
			
		||||
    - docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
 | 
			
		||||
    - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}" \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
 | 
			
		||||
    - docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}" \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
  only:
 | 
			
		||||
  - /^v\d+\.\d+\.\d+$/
 | 
			
		||||
  except:
 | 
			
		||||
  - /^(?!master).+@/
 | 
			
		||||
 | 
			
		||||
.deploy-beta: &deploy-beta
 | 
			
		||||
  <<: *docker-builder
 | 
			
		||||
  stage: deploy
 | 
			
		||||
  script:
 | 
			
		||||
    - version="${CI_COMMIT_TAG#v}"
 | 
			
		||||
    - echo "Publishing beta version ${version}"
 | 
			
		||||
    - docker pull "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}"
 | 
			
		||||
    - docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
    - docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}"
 | 
			
		||||
 | 
			
		||||
    - echo "Tag ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - |
 | 
			
		||||
      docker tag \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${version}" \
 | 
			
		||||
        "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
    - docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:rc"
 | 
			
		||||
  only:
 | 
			
		||||
  - /^v\d+\.\d+\.\d+b\d+$/
 | 
			
		||||
  except:
 | 
			
		||||
  - /^(?!rc).+@/
 | 
			
		||||
 | 
			
		||||
# Build jobs
 | 
			
		||||
build:normal:
 | 
			
		||||
  <<: *docker-builder
 | 
			
		||||
  stage: build
 | 
			
		||||
  script:
 | 
			
		||||
    - docker build -t "${CI_REGISTRY}/ottowinter/esphomeyaml:dev" .
 | 
			
		||||
 | 
			
		||||
.build-hassio-edge: &build-hassio-edge
 | 
			
		||||
  <<: *build-hassio
 | 
			
		||||
  except:
 | 
			
		||||
    - /^v\d+\.\d+\.\d+$/
 | 
			
		||||
    - /^v\d+\.\d+\.\d+b\d+$/
 | 
			
		||||
 | 
			
		||||
.build-hassio-release: &build-hassio-release
 | 
			
		||||
  <<: *build-hassio
 | 
			
		||||
  only:
 | 
			
		||||
    - /^v\d+\.\d+\.\d+$/
 | 
			
		||||
    - /^v\d+\.\d+\.\d+b\d+$/
 | 
			
		||||
 | 
			
		||||
build:hassio-armhf-edge:
 | 
			
		||||
  <<: *build-hassio-edge
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: armhf
 | 
			
		||||
    DO_PUSH: "false"
 | 
			
		||||
 | 
			
		||||
build:hassio-armhf:
 | 
			
		||||
  <<: *build-hassio-release
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: armhf
 | 
			
		||||
 | 
			
		||||
#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-i386-edge:
 | 
			
		||||
  <<: *build-hassio-edge
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: i386
 | 
			
		||||
    DO_PUSH: "false"
 | 
			
		||||
 | 
			
		||||
build:hassio-i386:
 | 
			
		||||
  <<: *build-hassio-release
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: i386
 | 
			
		||||
 | 
			
		||||
build:hassio-amd64-edge:
 | 
			
		||||
  <<: *build-hassio-edge
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: amd64
 | 
			
		||||
    DO_PUSH: "false"
 | 
			
		||||
 | 
			
		||||
build:hassio-amd64:
 | 
			
		||||
  <<: *build-hassio-release
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: amd64
 | 
			
		||||
 | 
			
		||||
# Deploy jobs
 | 
			
		||||
deploy-release:armhf:
 | 
			
		||||
  <<: *deploy-release
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: armhf
 | 
			
		||||
 | 
			
		||||
deploy-beta:armhf:
 | 
			
		||||
  <<: *deploy-beta
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: armhf
 | 
			
		||||
 | 
			
		||||
#deploy-release:aarch64:
 | 
			
		||||
#  <<: *deploy-release
 | 
			
		||||
#  variables:
 | 
			
		||||
#    ADDON_ARCH: aarch64
 | 
			
		||||
 | 
			
		||||
#deploy-beta:aarch64:
 | 
			
		||||
#  <<: *deploy-beta
 | 
			
		||||
#  variables:
 | 
			
		||||
#    ADDON_ARCH: aarch64
 | 
			
		||||
 | 
			
		||||
deploy-release:i386:
 | 
			
		||||
  <<: *deploy-release
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: i386
 | 
			
		||||
 | 
			
		||||
deploy-beta:i386:
 | 
			
		||||
  <<: *deploy-beta
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: i386
 | 
			
		||||
 | 
			
		||||
deploy-release:amd64:
 | 
			
		||||
  <<: *deploy-release
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: amd64
 | 
			
		||||
 | 
			
		||||
deploy-beta:amd64:
 | 
			
		||||
  <<: *deploy-beta
 | 
			
		||||
  variables:
 | 
			
		||||
    ADDON_ARCH: amd64
 | 
			
		||||
    - esphome tests/test3.yaml compile
 | 
			
		||||
 | 
			
		||||
.deploy-pypi: &deploy-pypi
 | 
			
		||||
  stage: deploy
 | 
			
		||||
  image: python:2.7
 | 
			
		||||
  before_script:
 | 
			
		||||
  - pip install -e .
 | 
			
		||||
  - pip install twine
 | 
			
		||||
  script:
 | 
			
		||||
  - python setup.py sdist
 | 
			
		||||
  - python setup.py sdist bdist_wheel
 | 
			
		||||
  - twine upload dist/*
 | 
			
		||||
  tags:
 | 
			
		||||
  - python2.7
 | 
			
		||||
  - esphomeyaml-test
 | 
			
		||||
  - docker
 | 
			
		||||
 | 
			
		||||
deploy-release:pypi:
 | 
			
		||||
  <<: *deploy-pypi
 | 
			
		||||
@@ -312,3 +144,204 @@ deploy-beta:pypi:
 | 
			
		||||
    - /^v\d+\.\d+\.\d+b\d+$/
 | 
			
		||||
  except:
 | 
			
		||||
    - /^(?!rc).+@/
 | 
			
		||||
 | 
			
		||||
.latest: &latest
 | 
			
		||||
  <<: *docker-base
 | 
			
		||||
  only:
 | 
			
		||||
  - /^v([0-9\.]+)$/
 | 
			
		||||
  except:
 | 
			
		||||
  - branches
 | 
			
		||||
 | 
			
		||||
.latest-vars: &latest-vars
 | 
			
		||||
  RELEASE: YES
 | 
			
		||||
  LATEST: YES
 | 
			
		||||
  # Also push to beta tag
 | 
			
		||||
  BETA: YES
 | 
			
		||||
 | 
			
		||||
.beta: &beta
 | 
			
		||||
  <<: *docker-base
 | 
			
		||||
  only:
 | 
			
		||||
  - /^v([0-9\.]+b\d+)$/
 | 
			
		||||
  except:
 | 
			
		||||
  - branches
 | 
			
		||||
 | 
			
		||||
.beta-vars: &beta-vars
 | 
			
		||||
  RELEASE: YES
 | 
			
		||||
  BETA: YES
 | 
			
		||||
 | 
			
		||||
.dev: &dev
 | 
			
		||||
  <<: *docker-base
 | 
			
		||||
  only:
 | 
			
		||||
  - dev
 | 
			
		||||
 | 
			
		||||
.dev-vars: &dev-vars
 | 
			
		||||
  DEV: YES
 | 
			
		||||
 | 
			
		||||
#aarch64-beta-docker:
 | 
			
		||||
#  <<: *beta
 | 
			
		||||
#  variables:
 | 
			
		||||
#    BETA: "YES"
 | 
			
		||||
#    BUILD_ARCH: aarch64
 | 
			
		||||
#    IS_HASSIO: "NO"
 | 
			
		||||
#    RELEASE: "YES"
 | 
			
		||||
#aarch64-beta-hassio:
 | 
			
		||||
#  <<: *beta
 | 
			
		||||
#  variables:
 | 
			
		||||
#    BETA: "YES"
 | 
			
		||||
#    BUILD_ARCH: aarch64
 | 
			
		||||
#    IS_HASSIO: "YES"
 | 
			
		||||
#    RELEASE: "YES"
 | 
			
		||||
#aarch64-dev-docker:
 | 
			
		||||
#  <<: *dev
 | 
			
		||||
#  variables:
 | 
			
		||||
#    BUILD_ARCH: aarch64
 | 
			
		||||
#    DEV: "YES"
 | 
			
		||||
#    IS_HASSIO: "NO"
 | 
			
		||||
#aarch64-dev-hassio:
 | 
			
		||||
#  <<: *dev
 | 
			
		||||
#  variables:
 | 
			
		||||
#    BUILD_ARCH: aarch64
 | 
			
		||||
#    DEV: "YES"
 | 
			
		||||
#    IS_HASSIO: "YES"
 | 
			
		||||
#aarch64-latest-docker:
 | 
			
		||||
#  <<: *latest
 | 
			
		||||
#  variables:
 | 
			
		||||
#    BETA: "YES"
 | 
			
		||||
#    BUILD_ARCH: aarch64
 | 
			
		||||
#    IS_HASSIO: "NO"
 | 
			
		||||
#    LATEST: "YES"
 | 
			
		||||
#    RELEASE: "YES"
 | 
			
		||||
#aarch64-latest-hassio:
 | 
			
		||||
#  <<: *latest
 | 
			
		||||
#  variables:
 | 
			
		||||
#    BETA: "YES"
 | 
			
		||||
#    BUILD_ARCH: aarch64
 | 
			
		||||
#    IS_HASSIO: "YES"
 | 
			
		||||
#    LATEST: "YES"
 | 
			
		||||
#    RELEASE: "YES"
 | 
			
		||||
amd64-beta-docker:
 | 
			
		||||
  <<: *beta
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: amd64
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
amd64-beta-hassio:
 | 
			
		||||
  <<: *beta
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: amd64
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
amd64-dev-docker:
 | 
			
		||||
  <<: *dev
 | 
			
		||||
  variables:
 | 
			
		||||
    BUILD_ARCH: amd64
 | 
			
		||||
    DEV: "YES"
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
amd64-dev-hassio:
 | 
			
		||||
  <<: *dev
 | 
			
		||||
  variables:
 | 
			
		||||
    BUILD_ARCH: amd64
 | 
			
		||||
    DEV: "YES"
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
amd64-latest-docker:
 | 
			
		||||
  <<: *latest
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: amd64
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
    LATEST: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
amd64-latest-hassio:
 | 
			
		||||
  <<: *latest
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: amd64
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
    LATEST: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
armhf-beta-docker:
 | 
			
		||||
  <<: *beta
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: armhf
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
armhf-beta-hassio:
 | 
			
		||||
  <<: *beta
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: armhf
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
armhf-dev-docker:
 | 
			
		||||
  <<: *dev
 | 
			
		||||
  variables:
 | 
			
		||||
    BUILD_ARCH: armhf
 | 
			
		||||
    DEV: "YES"
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
armhf-dev-hassio:
 | 
			
		||||
  <<: *dev
 | 
			
		||||
  variables:
 | 
			
		||||
    BUILD_ARCH: armhf
 | 
			
		||||
    DEV: "YES"
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
armhf-latest-docker:
 | 
			
		||||
  <<: *latest
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: armhf
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
    LATEST: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
armhf-latest-hassio:
 | 
			
		||||
  <<: *latest
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: armhf
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
    LATEST: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
i386-beta-docker:
 | 
			
		||||
  <<: *beta
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: i386
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
i386-beta-hassio:
 | 
			
		||||
  <<: *beta
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: i386
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
i386-dev-docker:
 | 
			
		||||
  <<: *dev
 | 
			
		||||
  variables:
 | 
			
		||||
    BUILD_ARCH: i386
 | 
			
		||||
    DEV: "YES"
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
i386-dev-hassio:
 | 
			
		||||
  <<: *dev
 | 
			
		||||
  variables:
 | 
			
		||||
    BUILD_ARCH: i386
 | 
			
		||||
    DEV: "YES"
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
i386-latest-docker:
 | 
			
		||||
  <<: *latest
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: i386
 | 
			
		||||
    IS_HASSIO: "NO"
 | 
			
		||||
    LATEST: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
i386-latest-hassio:
 | 
			
		||||
  <<: *latest
 | 
			
		||||
  variables:
 | 
			
		||||
    BETA: "YES"
 | 
			
		||||
    BUILD_ARCH: i386
 | 
			
		||||
    IS_HASSIO: "YES"
 | 
			
		||||
    LATEST: "YES"
 | 
			
		||||
    RELEASE: "YES"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								.travis.yml
									
									
									
									
									
								
							@@ -1,6 +1,13 @@
 | 
			
		||||
sudo: false
 | 
			
		||||
language: python
 | 
			
		||||
 | 
			
		||||
cache:
 | 
			
		||||
  directories:
 | 
			
		||||
    - "~/.platformio"
 | 
			
		||||
    - "$TRAVIS_BUILD_DIR/tests/build/test1/.piolibdeps"
 | 
			
		||||
    - "$TRAVIS_BUILD_DIR/tests/build/test2/.piolibdeps"
 | 
			
		||||
    - "$TRAVIS_BUILD_DIR/tests/build/test3/.piolibdeps"
 | 
			
		||||
 | 
			
		||||
matrix:
 | 
			
		||||
  fast_finish: true
 | 
			
		||||
  include:
 | 
			
		||||
@@ -8,23 +15,24 @@ matrix:
 | 
			
		||||
      env: TARGET=Lint2.7
 | 
			
		||||
      install: pip install -e . && pip install flake8==3.6.0 pylint==1.9.4 pillow
 | 
			
		||||
      script:
 | 
			
		||||
        - flake8 esphomeyaml
 | 
			
		||||
        - pylint esphomeyaml
 | 
			
		||||
        - flake8 esphome
 | 
			
		||||
        - pylint esphome
 | 
			
		||||
    - python: "3.5.3"
 | 
			
		||||
      env: TARGET=Lint3.5
 | 
			
		||||
      install: pip install -U https://github.com/platformio/platformio-core/archive/develop.zip && pip install -e . && pip install flake8==3.6.0 pylint==2.2.2 pillow
 | 
			
		||||
      install: pip install -U https://github.com/platformio/platformio-core/archive/develop.zip && pip install -e . && pip install flake8==3.6.0 pylint==2.3.0 pillow
 | 
			
		||||
      script:
 | 
			
		||||
        - flake8 esphomeyaml
 | 
			
		||||
        - pylint esphomeyaml
 | 
			
		||||
        - flake8 esphome
 | 
			
		||||
        - pylint esphome
 | 
			
		||||
    - python: "2.7"
 | 
			
		||||
      env: TARGET=Test2.7
 | 
			
		||||
      install: pip install -e . && pip install flake8==3.6.0 pylint==1.9.4 pillow
 | 
			
		||||
      script:
 | 
			
		||||
        - esphomeyaml tests/test1.yaml compile
 | 
			
		||||
        - esphomeyaml tests/test2.yaml compile
 | 
			
		||||
    - python: "3.5.3"
 | 
			
		||||
      env: TARGET=Test3.5
 | 
			
		||||
      install: pip install -U https://github.com/platformio/platformio-core/archive/develop.zip && pip install -e . && pip install flake8==3.6.0 pylint==2.2.2 pillow
 | 
			
		||||
      script:
 | 
			
		||||
        - esphomeyaml tests/test1.yaml compile
 | 
			
		||||
        - esphomeyaml tests/test2.yaml compile
 | 
			
		||||
        - esphome tests/test1.yaml compile
 | 
			
		||||
        - esphome tests/test2.yaml compile
 | 
			
		||||
        - esphome tests/test3.yaml compile
 | 
			
		||||
    #- python: "3.5.3"
 | 
			
		||||
    #  env: TARGET=Test3.5
 | 
			
		||||
    #  install: pip install -U https://github.com/platformio/platformio-core/archive/develop.zip && pip install -e . && pip install flake8==3.6.0 pylint==2.3.0 pillow
 | 
			
		||||
    #  script:
 | 
			
		||||
    #    - esphome tests/test1.yaml compile
 | 
			
		||||
    #    - esphome tests/test2.yaml compile
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,16 @@
 | 
			
		||||
# Contributing to esphomeyaml
 | 
			
		||||
# Contributing to ESPHome
 | 
			
		||||
 | 
			
		||||
esphomeyaml is a part of esphomelib and is responsible for reading in YAML configuration files,
 | 
			
		||||
This python project is responsible for reading in YAML configuration files,
 | 
			
		||||
converting them to C++ code. This code is then converted to a platformio project and compiled
 | 
			
		||||
with [esphomelib](https://github.com/OttoWinter/esphomelib), the C++ framework behind the project.
 | 
			
		||||
with [esphome-core](https://github.com/esphome/esphome-core), the C++ framework behind the project.
 | 
			
		||||
 | 
			
		||||
For a detailed guide, please see https://esphomelib.com/esphomeyaml/guides/contributing.html#contributing-to-esphomeyaml
 | 
			
		||||
For a detailed guide, please see https://esphome.io/guides/contributing.html#contributing-to-esphomeyaml
 | 
			
		||||
 | 
			
		||||
Things to note when contributing:
 | 
			
		||||
 | 
			
		||||
 - Please test your changes :)
 | 
			
		||||
 - If a new feature is added or an existing user-facing feature is changed, you should also 
 | 
			
		||||
   update the [docs](https://github.com/OttoWinter/esphomedocs). See [contributing to esphomedocs](https://esphomelib.com/esphomeyaml/guides/contributing.html#contributing-to-esphomedocs)
 | 
			
		||||
   update the [docs](https://github.com/esphome/esphome-docs). See [contributing to esphome-docs](https://esphome.io/guides/contributing.html#contributing-to-esphomedocs)
 | 
			
		||||
   for more information.
 | 
			
		||||
 - Please also update the tests in the `tests/` folder. You can do so by just adding a line in one of the YAML files
 | 
			
		||||
   which checks if your new feature compiles correctly.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								Dockerfile
									
									
									
									
									
								
							@@ -1,28 +0,0 @@
 | 
			
		||||
ARG BUILD_FROM=python:2.7
 | 
			
		||||
FROM ${BUILD_FROM}
 | 
			
		||||
MAINTAINER Otto Winter <contact@otto-winter.com>
 | 
			
		||||
 | 
			
		||||
RUN apt-get update && apt-get install -y \
 | 
			
		||||
        python-pil \
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
ENV ESPHOMEYAML_OTA_HOST_PORT=6123
 | 
			
		||||
EXPOSE 6123
 | 
			
		||||
VOLUME /config
 | 
			
		||||
WORKDIR /usr/src/app
 | 
			
		||||
 | 
			
		||||
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 .
 | 
			
		||||
 | 
			
		||||
WORKDIR /config
 | 
			
		||||
ENTRYPOINT ["esphomeyaml"]
 | 
			
		||||
CMD ["/config", "dashboard"]
 | 
			
		||||
							
								
								
									
										21
									
								
								MANIFEST.in
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								MANIFEST.in
									
									
									
									
									
								
							@@ -1,17 +1,6 @@
 | 
			
		||||
include LICENSE
 | 
			
		||||
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
 | 
			
		||||
include esphomeyaml/dashboard/static/ext-searchbox.js
 | 
			
		||||
include esphome/dashboard/templates/*.html
 | 
			
		||||
include esphome/dashboard/static/*.js
 | 
			
		||||
include esphome/dashboard/static/*.css
 | 
			
		||||
include esphome/dashboard/static/*.ico
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										39
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								README.md
									
									
									
									
									
								
							@@ -1,38 +1,9 @@
 | 
			
		||||
# esphomeyaml for [esphomelib](https://github.com/OttoWinter/esphomelib)
 | 
			
		||||
# ESPHome [](https://travis-ci.org/esphome/esphome) [](https://discord.gg/KhAMKrd) [](https://GitHub.com/esphome/esphome/releases/)
 | 
			
		||||
 | 
			
		||||
### Getting Started Guide: https://esphomelib.com/esphomeyaml/guides/getting_started_command_line.html
 | 
			
		||||
[](https://esphome.io/)
 | 
			
		||||
 | 
			
		||||
### Available Components: https://esphomelib.com/esphomeyaml/index.html
 | 
			
		||||
**Documentation:** https://esphome.io/
 | 
			
		||||
 | 
			
		||||
esphomeyaml is the solution for your ESP8266/ESP32 projects with Home Assistant. It allows you to create **custom firmwares** for your microcontrollers with no programming experience required. All you need to know is the YAML configuration format which is also used by [Home Assistant](https://www.home-assistant.io).
 | 
			
		||||
For issues, please go to [the issue tracker](https://github.com/esphome/issues/issues).
 | 
			
		||||
 | 
			
		||||
esphomeyaml will:
 | 
			
		||||
 | 
			
		||||
 * Read your configuration file and warn you about potential errors (like using the invalid pins.)
 | 
			
		||||
 * Create a custom C++ sketch file for you using esphomeyaml's powerful C++ generation engine.
 | 
			
		||||
 * Compile the sketch file for you using [platformio](http://platformio.org/).
 | 
			
		||||
 * Upload the binary to your ESP via Over the Air updates.
 | 
			
		||||
 * Automatically start remote logs via MQTT.
 | 
			
		||||
 | 
			
		||||
And all of that with a single command 🎉:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
esphomeyaml configuration.yaml run
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Features
 | 
			
		||||
 | 
			
		||||
 * **No programming experience required:** just edit YAML configuration
 | 
			
		||||
    files like you're used to with Home Assistant.
 | 
			
		||||
 * **Flexible:** Use [esphomelib](https://github.com/OttoWinter/esphomelib)'s powerful core to create custom sensors/outputs.
 | 
			
		||||
 * **Fast and efficient:** Written in C++ and keeps memory consumption to a minimum.
 | 
			
		||||
 * **Made for [Home Assistant](https://www.home-assistant.io):** Almost all [Home Assistant](https://www.home-assistant.io) features are supported out of the box. Including RGB lights and many more.
 | 
			
		||||
 * **Easy reproducible configuration:** No need to go through a long setup process for every single node. Just copy a configuration file and run a single command.
 | 
			
		||||
 * **Smart Over The Air Updates:** esphomeyaml has OTA updates deeply integrated into the system. It even automatically enters a recovery mode if a boot loop is detected.
 | 
			
		||||
 * **Powerful logging engine:** View colorful logs and debug issues remotely.
 | 
			
		||||
 * **Open Source**
 | 
			
		||||
 * For me: Makes documenting esphomelib's features a lot easier.
 | 
			
		||||
 | 
			
		||||
## Special Thanks
 | 
			
		||||
 | 
			
		||||
Special Thanks to the Home Assistant project. Lots of the code base of esphomeyaml is based off of Home Assistant, for example the loading and config validation code.
 | 
			
		||||
For feature requests, please see [feature requests](https://github.com/esphome/feature-requests/issues).
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								docker/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								docker/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
ARG BUILD_FROM=esphome/esphome-base-amd64:1.3.0
 | 
			
		||||
FROM ${BUILD_FROM}
 | 
			
		||||
 | 
			
		||||
COPY . .
 | 
			
		||||
RUN \
 | 
			
		||||
    pip2 install --no-cache-dir --no-binary :all: -e .
 | 
			
		||||
 | 
			
		||||
WORKDIR /config
 | 
			
		||||
ENTRYPOINT ["esphome"]
 | 
			
		||||
CMD ["/config", "dashboard"]
 | 
			
		||||
@@ -1,30 +0,0 @@
 | 
			
		||||
FROM multiarch/ubuntu-core:amd64-xenial
 | 
			
		||||
 | 
			
		||||
# setup locals
 | 
			
		||||
RUN apt-get update && apt-get install -y \
 | 
			
		||||
        jq \
 | 
			
		||||
        git \
 | 
			
		||||
        python3-setuptools \
 | 
			
		||||
    && rm -rf /var/lib/apt/lists/* \
 | 
			
		||||
ENV LANG C.UTF-8
 | 
			
		||||
 | 
			
		||||
# Install docker
 | 
			
		||||
# https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
 | 
			
		||||
RUN apt-get update && apt-get install -y \
 | 
			
		||||
        apt-transport-https \
 | 
			
		||||
        ca-certificates \
 | 
			
		||||
        curl \
 | 
			
		||||
        software-properties-common \
 | 
			
		||||
    && rm -rf /var/lib/apt/lists/* \
 | 
			
		||||
    && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
 | 
			
		||||
    && add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
 | 
			
		||||
    && apt-get update && apt-get install -y docker-ce \
 | 
			
		||||
    && rm -rf /var/lib/apt/lists/*
 | 
			
		||||
 | 
			
		||||
# setup arm binary support
 | 
			
		||||
RUN apt-get update && apt-get install -y \
 | 
			
		||||
        qemu-user-static \
 | 
			
		||||
        binfmt-support \
 | 
			
		||||
    && rm -rf /var/lib/apt/lists/*
 | 
			
		||||
 | 
			
		||||
WORKDIR /data
 | 
			
		||||
@@ -1,75 +1,20 @@
 | 
			
		||||
ARG BUILD_FROM=hassioaddons/ubuntu-base:2.2.0
 | 
			
		||||
# hadolint ignore=DL3006
 | 
			
		||||
ARG BUILD_FROM=esphome/esphome-hassio-base-amd64:1.3.0
 | 
			
		||||
FROM ${BUILD_FROM}
 | 
			
		||||
 | 
			
		||||
# 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
 | 
			
		||||
COPY docker/rootfs/ /
 | 
			
		||||
COPY setup.py setup.cfg MANIFEST.in /opt/esphome/
 | 
			
		||||
COPY esphome /opt/esphome/esphome
 | 
			
		||||
 | 
			
		||||
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 \
 | 
			
		||||
        # 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 \
 | 
			
		||||
    \
 | 
			
		||||
    # 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/
 | 
			
		||||
    pip2 install --no-cache-dir --no-binary :all: -e /opt/esphome
 | 
			
		||||
 | 
			
		||||
# Build arugments
 | 
			
		||||
ARG BUILD_ARCH=amd64
 | 
			
		||||
ARG BUILD_DATE
 | 
			
		||||
ARG BUILD_REF
 | 
			
		||||
ARG BUILD_VERSION
 | 
			
		||||
# Build arguments
 | 
			
		||||
ARG BUILD_VERSION=dev
 | 
			
		||||
 | 
			
		||||
# Labels
 | 
			
		||||
LABEL \
 | 
			
		||||
    io.hass.name="esphomeyaml" \
 | 
			
		||||
    io.hass.name="ESPHome" \
 | 
			
		||||
    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" \
 | 
			
		||||
    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"
 | 
			
		||||
    io.hass.version=${BUILD_VERSION}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								docker/hooks/build
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								docker/hooks/build
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
# the Docker repository tag being built.
 | 
			
		||||
declare CACHE_TAG
 | 
			
		||||
echo "CACHE_TAG: ${CACHE_TAG}"
 | 
			
		||||
# the name and tag of the Docker repository being built. (This variable is a combination of DOCKER_REPO:CACHE_TAG.)
 | 
			
		||||
declare IMAGE_NAME
 | 
			
		||||
echo "IMAGE_NAME: ${IMAGE_NAME}"
 | 
			
		||||
# the architecture to build
 | 
			
		||||
declare BUILD_ARCH
 | 
			
		||||
echo "BUILD_ARCH: ${BUILD_ARCH}"
 | 
			
		||||
# whether this is a hassio build
 | 
			
		||||
declare IS_HASSIO
 | 
			
		||||
echo "IS_HASSIO: ${IS_HASSIO}"
 | 
			
		||||
echo "PWD: $PWD"
 | 
			
		||||
 | 
			
		||||
if [[ ${IS_HASSIO} = "YES" ]]; then
 | 
			
		||||
    docker build \
 | 
			
		||||
      --build-arg "BUILD_FROM=esphome/esphome-hassio-base-${BUILD_ARCH}:1.3.0" \
 | 
			
		||||
      --build-arg "BUILD_VERSION=${CACHE_TAG}" \
 | 
			
		||||
      -t "${IMAGE_NAME}" -f ../docker/Dockerfile.hassio ..
 | 
			
		||||
else
 | 
			
		||||
    docker build \
 | 
			
		||||
      --build-arg "BUILD_FROM=esphome/esphome-base-${BUILD_ARCH}:1.3.0" \
 | 
			
		||||
      -t "${IMAGE_NAME}" -f ../docker/Dockerfile ..
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										18
									
								
								docker/hooks/pre_build
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										18
									
								
								docker/hooks/pre_build
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
# the architecture to build
 | 
			
		||||
declare BUILD_ARCH
 | 
			
		||||
 | 
			
		||||
echo "BUILD_ARCH: ${BUILD_ARCH}"
 | 
			
		||||
 | 
			
		||||
if [[ ${BUILD_ARCH} = "amd64" ]]; then
 | 
			
		||||
    echo "No qemu required..."
 | 
			
		||||
    exit 0
 | 
			
		||||
fi
 | 
			
		||||
if [[ ${BUILD_ARCH} = "i386" ]]; then
 | 
			
		||||
    echo "No qemu required..."
 | 
			
		||||
    exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "Installing qemu..."
 | 
			
		||||
docker run --rm --privileged multiarch/qemu-user-static:register --reset
 | 
			
		||||
@@ -2,11 +2,11 @@
 | 
			
		||||
; platforms
 | 
			
		||||
 | 
			
		||||
[env:espressif8266]
 | 
			
		||||
platform = espressif8266
 | 
			
		||||
platform = espressif8266@1.8.0
 | 
			
		||||
board = nodemcuv2
 | 
			
		||||
framework = arduino
 | 
			
		||||
 | 
			
		||||
[env:espressif32]
 | 
			
		||||
platform = espressif32
 | 
			
		||||
platform = espressif32@1.5.0
 | 
			
		||||
board = nodemcu-32s
 | 
			
		||||
framework = arduino
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
#!/usr/bin/with-contenv bash
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: esphomeyaml
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# This files check if all user configuration requirements are met
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# shellcheck disable=SC1091
 | 
			
		||||
@@ -22,7 +22,7 @@ if hass.config.true 'ssl'; then
 | 
			
		||||
            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
 | 
			
		||||
            to encrypt connections to the ESPHome dashboard, you can manually disable
 | 
			
		||||
            SSL by setting \"ssl\" to false."
 | 
			
		||||
            hass.die "${text}"
 | 
			
		||||
        fi
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
#!/usr/bin/with-contenv bash
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: esphomeyaml
 | 
			
		||||
# Configures NGINX for use with esphomeyaml
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# Configures NGINX for use with ESPHome
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# shellcheck disable=SC1091
 | 
			
		||||
source /usr/lib/hassio-addons/base.sh
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
#!/usr/bin/with-contenv bash
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: esphomeyaml
 | 
			
		||||
# This files installs the user esphomeyaml version if specified
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# This files installs the user ESPHome version if specified
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# shellcheck disable=SC1091
 | 
			
		||||
source /usr/lib/hassio-addons/base.sh
 | 
			
		||||
 | 
			
		||||
declare esphomeyaml_version
 | 
			
		||||
declare esphome_version
 | 
			
		||||
 | 
			
		||||
if hass.config.has_value 'esphomeyaml_version'; then
 | 
			
		||||
    esphomeyaml_version=$(hass.config.get 'esphomeyaml_version')
 | 
			
		||||
    pip2 install --no-cache-dir --no-binary :all: "https://github.com/OttoWinter/esphomeyaml/archive/${esphomeyaml_version}.zip"
 | 
			
		||||
if hass.config.has_value 'esphome_version'; then
 | 
			
		||||
    esphome_version=$(hass.config.get 'esphome_version')
 | 
			
		||||
    pip2 install --no-cache-dir --no-binary :all: "https://github.com/esphome/esphome/archive/${esphome_version}.zip"
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										13
									
								
								docker/rootfs/etc/cont-init.d/40-migrate.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								docker/rootfs/etc/cont-init.d/40-migrate.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
#!/usr/bin/with-contenv bash
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# This files migrates the esphome config directory from the old path
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# shellcheck disable=SC1091
 | 
			
		||||
source /usr/lib/hassio-addons/base.sh
 | 
			
		||||
 | 
			
		||||
if [[ ! -d /config/esphome && -d /config/esphomeyaml ]]; then
 | 
			
		||||
    echo "Moving config directory from /config/esphomeyaml to /config/esphome"
 | 
			
		||||
    mv /config/esphomeyaml /config/esphome
 | 
			
		||||
    mv /config/esphome/.esphomeyaml /config/esphome/.esphome
 | 
			
		||||
fi
 | 
			
		||||
@@ -13,9 +13,9 @@ http {
 | 
			
		||||
    sendfile           on;
 | 
			
		||||
    keepalive_timeout  65;
 | 
			
		||||
 | 
			
		||||
    upstream esphomeyaml {
 | 
			
		||||
    upstream esphome {
 | 
			
		||||
        ip_hash;
 | 
			
		||||
        server unix:/var/run/esphomeyaml.sock;
 | 
			
		||||
        server unix:/var/run/esphome.sock;
 | 
			
		||||
    }
 | 
			
		||||
    map $http_upgrade $connection_upgrade {
 | 
			
		||||
        default upgrade;
 | 
			
		||||
@@ -45,7 +45,7 @@ http {
 | 
			
		||||
 | 
			
		||||
        location / {
 | 
			
		||||
            proxy_redirect off;
 | 
			
		||||
            proxy_pass http://esphomeyaml;
 | 
			
		||||
            proxy_pass http://esphome;
 | 
			
		||||
 | 
			
		||||
            proxy_http_version 1.1;
 | 
			
		||||
            proxy_set_header Upgrade $http_upgrade;
 | 
			
		||||
@@ -13,9 +13,9 @@ http {
 | 
			
		||||
    sendfile           on;
 | 
			
		||||
    keepalive_timeout  65;
 | 
			
		||||
 | 
			
		||||
    upstream esphomeyaml {
 | 
			
		||||
    upstream esphome {
 | 
			
		||||
        ip_hash;
 | 
			
		||||
        server unix:/var/run/esphomeyaml.sock;
 | 
			
		||||
        server unix:/var/run/esphome.sock;
 | 
			
		||||
    }
 | 
			
		||||
    map $http_upgrade $connection_upgrade {
 | 
			
		||||
        default upgrade;
 | 
			
		||||
@@ -29,7 +29,7 @@ http {
 | 
			
		||||
 | 
			
		||||
        location / {
 | 
			
		||||
            proxy_redirect off;
 | 
			
		||||
            proxy_pass http://esphomeyaml;
 | 
			
		||||
            proxy_pass http://esphome;
 | 
			
		||||
 | 
			
		||||
            proxy_http_version 1.1;
 | 
			
		||||
            proxy_set_header Upgrade $http_upgrade;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
#!/usr/bin/execlineb -S0
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: esphomeyaml
 | 
			
		||||
# Take down the S6 supervision tree when esphomeyaml fails
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# Take down the S6 supervision tree when ESPHome fails
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
if -n { s6-test $# -ne 0 }
 | 
			
		||||
if -n { s6-test ${1} -eq 256 }
 | 
			
		||||
							
								
								
									
										28
									
								
								docker/rootfs/etc/services.d/esphome/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										28
									
								
								docker/rootfs/etc/services.d/esphome/run
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#!/usr/bin/with-contenv bash
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# Runs the ESPHome dashboard
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# shellcheck disable=SC1091
 | 
			
		||||
source /usr/lib/hassio-addons/base.sh
 | 
			
		||||
 | 
			
		||||
export ESPHOME_IS_HASSIO=true
 | 
			
		||||
 | 
			
		||||
if hass.config.true 'leave_front_door_open'; then
 | 
			
		||||
    export DISABLE_HA_AUTHENTICATION=true
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if hass.config.true 'streamer_mode'; then
 | 
			
		||||
    export ESPHOME_STREAMER_MODE=true
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if hass.config.true 'status_use_ping'; then
 | 
			
		||||
    export ESPHOME_DASHBOARD_USE_PING=true
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if hass.config.has_value 'relative_url'; then
 | 
			
		||||
    export ESPHOME_DASHBOARD_RELATIVE_URL=$(hass.config.get 'relative_url')
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
hass.log.info "Starting ESPHome dashboard..."
 | 
			
		||||
exec esphome /config/esphome dashboard --socket /var/run/esphome.sock --hassio
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
#!/usr/bin/execlineb -S0
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: esphomeyaml
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# Take down the S6 supervision tree when NGINX fails
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
if -n { s6-test $# -ne 0 }
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
#!/usr/bin/with-contenv bash
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Community Hass.io Add-ons: esphomeyaml
 | 
			
		||||
# Community Hass.io Add-ons: ESPHome
 | 
			
		||||
# Runs the NGINX proxy
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# shellcheck disable=SC1091
 | 
			
		||||
@@ -1,29 +1,28 @@
 | 
			
		||||
from __future__ import print_function
 | 
			
		||||
 | 
			
		||||
import argparse
 | 
			
		||||
from collections import OrderedDict
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
import logging
 | 
			
		||||
import os
 | 
			
		||||
import random
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import const, core_config, mqtt, platformio_api, wizard, writer, yaml_util
 | 
			
		||||
from esphomeyaml.api.client import run_logs
 | 
			
		||||
from esphomeyaml.config import get_component, iter_components, read_config, strip_default_ids
 | 
			
		||||
from esphomeyaml.const import CONF_BAUD_RATE, CONF_ESPHOMEYAML, CONF_LOGGER, CONF_USE_CUSTOM_CODE, \
 | 
			
		||||
    CONF_BROKER
 | 
			
		||||
from esphomeyaml.core import CORE, EsphomeyamlError
 | 
			
		||||
from esphomeyaml.cpp_generator import Expression, RawStatement, add, statement
 | 
			
		||||
from esphomeyaml.helpers import color, indent
 | 
			
		||||
from esphomeyaml.py_compat import safe_input, text_type, IS_PY2
 | 
			
		||||
from esphomeyaml.storage_json import StorageJSON, esphomeyaml_storage_path, \
 | 
			
		||||
    start_update_check_thread, storage_path
 | 
			
		||||
from esphomeyaml.util import run_external_command, safe_print
 | 
			
		||||
from esphome import const, core_config, mqtt, platformio_api, wizard, writer, yaml_util
 | 
			
		||||
from esphome.api.client import run_logs
 | 
			
		||||
from esphome.config import get_component, iter_components, read_config, strip_default_ids
 | 
			
		||||
from esphome.const import CONF_BAUD_RATE, CONF_BROKER, CONF_ESPHOME, CONF_LOGGER, \
 | 
			
		||||
    CONF_USE_CUSTOM_CODE
 | 
			
		||||
from esphome.core import CORE, EsphomeError
 | 
			
		||||
from esphome.cpp_generator import Expression, RawStatement, add, statement
 | 
			
		||||
from esphome.helpers import color, indent
 | 
			
		||||
from esphome.py_compat import IS_PY2, safe_input, text_type
 | 
			
		||||
from esphome.storage_json import StorageJSON, storage_path
 | 
			
		||||
from esphome.util import run_external_command, run_external_process, safe_print, \
 | 
			
		||||
    is_dev_esphome_version
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
PRE_INITIALIZE = ['esphomeyaml', 'logger', 'wifi', 'ethernet', 'ota', 'mqtt', 'web_server', 'api',
 | 
			
		||||
PRE_INITIALIZE = ['esphome', 'logger', 'wifi', 'ethernet', 'ota', 'mqtt', 'web_server', 'api',
 | 
			
		||||
                  'i2c']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -127,9 +126,9 @@ def run_miniterm(config, port):
 | 
			
		||||
def write_cpp(config):
 | 
			
		||||
    _LOGGER.info("Generating C++ source...")
 | 
			
		||||
 | 
			
		||||
    CORE.add_job(core_config.to_code, config[CONF_ESPHOMEYAML], domain='esphomeyaml')
 | 
			
		||||
    CORE.add_job(core_config.to_code, config[CONF_ESPHOME], domain='esphome')
 | 
			
		||||
    for domain in PRE_INITIALIZE:
 | 
			
		||||
        if domain == CONF_ESPHOMEYAML or domain not in config:
 | 
			
		||||
        if domain == CONF_ESPHOME or domain not in config:
 | 
			
		||||
            continue
 | 
			
		||||
        CORE.add_job(get_component(domain).to_code, config[domain], domain=domain)
 | 
			
		||||
 | 
			
		||||
@@ -143,7 +142,7 @@ def write_cpp(config):
 | 
			
		||||
    add(RawStatement(''))
 | 
			
		||||
    all_code = []
 | 
			
		||||
    for exp in CORE.expressions:
 | 
			
		||||
        if not config[CONF_ESPHOMEYAML][CONF_USE_CUSTOM_CODE]:
 | 
			
		||||
        if not config[CONF_ESPHOME][CONF_USE_CUSTOM_CODE]:
 | 
			
		||||
            if isinstance(exp, Expression) and not exp.required:
 | 
			
		||||
                continue
 | 
			
		||||
        all_code.append(text_type(statement(exp)))
 | 
			
		||||
@@ -157,23 +156,30 @@ def write_cpp(config):
 | 
			
		||||
 | 
			
		||||
def compile_program(args, config):
 | 
			
		||||
    _LOGGER.info("Compiling app...")
 | 
			
		||||
    update_check = not os.getenv('ESPHOMEYAML_NO_UPDATE_CHECK', '')
 | 
			
		||||
    if update_check:
 | 
			
		||||
        thread = start_update_check_thread(esphomeyaml_storage_path(CORE.config_dir))
 | 
			
		||||
    rc = platformio_api.run_compile(config, args.verbose)
 | 
			
		||||
    if update_check:
 | 
			
		||||
        thread.join()
 | 
			
		||||
    if rc != 0 and CORE.is_dev_esphome_core_version and not is_dev_esphome_version():
 | 
			
		||||
        _LOGGER.warning("You're using 'esphome_core_version: dev' but not using the "
 | 
			
		||||
                        "dev version of the ESPHome tool.")
 | 
			
		||||
        _LOGGER.warning("Expect compile errors if these versions are out of sync.")
 | 
			
		||||
        _LOGGER.warning("Please install the dev version of ESPHome too when using "
 | 
			
		||||
                        "'esphome_core_version: dev'.")
 | 
			
		||||
        _LOGGER.warning(" - Hass.io: Install 'ESPHome (dev)' addon")
 | 
			
		||||
        _LOGGER.warning(" - Docker: docker run [...] esphome/esphome:dev [...]")
 | 
			
		||||
        _LOGGER.warning(" - PIP: pip install -U https://github.com/esphome/esphome/archive/dev.zip")
 | 
			
		||||
    return rc
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def upload_using_esptool(config, port):
 | 
			
		||||
    import esptool
 | 
			
		||||
 | 
			
		||||
    path = os.path.join(CORE.build_path, '.pioenvs', CORE.name, 'firmware.bin')
 | 
			
		||||
    path = CORE.firmware_bin
 | 
			
		||||
    cmd = ['esptool.py', '--before', 'default_reset', '--after', 'hard_reset',
 | 
			
		||||
           '--chip', 'esp8266', '--port', port, 'write_flash', '0x0', path]
 | 
			
		||||
    # pylint: disable=protected-access
 | 
			
		||||
    return run_external_command(esptool._main, *cmd)
 | 
			
		||||
 | 
			
		||||
    if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
 | 
			
		||||
        import esptool
 | 
			
		||||
        # pylint: disable=protected-access
 | 
			
		||||
        return run_external_command(esptool._main, *cmd)
 | 
			
		||||
 | 
			
		||||
    return run_external_process(*cmd)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def upload_program(config, args, host):
 | 
			
		||||
@@ -183,13 +189,13 @@ def upload_program(config, args, host):
 | 
			
		||||
            return upload_using_esptool(config, host)
 | 
			
		||||
        return platformio_api.run_upload(config, args.verbose, host)
 | 
			
		||||
 | 
			
		||||
    from esphomeyaml.components import ota
 | 
			
		||||
    from esphomeyaml import espota2
 | 
			
		||||
    from esphome.components import ota
 | 
			
		||||
    from esphome import espota2
 | 
			
		||||
 | 
			
		||||
    if args.host_port is not None:
 | 
			
		||||
        host_port = args.host_port
 | 
			
		||||
    else:
 | 
			
		||||
        host_port = int(os.getenv('ESPHOMEYAML_OTA_HOST_PORT', random.randint(10000, 60000)))
 | 
			
		||||
        host_port = int(os.getenv('ESPHOME_OTA_HOST_PORT', random.randint(10000, 60000)))
 | 
			
		||||
 | 
			
		||||
    verbose = args.verbose
 | 
			
		||||
    remote_port = ota.get_port(config)
 | 
			
		||||
@@ -211,12 +217,14 @@ def upload_program(config, args, host):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def show_logs(config, args, port):
 | 
			
		||||
    if 'logger' not in config:
 | 
			
		||||
        raise EsphomeError("Logger is not configured!")
 | 
			
		||||
    if get_port_type(port) == 'SERIAL':
 | 
			
		||||
        run_miniterm(config, port)
 | 
			
		||||
        return 0
 | 
			
		||||
    if get_port_type(port) == 'NETWORK':
 | 
			
		||||
    if get_port_type(port) == 'NETWORK' and 'api' in config:
 | 
			
		||||
        return run_logs(config, port)
 | 
			
		||||
    if get_port_type(port) == 'MQTT':
 | 
			
		||||
    if get_port_type(port) == 'MQTT' and 'mqtt' in config:
 | 
			
		||||
        return mqtt.show_logs(config, args.topic, args.username, args.password, args.client_id)
 | 
			
		||||
 | 
			
		||||
    raise ValueError
 | 
			
		||||
@@ -339,30 +347,8 @@ def command_clean(args, config):
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def command_hass_config(args, config):
 | 
			
		||||
    from esphomeyaml.components import mqtt as mqtt_component
 | 
			
		||||
 | 
			
		||||
    _LOGGER.info("This is what you should put in your Home Assistant YAML configuration.")
 | 
			
		||||
    _LOGGER.info("Please note this is only necessary if you're not using MQTT discovery.")
 | 
			
		||||
    data = mqtt_component.GenerateHassConfigData(config)
 | 
			
		||||
    hass_config = OrderedDict()
 | 
			
		||||
    for domain, component, conf in iter_components(config):
 | 
			
		||||
        if not hasattr(component, 'to_hass_config'):
 | 
			
		||||
            continue
 | 
			
		||||
        func = getattr(component, 'to_hass_config')
 | 
			
		||||
        ret = func(data, conf)
 | 
			
		||||
        if not isinstance(ret, (list, tuple)):
 | 
			
		||||
            ret = [ret]
 | 
			
		||||
        ret = [x for x in ret if x is not None]
 | 
			
		||||
        domain_conf = hass_config.setdefault(domain.split('.')[0], [])
 | 
			
		||||
        domain_conf += ret
 | 
			
		||||
 | 
			
		||||
    safe_print(yaml_util.dump(hass_config))
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def command_dashboard(args):
 | 
			
		||||
    from esphomeyaml.dashboard import dashboard
 | 
			
		||||
    from esphome.dashboard import dashboard
 | 
			
		||||
 | 
			
		||||
    return dashboard.start_web_server(args)
 | 
			
		||||
 | 
			
		||||
@@ -382,13 +368,12 @@ POST_CONFIG_ACTIONS = {
 | 
			
		||||
    'clean-mqtt': command_clean_mqtt,
 | 
			
		||||
    'mqtt-fingerprint': command_mqtt_fingerprint,
 | 
			
		||||
    'clean': command_clean,
 | 
			
		||||
    'hass-config': command_hass_config,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def parse_args(argv):
 | 
			
		||||
    parser = argparse.ArgumentParser(prog='esphomeyaml')
 | 
			
		||||
    parser.add_argument('-v', '--verbose', help="Enable verbose esphomeyaml logs.",
 | 
			
		||||
    parser = argparse.ArgumentParser(prog='esphome')
 | 
			
		||||
    parser.add_argument('-v', '--verbose', help="Enable verbose esphome logs.",
 | 
			
		||||
                        action='store_true')
 | 
			
		||||
    parser.add_argument('--dashboard', help="Internal flag to set if the command is run from the "
 | 
			
		||||
                                            "dashboard.", action='store_true')
 | 
			
		||||
@@ -439,11 +424,11 @@ def parse_args(argv):
 | 
			
		||||
    parser_clean.add_argument('--client-id', help='Manually set the client id.')
 | 
			
		||||
 | 
			
		||||
    subparsers.add_parser('wizard', help="A helpful setup wizard that will guide "
 | 
			
		||||
                                         "you through setting up esphomeyaml.")
 | 
			
		||||
                                         "you through setting up esphome.")
 | 
			
		||||
 | 
			
		||||
    subparsers.add_parser('mqtt-fingerprint', help="Get the SSL fingerprint from a MQTT broker.")
 | 
			
		||||
 | 
			
		||||
    subparsers.add_parser('version', help="Print the esphomeyaml version and exit.")
 | 
			
		||||
    subparsers.add_parser('version', help="Print the esphome version and exit.")
 | 
			
		||||
 | 
			
		||||
    subparsers.add_parser('clean', help="Delete all temporary build files.")
 | 
			
		||||
 | 
			
		||||
@@ -456,20 +441,16 @@ def parse_args(argv):
 | 
			
		||||
    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 "
 | 
			
		||||
                           help="Internal flag used to tell esphome is started as a Hass.io "
 | 
			
		||||
                                "add-on.",
 | 
			
		||||
                           action="store_true")
 | 
			
		||||
    dashboard.add_argument("--socket",
 | 
			
		||||
                           help="Make the dashboard serve under a unix socket", type=str)
 | 
			
		||||
 | 
			
		||||
    subparsers.add_parser('hass-config',
 | 
			
		||||
                          help="Dump the configuration entries that should be added "
 | 
			
		||||
                               "to Home Assistant when not using MQTT discovery.")
 | 
			
		||||
 | 
			
		||||
    return parser.parse_args(argv[1:])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def run_esphomeyaml(argv):
 | 
			
		||||
def run_esphome(argv):
 | 
			
		||||
    args = parse_args(argv)
 | 
			
		||||
    CORE.dashboard = args.dashboard
 | 
			
		||||
 | 
			
		||||
@@ -477,7 +458,7 @@ def run_esphomeyaml(argv):
 | 
			
		||||
    if args.command in PRE_CONFIG_ACTIONS:
 | 
			
		||||
        try:
 | 
			
		||||
            return PRE_CONFIG_ACTIONS[args.command](args)
 | 
			
		||||
        except EsphomeyamlError as e:
 | 
			
		||||
        except EsphomeError as e:
 | 
			
		||||
            _LOGGER.error(e)
 | 
			
		||||
            return 1
 | 
			
		||||
 | 
			
		||||
@@ -491,7 +472,7 @@ def run_esphomeyaml(argv):
 | 
			
		||||
    if args.command in POST_CONFIG_ACTIONS:
 | 
			
		||||
        try:
 | 
			
		||||
            return POST_CONFIG_ACTIONS[args.command](args, config)
 | 
			
		||||
        except EsphomeyamlError as e:
 | 
			
		||||
        except EsphomeError as e:
 | 
			
		||||
            _LOGGER.error(e)
 | 
			
		||||
            return 1
 | 
			
		||||
    safe_print(u"Unknown command {}".format(args.command))
 | 
			
		||||
@@ -500,8 +481,8 @@ def run_esphomeyaml(argv):
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    try:
 | 
			
		||||
        return run_esphomeyaml(sys.argv)
 | 
			
		||||
    except EsphomeyamlError as e:
 | 
			
		||||
        return run_esphome(sys.argv)
 | 
			
		||||
    except EsphomeError as e:
 | 
			
		||||
        _LOGGER.error(e)
 | 
			
		||||
        return 1
 | 
			
		||||
    except KeyboardInterrupt:
 | 
			
		||||
@@ -92,7 +92,7 @@ message DeviceInfoResponse {
 | 
			
		||||
 | 
			
		||||
  // A string describing the date of compilation, this is generated by the compiler
 | 
			
		||||
  // and therefore may not be in the same format all the time.
 | 
			
		||||
  // If the user isn't using esphomeyaml, this will also not be set.
 | 
			
		||||
  // If the user isn't using esphome, this will also not be set.
 | 
			
		||||
  string compilation_time = 5;
 | 
			
		||||
 | 
			
		||||
  // The model of the board. For example NodeMCU
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
# Generated by the protocol buffer compiler.  DO NOT EDIT!
 | 
			
		||||
# source: api.proto
 | 
			
		||||
 | 
			
		||||
@@ -9,18 +9,18 @@ import time
 | 
			
		||||
from typing import Optional  # noqa
 | 
			
		||||
from google.protobuf import message  # noqa
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import const
 | 
			
		||||
import esphomeyaml.api.api_pb2 as pb
 | 
			
		||||
from esphomeyaml.const import CONF_PASSWORD, CONF_PORT
 | 
			
		||||
from esphomeyaml.core import EsphomeyamlError
 | 
			
		||||
from esphomeyaml.helpers import resolve_ip_address, indent, color
 | 
			
		||||
from esphomeyaml.py_compat import text_type, IS_PY2, byte_to_bytes, char_to_byte, format_bytes
 | 
			
		||||
from esphomeyaml.util import safe_print
 | 
			
		||||
from esphome import const
 | 
			
		||||
import esphome.api.api_pb2 as pb
 | 
			
		||||
from esphome.const import CONF_PASSWORD, CONF_PORT
 | 
			
		||||
from esphome.core import EsphomeError
 | 
			
		||||
from esphome.helpers import resolve_ip_address, indent, color
 | 
			
		||||
from esphome.py_compat import text_type, IS_PY2, byte_to_bytes, char_to_byte, format_bytes
 | 
			
		||||
from esphome.util import safe_print
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class APIConnectionError(EsphomeyamlError):
 | 
			
		||||
class APIConnectionError(EsphomeError):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -179,11 +179,11 @@ class APIClient(threading.Thread):
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            ip = resolve_ip_address(self._address)
 | 
			
		||||
        except EsphomeyamlError as err:
 | 
			
		||||
        except EsphomeError as err:
 | 
			
		||||
            _LOGGER.warning("Error resolving IP address of %s. Is it connected to WiFi?",
 | 
			
		||||
                            self._address)
 | 
			
		||||
            _LOGGER.warning("(If this error persists, please set a static IP address: "
 | 
			
		||||
                            "https://esphomelib.com/esphomeyaml/components/wifi.html#manual-ips)")
 | 
			
		||||
                            "https://esphome.io/components/wifi.html#manual-ips)")
 | 
			
		||||
            raise APIConnectionError(err)
 | 
			
		||||
 | 
			
		||||
        _LOGGER.info("Connecting to %s:%s (%s)", self._address, self._port, ip)
 | 
			
		||||
@@ -200,7 +200,7 @@ class APIClient(threading.Thread):
 | 
			
		||||
        self._socket_open_event.set()
 | 
			
		||||
 | 
			
		||||
        hello = pb.HelloRequest()
 | 
			
		||||
        hello.client_info = 'esphomeyaml v{}'.format(const.__version__)
 | 
			
		||||
        hello.client_info = 'ESPHome v{}'.format(const.__version__)
 | 
			
		||||
        try:
 | 
			
		||||
            resp = self._send_message_await_response(hello, pb.HelloResponse)
 | 
			
		||||
        except APIConnectionError as err:
 | 
			
		||||
@@ -423,12 +423,14 @@ def run_logs(config, address):
 | 
			
		||||
    conf = config['api']
 | 
			
		||||
    port = conf[CONF_PORT]
 | 
			
		||||
    password = conf[CONF_PASSWORD]
 | 
			
		||||
    _LOGGER.info("Starting log output from %s using esphomelib API", address)
 | 
			
		||||
    _LOGGER.info("Starting log output from %s using esphome API", address)
 | 
			
		||||
 | 
			
		||||
    cli = APIClient(address, port, password)
 | 
			
		||||
    stopping = False
 | 
			
		||||
    retry_timer = []
 | 
			
		||||
 | 
			
		||||
    has_connects = []
 | 
			
		||||
 | 
			
		||||
    def try_connect(tries=0, is_disconnect=True):
 | 
			
		||||
        if stopping:
 | 
			
		||||
            return
 | 
			
		||||
@@ -451,8 +453,13 @@ def run_logs(config, address):
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        wait_time = min(2**tries, 300)
 | 
			
		||||
        _LOGGER.warning(u"Couldn't connect to API (%s). Trying to reconnect in %s seconds",
 | 
			
		||||
                        error, wait_time)
 | 
			
		||||
        if not has_connects:
 | 
			
		||||
            _LOGGER.warning(u"Initial connection failed. The ESP might not be connected "
 | 
			
		||||
                            u"to WiFi yet (%s). Re-Trying in %s seconds",
 | 
			
		||||
                            error, wait_time)
 | 
			
		||||
        else:
 | 
			
		||||
            _LOGGER.warning(u"Couldn't connect to API (%s). Trying to reconnect in %s seconds",
 | 
			
		||||
                            error, wait_time)
 | 
			
		||||
        timer = threading.Timer(wait_time, functools.partial(try_connect, tries + 1, is_disconnect))
 | 
			
		||||
        timer.start()
 | 
			
		||||
        retry_timer.append(timer)
 | 
			
		||||
@@ -465,8 +472,6 @@ def run_logs(config, address):
 | 
			
		||||
                                  'TCP buffer - This is only cosmetic)')
 | 
			
		||||
        safe_print(time_ + text)
 | 
			
		||||
 | 
			
		||||
    has_connects = []
 | 
			
		||||
 | 
			
		||||
    def on_login():
 | 
			
		||||
        try:
 | 
			
		||||
            cli.subscribe_logs(on_log, dump_config=not has_connects)
 | 
			
		||||
@@ -2,16 +2,16 @@ import copy
 | 
			
		||||
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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, 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, void, bool_
 | 
			
		||||
from esphomeyaml.util import ServiceRegistry
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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, CONF_WAIT_UNTIL, CONF_WHILE
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, TemplateArguments, add, get_variable, \
 | 
			
		||||
    process_lambda, templatable
 | 
			
		||||
from esphome.cpp_types import Action, App, Component, PollingComponent, Trigger, bool_, \
 | 
			
		||||
    esphome_ns, float_, uint32, void
 | 
			
		||||
from esphome.util import ServiceRegistry
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def maybe_simple_id(*validators):
 | 
			
		||||
@@ -48,7 +48,7 @@ def validate_recursive_condition(value):
 | 
			
		||||
                              u"".format(key, key2), path)
 | 
			
		||||
        validator = CONDITION_REGISTRY[key][0]
 | 
			
		||||
        try:
 | 
			
		||||
            condition = validator(item[key])
 | 
			
		||||
            condition = validator(item[key] or {})
 | 
			
		||||
        except vol.Invalid as err:
 | 
			
		||||
            err.prepend(path)
 | 
			
		||||
            raise err
 | 
			
		||||
@@ -83,7 +83,7 @@ def validate_recursive_action(value):
 | 
			
		||||
                              u"".format(key, key2), path)
 | 
			
		||||
        validator = ACTION_REGISTRY[key][0]
 | 
			
		||||
        try:
 | 
			
		||||
            action = validator(item[key])
 | 
			
		||||
            action = validator(item[key] or {})
 | 
			
		||||
        except vol.Invalid as err:
 | 
			
		||||
            err.prepend(path)
 | 
			
		||||
            raise err
 | 
			
		||||
@@ -98,22 +98,27 @@ 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')
 | 
			
		||||
DelayAction = esphome_ns.class_('DelayAction', Action, Component)
 | 
			
		||||
LambdaAction = esphome_ns.class_('LambdaAction', Action)
 | 
			
		||||
IfAction = esphome_ns.class_('IfAction', Action)
 | 
			
		||||
WhileAction = esphome_ns.class_('WhileAction', Action)
 | 
			
		||||
WaitUntilAction = esphome_ns.class_('WaitUntilAction', Action, Component)
 | 
			
		||||
UpdateComponentAction = esphome_ns.class_('UpdateComponentAction', Action)
 | 
			
		||||
Automation = esphome_ns.class_('Automation')
 | 
			
		||||
 | 
			
		||||
Condition = esphomelib_ns.class_('Condition')
 | 
			
		||||
AndCondition = esphomelib_ns.class_('AndCondition', Condition)
 | 
			
		||||
OrCondition = esphomelib_ns.class_('OrCondition', Condition)
 | 
			
		||||
RangeCondition = esphomelib_ns.class_('RangeCondition', Condition)
 | 
			
		||||
LambdaCondition = esphomelib_ns.class_('LambdaCondition', Condition)
 | 
			
		||||
Condition = esphome_ns.class_('Condition')
 | 
			
		||||
AndCondition = esphome_ns.class_('AndCondition', Condition)
 | 
			
		||||
OrCondition = esphome_ns.class_('OrCondition', Condition)
 | 
			
		||||
RangeCondition = esphome_ns.class_('RangeCondition', Condition)
 | 
			
		||||
LambdaCondition = esphome_ns.class_('LambdaCondition', Condition)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_automation(extra_schema=None, extra_validators=None, single=False):
 | 
			
		||||
    schema = AUTOMATION_SCHEMA.extend(extra_schema or {})
 | 
			
		||||
    if extra_schema is None:
 | 
			
		||||
        extra_schema = {}
 | 
			
		||||
    if isinstance(extra_schema, vol.Schema):
 | 
			
		||||
        extra_schema = extra_schema.schema
 | 
			
		||||
    schema = AUTOMATION_SCHEMA.extend(extra_schema)
 | 
			
		||||
 | 
			
		||||
    def validator_(value):
 | 
			
		||||
        if isinstance(value, list):
 | 
			
		||||
@@ -121,9 +126,12 @@ def validate_automation(extra_schema=None, extra_validators=None, single=False):
 | 
			
		||||
                # First try as a sequence of actions
 | 
			
		||||
                return [schema({CONF_THEN: value})]
 | 
			
		||||
            except vol.Invalid as err:
 | 
			
		||||
                if err.path and err.path[0] == CONF_THEN:
 | 
			
		||||
                    err.path.pop(0)
 | 
			
		||||
 | 
			
		||||
                # Next try as a sequence of automations
 | 
			
		||||
                try:
 | 
			
		||||
                    return vol.Schema([schema])(value)
 | 
			
		||||
                    return cv.Schema([schema])(value)
 | 
			
		||||
                except vol.Invalid as err2:
 | 
			
		||||
                    if 'Unable to find action' in str(err):
 | 
			
		||||
                        raise err2
 | 
			
		||||
@@ -138,7 +146,7 @@ def validate_automation(extra_schema=None, extra_validators=None, single=False):
 | 
			
		||||
    def validator(value):
 | 
			
		||||
        value = validator_(value)
 | 
			
		||||
        if extra_validators is not None:
 | 
			
		||||
            value = vol.Schema([extra_validators])(value)
 | 
			
		||||
            value = cv.Schema([extra_validators])(value)
 | 
			
		||||
        if single:
 | 
			
		||||
            if len(value) != 1:
 | 
			
		||||
                raise vol.Invalid("Cannot have more than 1 automation for templates")
 | 
			
		||||
@@ -148,10 +156,9 @@ def validate_automation(extra_schema=None, extra_validators=None, single=False):
 | 
			
		||||
    return validator
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
AUTOMATION_SCHEMA = vol.Schema({
 | 
			
		||||
AUTOMATION_SCHEMA = cv.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): validate_recursive_condition,
 | 
			
		||||
    vol.Required(CONF_THEN): validate_recursive_action,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
@@ -159,8 +166,8 @@ AND_CONDITION_SCHEMA = validate_recursive_condition
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@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):
 | 
			
		||||
def and_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    for conditions in build_conditions(config, template_arg, args):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = AndCondition.new(template_arg, conditions)
 | 
			
		||||
    type = AndCondition.template(template_arg)
 | 
			
		||||
@@ -171,33 +178,33 @@ 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):
 | 
			
		||||
def or_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    for conditions in build_conditions(config, template_arg, args):
 | 
			
		||||
        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({
 | 
			
		||||
RANGE_CONDITION_SCHEMA = vol.All(cv.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):
 | 
			
		||||
def range_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    for conditions in build_conditions(config, template_arg, args):
 | 
			
		||||
        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_):
 | 
			
		||||
        for template_ in templatable(config[CONF_ABOVE], args, float_):
 | 
			
		||||
            yield
 | 
			
		||||
        condition.set_min(template_)
 | 
			
		||||
    if CONF_BELOW in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_BELOW], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_BELOW], args, float_):
 | 
			
		||||
            yield
 | 
			
		||||
        condition.set_max(template_)
 | 
			
		||||
    yield condition
 | 
			
		||||
@@ -207,11 +214,11 @@ 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):
 | 
			
		||||
def delay_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    rhs = App.register_component(DelayAction.new(template_arg))
 | 
			
		||||
    type = DelayAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    for template_ in templatable(config, arg_type, uint32):
 | 
			
		||||
    for template_ in templatable(config, args, uint32):
 | 
			
		||||
        yield
 | 
			
		||||
    add(action.set_delay(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
@@ -225,48 +232,71 @@ 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):
 | 
			
		||||
    for conditions in build_conditions(config[CONF_CONDITION], arg_type):
 | 
			
		||||
def if_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for conditions in build_conditions(config[CONF_CONDITION], template_arg, args):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = IfAction.new(template_arg, conditions)
 | 
			
		||||
    type = IfAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    if CONF_THEN in config:
 | 
			
		||||
        for actions in build_actions(config[CONF_THEN], arg_type):
 | 
			
		||||
        for actions in build_actions(config[CONF_THEN], template_arg, args):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.add_then(actions))
 | 
			
		||||
    if CONF_ELSE in config:
 | 
			
		||||
        for actions in build_actions(config[CONF_ELSE], arg_type):
 | 
			
		||||
        for actions in build_actions(config[CONF_ELSE], template_arg, args):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.add_else(actions))
 | 
			
		||||
    yield action
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WHILE_ACTION_SCHEMA = vol.Schema({
 | 
			
		||||
WHILE_ACTION_SCHEMA = cv.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):
 | 
			
		||||
def while_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for conditions in build_conditions(config[CONF_CONDITION], template_arg, args):
 | 
			
		||||
        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):
 | 
			
		||||
    for actions in build_actions(config[CONF_THEN], template_arg, args):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.add_then(actions))
 | 
			
		||||
    yield action
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_wait_until(value):
 | 
			
		||||
    schema = cv.Schema({
 | 
			
		||||
        vol.Required(CONF_CONDITION): validate_recursive_condition
 | 
			
		||||
    })
 | 
			
		||||
    if isinstance(value, dict) and CONF_CONDITION in value:
 | 
			
		||||
        return schema(value)
 | 
			
		||||
    return validate_wait_until({CONF_CONDITION: value})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WAIT_UNTIL_ACTION_SCHEMA = validate_wait_until
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_WAIT_UNTIL, WAIT_UNTIL_ACTION_SCHEMA)
 | 
			
		||||
def wait_until_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for conditions in build_conditions(config[CONF_CONDITION], template_arg, args):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = WaitUntilAction.new(template_arg, conditions)
 | 
			
		||||
    type = WaitUntilAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    add(App.register_component(action))
 | 
			
		||||
    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):
 | 
			
		||||
    for lambda_ in process_lambda(config, [(arg_type, 'x')], return_type=void):
 | 
			
		||||
def lambda_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for lambda_ in process_lambda(config, args, return_type=void):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = LambdaAction.new(template_arg, lambda_)
 | 
			
		||||
    type = LambdaAction.template(template_arg)
 | 
			
		||||
@@ -277,8 +307,8 @@ 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')], return_type=bool_):
 | 
			
		||||
def lambda_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    for lambda_ in process_lambda(config, args, return_type=bool_):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = LambdaCondition.new(template_arg, lambda_)
 | 
			
		||||
    type = LambdaCondition.template(template_arg)
 | 
			
		||||
@@ -292,70 +322,63 @@ 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):
 | 
			
		||||
def component_update_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = UpdateComponentAction.new(var)
 | 
			
		||||
    rhs = UpdateComponentAction.new(template_arg, var)
 | 
			
		||||
    type = UpdateComponentAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_action(full_config, arg_type):
 | 
			
		||||
def build_action(full_config, template_arg, args):
 | 
			
		||||
    action_id = full_config[CONF_ACTION_ID]
 | 
			
		||||
    key, config = next((k, v) for k, v in full_config.items() if k in ACTION_REGISTRY)
 | 
			
		||||
 | 
			
		||||
    builder = ACTION_REGISTRY[key][1]
 | 
			
		||||
    template_arg = TemplateArguments(arg_type)
 | 
			
		||||
    for result in builder(config, action_id, arg_type, template_arg):
 | 
			
		||||
    for result in builder(config, action_id, template_arg, args):
 | 
			
		||||
        yield None
 | 
			
		||||
    yield result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_actions(config, arg_type):
 | 
			
		||||
def build_actions(config, templ, arg_type):
 | 
			
		||||
    actions = []
 | 
			
		||||
    for conf in config:
 | 
			
		||||
        action = None
 | 
			
		||||
        for action in build_action(conf, arg_type):
 | 
			
		||||
        for action in build_action(conf, templ, arg_type):
 | 
			
		||||
            yield None
 | 
			
		||||
        actions.append(action)
 | 
			
		||||
    yield ArrayInitializer(*actions, multiline=False)
 | 
			
		||||
    yield actions
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_condition(full_config, arg_type):
 | 
			
		||||
def build_condition(full_config, template_arg, args):
 | 
			
		||||
    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):
 | 
			
		||||
    for result in builder(config, action_id, template_arg, args):
 | 
			
		||||
        yield None
 | 
			
		||||
    yield result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_conditions(config, arg_type):
 | 
			
		||||
def build_conditions(config, templ, args):
 | 
			
		||||
    conditions = []
 | 
			
		||||
    for conf in config:
 | 
			
		||||
        for condition in build_condition(conf, arg_type):
 | 
			
		||||
        for condition in build_condition(conf, templ, args):
 | 
			
		||||
            yield None
 | 
			
		||||
        conditions.append(condition)
 | 
			
		||||
    yield ArrayInitializer(*conditions, multiline=False)
 | 
			
		||||
    yield conditions
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_automation_(trigger, arg_type, config):
 | 
			
		||||
    rhs = App.make_automation(TemplateArguments(arg_type), trigger)
 | 
			
		||||
    type = Automation.template(arg_type)
 | 
			
		||||
def build_automation_(trigger, args, config):
 | 
			
		||||
    arg_types = [arg[0] for arg in args]
 | 
			
		||||
    templ = TemplateArguments(*arg_types)
 | 
			
		||||
    rhs = App.make_automation(templ, trigger)
 | 
			
		||||
    type = Automation.template(templ)
 | 
			
		||||
    obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type)
 | 
			
		||||
    if CONF_IF in config:
 | 
			
		||||
        conditions = None
 | 
			
		||||
        for conditions in build_conditions(config[CONF_IF], arg_type):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(obj.add_conditions(conditions))
 | 
			
		||||
    actions = None
 | 
			
		||||
    for actions in build_actions(config[CONF_THEN], arg_type):
 | 
			
		||||
    for actions in build_actions(config[CONF_THEN], templ, args):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(obj.add_actions(actions))
 | 
			
		||||
    yield obj
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_automation(trigger, arg_type, config):
 | 
			
		||||
    CORE.add_job(build_automation_, trigger, arg_type, config)
 | 
			
		||||
def build_automations(trigger, args, config):
 | 
			
		||||
    CORE.add_job(build_automation_, trigger, args, config)
 | 
			
		||||
@@ -1,18 +1,18 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import i2c, sensor
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID
 | 
			
		||||
from esphomeyaml.cpp_generator import Pvariable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, Component
 | 
			
		||||
from esphome.components import i2c, sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_ID
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['i2c']
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
ADS1115Component = sensor.sensor_ns.class_('ADS1115Component', Component, i2c.I2CDevice)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(ADS1115Component),
 | 
			
		||||
    vol.Required(CONF_ADDRESS): cv.i2c_address,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import i2c, sensor
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_UPDATE_INTERVAL
 | 
			
		||||
from esphomeyaml.cpp_generator import Pvariable, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, PollingComponent
 | 
			
		||||
from esphome.components import i2c, sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_UPDATE_INTERVAL
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['i2c']
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
@@ -13,7 +13,7 @@ MULTI_CONF = True
 | 
			
		||||
CONF_APDS9960_ID = 'apds9960_id'
 | 
			
		||||
APDS9960 = sensor.sensor_ns.class_('APDS9960', PollingComponent, i2c.I2CDevice)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(APDS9960),
 | 
			
		||||
    vol.Optional(CONF_ADDRESS): cv.i2c_address,
 | 
			
		||||
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
 | 
			
		||||
							
								
								
									
										141
									
								
								esphome/components/api.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								esphome/components/api.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,141 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import automation
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, CONDITION_REGISTRY, Condition
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_DATA, CONF_DATA_TEMPLATE, CONF_ID, CONF_PASSWORD, CONF_PORT, \
 | 
			
		||||
    CONF_REBOOT_TIMEOUT, CONF_SERVICE, CONF_VARIABLES, CONF_SERVICES, CONF_TRIGGER_ID
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import Action, App, Component, StoringController, esphome_ns, Trigger, \
 | 
			
		||||
    bool_, int32, float_, std_string
 | 
			
		||||
 | 
			
		||||
api_ns = esphome_ns.namespace('api')
 | 
			
		||||
APIServer = api_ns.class_('APIServer', Component, StoringController)
 | 
			
		||||
HomeAssistantServiceCallAction = api_ns.class_('HomeAssistantServiceCallAction', Action)
 | 
			
		||||
KeyValuePair = api_ns.class_('KeyValuePair')
 | 
			
		||||
TemplatableKeyValuePair = api_ns.class_('TemplatableKeyValuePair')
 | 
			
		||||
APIConnectedCondition = api_ns.class_('APIConnectedCondition', Condition)
 | 
			
		||||
 | 
			
		||||
UserService = api_ns.class_('UserService', Trigger)
 | 
			
		||||
ServiceTypeArgument = api_ns.class_('ServiceTypeArgument')
 | 
			
		||||
ServiceArgType = api_ns.enum('ServiceArgType')
 | 
			
		||||
SERVICE_ARG_TYPES = {
 | 
			
		||||
    'bool': ServiceArgType.SERVICE_ARG_TYPE_BOOL,
 | 
			
		||||
    'int': ServiceArgType.SERVICE_ARG_TYPE_INT,
 | 
			
		||||
    'float': ServiceArgType.SERVICE_ARG_TYPE_FLOAT,
 | 
			
		||||
    'string': ServiceArgType.SERVICE_ARG_TYPE_STRING,
 | 
			
		||||
}
 | 
			
		||||
SERVICE_ARG_NATIVE_TYPES = {
 | 
			
		||||
    'bool': bool_,
 | 
			
		||||
    'int': int32,
 | 
			
		||||
    'float': float_,
 | 
			
		||||
    'string': std_string,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(APIServer),
 | 
			
		||||
    vol.Optional(CONF_PORT, default=6053): cv.port,
 | 
			
		||||
    vol.Optional(CONF_PASSWORD, default=''): cv.string_strict,
 | 
			
		||||
    vol.Optional(CONF_REBOOT_TIMEOUT): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_SERVICES): automation.validate_automation({
 | 
			
		||||
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(UserService),
 | 
			
		||||
        vol.Required(CONF_SERVICE): cv.valid_name,
 | 
			
		||||
        vol.Optional(CONF_VARIABLES, default={}): cv.Schema({
 | 
			
		||||
            cv.validate_id_name: cv.one_of(*SERVICE_ARG_TYPES, lower=True),
 | 
			
		||||
        }),
 | 
			
		||||
    }),
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.init_api_server()
 | 
			
		||||
    api = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    if config[CONF_PORT] != 6053:
 | 
			
		||||
        add(api.set_port(config[CONF_PORT]))
 | 
			
		||||
    if config.get(CONF_PASSWORD):
 | 
			
		||||
        add(api.set_password(config[CONF_PASSWORD]))
 | 
			
		||||
    if CONF_REBOOT_TIMEOUT in config:
 | 
			
		||||
        add(api.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT]))
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_SERVICES, []):
 | 
			
		||||
        template_args = []
 | 
			
		||||
        func_args = []
 | 
			
		||||
        service_type_args = []
 | 
			
		||||
        for name, var_ in conf[CONF_VARIABLES].items():
 | 
			
		||||
            native = SERVICE_ARG_NATIVE_TYPES[var_]
 | 
			
		||||
            template_args.append(native)
 | 
			
		||||
            func_args.append((native, name))
 | 
			
		||||
            service_type_args.append(ServiceTypeArgument(name, SERVICE_ARG_TYPES[var_]))
 | 
			
		||||
        func = api.make_user_service_trigger.template(*template_args)
 | 
			
		||||
        rhs = func(conf[CONF_SERVICE], service_type_args)
 | 
			
		||||
        type_ = UserService.template(*template_args)
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs, type=type_)
 | 
			
		||||
        automation.build_automations(trigger, func_args, conf)
 | 
			
		||||
 | 
			
		||||
    setup_component(api, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_API'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def lib_deps(config):
 | 
			
		||||
    if CORE.is_esp32:
 | 
			
		||||
        return 'AsyncTCP@1.0.3'
 | 
			
		||||
    if CORE.is_esp8266:
 | 
			
		||||
        return 'ESPAsyncTCP@1.1.3'
 | 
			
		||||
    raise NotImplementedError
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_HOMEASSISTANT_SERVICE = 'homeassistant.service'
 | 
			
		||||
HOMEASSISTANT_SERVIC_ACTION_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.use_variable_id(APIServer),
 | 
			
		||||
    vol.Required(CONF_SERVICE): cv.string,
 | 
			
		||||
    vol.Optional(CONF_DATA): cv.Schema({
 | 
			
		||||
        cv.string: cv.string,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_DATA_TEMPLATE): cv.Schema({
 | 
			
		||||
        cv.string: cv.string,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_VARIABLES): cv.Schema({
 | 
			
		||||
        cv.string: cv.lambda_,
 | 
			
		||||
    }),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_HOMEASSISTANT_SERVICE, HOMEASSISTANT_SERVIC_ACTION_SCHEMA)
 | 
			
		||||
def homeassistant_service_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_home_assistant_service_call_action(template_arg)
 | 
			
		||||
    type = HomeAssistantServiceCallAction.template(template_arg)
 | 
			
		||||
    act = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    add(act.set_service(config[CONF_SERVICE]))
 | 
			
		||||
    if CONF_DATA in config:
 | 
			
		||||
        datas = [KeyValuePair(k, v) for k, v in config[CONF_DATA].items()]
 | 
			
		||||
        add(act.set_data(datas))
 | 
			
		||||
    if CONF_DATA_TEMPLATE in config:
 | 
			
		||||
        datas = [KeyValuePair(k, v) for k, v in config[CONF_DATA_TEMPLATE].items()]
 | 
			
		||||
        add(act.set_data_template(datas))
 | 
			
		||||
    if CONF_VARIABLES in config:
 | 
			
		||||
        datas = []
 | 
			
		||||
        for key, value in config[CONF_VARIABLES].items():
 | 
			
		||||
            for value_ in process_lambda(value, []):
 | 
			
		||||
                yield None
 | 
			
		||||
            datas.append(TemplatableKeyValuePair(key, value_))
 | 
			
		||||
        add(act.set_variables(datas))
 | 
			
		||||
    yield act
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_API_CONNECTED = 'api.connected'
 | 
			
		||||
API_CONNECTED_CONDITION_SCHEMA = cv.Schema({})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@CONDITION_REGISTRY.register(CONF_API_CONNECTED, API_CONNECTED_CONDITION_SCHEMA)
 | 
			
		||||
def api_connected_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    rhs = APIConnectedCondition.new(template_arg)
 | 
			
		||||
    type = APIConnectedCondition.template(template_arg)
 | 
			
		||||
    yield Pvariable(condition_id, rhs, type=type)
 | 
			
		||||
@@ -1,21 +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, \
 | 
			
		||||
from esphome import automation, core
 | 
			
		||||
from esphome.automation import CONDITION_REGISTRY, Condition, maybe_simple_id
 | 
			
		||||
from esphome.components import mqtt
 | 
			
		||||
from esphome.components.mqtt import setup_mqtt_component
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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, CONF_ON_STATE
 | 
			
		||||
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_, \
 | 
			
		||||
    optional
 | 
			
		||||
from esphomeyaml.py_compat import string_types
 | 
			
		||||
    CONF_ON_DOUBLE_CLICK, CONF_ON_MULTI_CLICK, CONF_ON_PRESS, CONF_ON_RELEASE, CONF_ON_STATE, \
 | 
			
		||||
    CONF_STATE, CONF_TIMING, CONF_TRIGGER_ID, CONF_FOR
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, StructInitializer, add, get_variable, process_lambda
 | 
			
		||||
from esphome.cpp_types import App, Component, Nameable, Trigger, bool_, esphome_ns, optional
 | 
			
		||||
from esphome.py_compat import string_types
 | 
			
		||||
 | 
			
		||||
DEVICE_CLASSES = [
 | 
			
		||||
    '', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas',
 | 
			
		||||
@@ -28,17 +26,17 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
binary_sensor_ns = esphomelib_ns.namespace('binary_sensor')
 | 
			
		||||
binary_sensor_ns = esphome_ns.namespace('binary_sensor')
 | 
			
		||||
BinarySensor = binary_sensor_ns.class_('BinarySensor', Nameable)
 | 
			
		||||
BinarySensorPtr = BinarySensor.operator('ptr')
 | 
			
		||||
MQTTBinarySensorComponent = binary_sensor_ns.class_('MQTTBinarySensorComponent', mqtt.MQTTComponent)
 | 
			
		||||
 | 
			
		||||
# Triggers
 | 
			
		||||
PressTrigger = binary_sensor_ns.class_('PressTrigger', Trigger.template(NoArg))
 | 
			
		||||
ReleaseTrigger = binary_sensor_ns.class_('ReleaseTrigger', Trigger.template(NoArg))
 | 
			
		||||
ClickTrigger = binary_sensor_ns.class_('ClickTrigger', Trigger.template(NoArg))
 | 
			
		||||
DoubleClickTrigger = binary_sensor_ns.class_('DoubleClickTrigger', Trigger.template(NoArg))
 | 
			
		||||
MultiClickTrigger = binary_sensor_ns.class_('MultiClickTrigger', Trigger.template(NoArg), Component)
 | 
			
		||||
PressTrigger = binary_sensor_ns.class_('PressTrigger', Trigger.template())
 | 
			
		||||
ReleaseTrigger = binary_sensor_ns.class_('ReleaseTrigger', Trigger.template())
 | 
			
		||||
ClickTrigger = binary_sensor_ns.class_('ClickTrigger', Trigger.template())
 | 
			
		||||
DoubleClickTrigger = binary_sensor_ns.class_('DoubleClickTrigger', Trigger.template())
 | 
			
		||||
MultiClickTrigger = binary_sensor_ns.class_('MultiClickTrigger', Trigger.template(), Component)
 | 
			
		||||
MultiClickTriggerEvent = binary_sensor_ns.struct('MultiClickTriggerEvent')
 | 
			
		||||
StateTrigger = binary_sensor_ns.class_('StateTrigger', Trigger.template(bool_))
 | 
			
		||||
 | 
			
		||||
@@ -53,18 +51,18 @@ HeartbeatFilter = binary_sensor_ns.class_('HeartbeatFilter', Filter, Component)
 | 
			
		||||
InvertFilter = binary_sensor_ns.class_('InvertFilter', Filter)
 | 
			
		||||
LambdaFilter = binary_sensor_ns.class_('LambdaFilter', Filter)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
FILTER_KEYS = [CONF_INVERT, CONF_DELAYED_ON, CONF_DELAYED_OFF, CONF_LAMBDA, CONF_HEARTBEAT]
 | 
			
		||||
 | 
			
		||||
FILTERS_SCHEMA = cv.ensure_list({
 | 
			
		||||
    vol.Optional(CONF_INVERT): None,
 | 
			
		||||
    vol.Optional(CONF_DELAYED_ON): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_DELAYED_OFF): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_HEARTBEAT): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
 | 
			
		||||
    vol.Optional(CONF_HEARTBEAT): cv.invalid("The heartbeat filter has been removed in 1.11.0"),
 | 
			
		||||
}, cv.has_exactly_one_key(*FILTER_KEYS))
 | 
			
		||||
 | 
			
		||||
MULTI_CLICK_TIMING_SCHEMA = vol.Schema({
 | 
			
		||||
MULTI_CLICK_TIMING_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Optional(CONF_STATE): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_MIN_LENGTH): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_MAX_LENGTH): cv.positive_time_period_milliseconds,
 | 
			
		||||
@@ -191,7 +189,7 @@ BINARY_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_INVERTED): cv.invalid(
 | 
			
		||||
        "The inverted binary_sensor property has been replaced by the "
 | 
			
		||||
        "new 'invert' binary  sensor filter. Please see "
 | 
			
		||||
        "https://esphomelib.com/esphomeyaml/components/binary_sensor/index.html."
 | 
			
		||||
        "https://esphome.io/components/binary_sensor/index.html."
 | 
			
		||||
    ),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
@@ -205,8 +203,6 @@ def setup_filter(config):
 | 
			
		||||
        yield App.register_component(DelayedOffFilter.new(config[CONF_DELAYED_OFF]))
 | 
			
		||||
    elif CONF_DELAYED_ON in config:
 | 
			
		||||
        yield App.register_component(DelayedOnFilter.new(config[CONF_DELAYED_ON]))
 | 
			
		||||
    elif CONF_HEARTBEAT in config:
 | 
			
		||||
        yield App.register_component(HeartbeatFilter.new(config[CONF_HEARTBEAT]))
 | 
			
		||||
    elif CONF_LAMBDA in config:
 | 
			
		||||
        for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')],
 | 
			
		||||
                                      return_type=optional.template(bool_)):
 | 
			
		||||
@@ -217,14 +213,13 @@ def setup_filter(config):
 | 
			
		||||
def setup_filters(config):
 | 
			
		||||
    filters = []
 | 
			
		||||
    for conf in config:
 | 
			
		||||
        filter = None
 | 
			
		||||
        for filter in setup_filter(conf):
 | 
			
		||||
            yield None
 | 
			
		||||
        filters.append(filter)
 | 
			
		||||
    yield ArrayInitializer(*filters)
 | 
			
		||||
    yield filters
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
 | 
			
		||||
def setup_binary_sensor_core_(binary_sensor_var, config):
 | 
			
		||||
    if CONF_INTERNAL in config:
 | 
			
		||||
        add(binary_sensor_var.set_internal(CONF_INTERNAL))
 | 
			
		||||
    if CONF_DEVICE_CLASS in config:
 | 
			
		||||
@@ -232,7 +227,6 @@ def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
 | 
			
		||||
    if CONF_INVERTED in config:
 | 
			
		||||
        add(binary_sensor_var.set_inverted(config[CONF_INVERTED]))
 | 
			
		||||
    if CONF_FILTERS in config:
 | 
			
		||||
        filters = None
 | 
			
		||||
        for filters in setup_filters(config[CONF_FILTERS]):
 | 
			
		||||
            yield
 | 
			
		||||
        add(binary_sensor_var.add_filters(filters))
 | 
			
		||||
@@ -240,23 +234,23 @@ def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
 | 
			
		||||
    for conf in config.get(CONF_ON_PRESS, []):
 | 
			
		||||
        rhs = binary_sensor_var.make_press_trigger()
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        automation.build_automation(trigger, NoArg, conf)
 | 
			
		||||
        automation.build_automations(trigger, [], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_RELEASE, []):
 | 
			
		||||
        rhs = binary_sensor_var.make_release_trigger()
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        automation.build_automation(trigger, NoArg, conf)
 | 
			
		||||
        automation.build_automations(trigger, [], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_CLICK, []):
 | 
			
		||||
        rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH])
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        automation.build_automation(trigger, NoArg, conf)
 | 
			
		||||
        automation.build_automations(trigger, [], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_DOUBLE_CLICK, []):
 | 
			
		||||
        rhs = binary_sensor_var.make_double_click_trigger(conf[CONF_MIN_LENGTH],
 | 
			
		||||
                                                          conf[CONF_MAX_LENGTH])
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        automation.build_automation(trigger, NoArg, conf)
 | 
			
		||||
        automation.build_automations(trigger, [], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_MULTI_CLICK, []):
 | 
			
		||||
        timings = []
 | 
			
		||||
@@ -267,74 +261,61 @@ def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config):
 | 
			
		||||
                ('min_length', tim[CONF_MIN_LENGTH]),
 | 
			
		||||
                ('max_length', tim.get(CONF_MAX_LENGTH, 4294967294)),
 | 
			
		||||
            ))
 | 
			
		||||
        timings = ArrayInitializer(*timings, multiline=False)
 | 
			
		||||
        rhs = App.register_component(binary_sensor_var.make_multi_click_trigger(timings))
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        if CONF_INVALID_COOLDOWN in conf:
 | 
			
		||||
            add(trigger.set_invalid_cooldown(conf[CONF_INVALID_COOLDOWN]))
 | 
			
		||||
        automation.build_automation(trigger, NoArg, conf)
 | 
			
		||||
        automation.build_automations(trigger, [], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_STATE, []):
 | 
			
		||||
        rhs = binary_sensor_var.make_state_trigger()
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        automation.build_automation(trigger, bool_, conf)
 | 
			
		||||
        automation.build_automations(trigger, [(bool_, 'x')], conf)
 | 
			
		||||
 | 
			
		||||
    setup_mqtt_component(mqtt_var, config)
 | 
			
		||||
    setup_mqtt_component(binary_sensor_var.Pget_mqtt(), config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_binary_sensor(binary_sensor_obj, mqtt_obj, config):
 | 
			
		||||
    binary_sensor_var = Pvariable(config[CONF_ID], binary_sensor_obj,
 | 
			
		||||
                                  has_side_effects=False)
 | 
			
		||||
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj,
 | 
			
		||||
                         has_side_effects=False)
 | 
			
		||||
    CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
 | 
			
		||||
def setup_binary_sensor(binary_sensor_obj, config):
 | 
			
		||||
    if not CORE.has_id(config[CONF_ID]):
 | 
			
		||||
        binary_sensor_obj = Pvariable(config[CONF_ID], binary_sensor_obj, has_side_effects=True)
 | 
			
		||||
    CORE.add_job(setup_binary_sensor_core_, binary_sensor_obj, 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)
 | 
			
		||||
    CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, mqtt_var, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def core_to_hass_config(data, config):
 | 
			
		||||
    ret = mqtt.build_hass_config(data, 'binary_sensor', config,
 | 
			
		||||
                                 include_state=True, include_command=False)
 | 
			
		||||
    if ret is None:
 | 
			
		||||
        return None
 | 
			
		||||
    if CONF_DEVICE_CLASS in config:
 | 
			
		||||
        ret['device_class'] = config[CONF_DEVICE_CLASS]
 | 
			
		||||
    return ret
 | 
			
		||||
    add(App.register_binary_sensor(binary_sensor_var))
 | 
			
		||||
    CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, 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),
 | 
			
		||||
    vol.Optional(CONF_FOR): cv.positive_time_period_milliseconds,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@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):
 | 
			
		||||
def binary_sensor_is_on_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    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)
 | 
			
		||||
    rhs = var.make_binary_sensor_is_on_condition(template_arg, config.get(CONF_FOR))
 | 
			
		||||
    type = BinarySensorCondition.template(template_arg)
 | 
			
		||||
    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),
 | 
			
		||||
    vol.Optional(CONF_FOR): cv.positive_time_period_milliseconds,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@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):
 | 
			
		||||
def binary_sensor_is_off_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    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)
 | 
			
		||||
    rhs = var.make_binary_sensor_is_off_condition(template_arg, config.get(CONF_FOR))
 | 
			
		||||
    type = BinarySensorCondition.template(template_arg)
 | 
			
		||||
    yield Pvariable(condition_id, rhs, type=type)
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import binary_sensor, sensor
 | 
			
		||||
from esphomeyaml.components.apds9960 import APDS9960, CONF_APDS9960_ID
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_DIRECTION, CONF_NAME
 | 
			
		||||
from esphomeyaml.cpp_generator import get_variable
 | 
			
		||||
from esphome.components import binary_sensor, sensor
 | 
			
		||||
from esphome.components.apds9960 import APDS9960, CONF_APDS9960_ID
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_DIRECTION, CONF_NAME
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['apds9960']
 | 
			
		||||
APDS9960GestureDirectionBinarySensor = sensor.sensor_ns.class_(
 | 
			
		||||
@@ -30,7 +30,3 @@ def to_code(config):
 | 
			
		||||
    func = getattr(hub, DIRECTIONS[config[CONF_DIRECTION]])
 | 
			
		||||
    rhs = func(config[CONF_NAME])
 | 
			
		||||
    binary_sensor.register_binary_sensor(rhs, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
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
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_BINARY_SENSORS, CONF_ID, CONF_LAMBDA, CONF_NAME
 | 
			
		||||
from esphome.cpp_generator import add, process_lambda, variable
 | 
			
		||||
from esphome.cpp_types import std_vector
 | 
			
		||||
 | 
			
		||||
CustomBinarySensorConstructor = binary_sensor.binary_sensor_ns.class_(
 | 
			
		||||
    'CustomBinarySensorConstructor')
 | 
			
		||||
@@ -26,12 +26,10 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
    for i, conf in enumerate(config[CONF_BINARY_SENSORS]):
 | 
			
		||||
        rhs = custom.Pget_binary_sensor(i)
 | 
			
		||||
        add(rhs.set_name(conf[CONF_NAME]))
 | 
			
		||||
        binary_sensor.register_binary_sensor(rhs, conf)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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]]
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import binary_sensor
 | 
			
		||||
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
from esphome.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.cpp_generator import get_variable
 | 
			
		||||
from esphomeyaml.cpp_types import esphomelib_ns
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_MAC_ADDRESS, CONF_NAME
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
from esphome.cpp_types import esphome_ns
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['esp32_ble_tracker']
 | 
			
		||||
ESP32BLEPresenceDevice = esphomelib_ns.class_('ESP32BLEPresenceDevice', binary_sensor.BinarySensor)
 | 
			
		||||
ESP32BLEPresenceDevice = esphome_ns.class_('ESP32BLEPresenceDevice', binary_sensor.BinarySensor)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(ESP32BLEPresenceDevice),
 | 
			
		||||
@@ -19,12 +19,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    hub = None
 | 
			
		||||
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = hub.make_presence_sensor(config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS]))
 | 
			
		||||
    binary_sensor.register_binary_sensor(rhs, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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.cpp_generator import get_variable
 | 
			
		||||
from esphomeyaml.cpp_types import global_ns
 | 
			
		||||
from esphomeyaml.pins import validate_gpio_pin
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
from esphome.components.esp32_touch import ESP32TouchComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_NAME, CONF_PIN, CONF_THRESHOLD, ESP_PLATFORM_ESP32
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
from esphome.cpp_types import global_ns
 | 
			
		||||
from esphome.pins import validate_gpio_pin
 | 
			
		||||
 | 
			
		||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
 | 
			
		||||
 | 
			
		||||
@@ -56,7 +56,3 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_ESP32_TOUCH_BINARY_SENSOR'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
							
								
								
									
										31
									
								
								esphome/components/binary_sensor/gpio.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								esphome/components/binary_sensor/gpio.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_NAME, CONF_PIN
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import gpio_input_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component
 | 
			
		||||
 | 
			
		||||
GPIOBinarySensorComponent = binary_sensor.binary_sensor_ns.class_('GPIOBinarySensorComponent',
 | 
			
		||||
                                                                  binary_sensor.BinarySensor,
 | 
			
		||||
                                                                  Component)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(GPIOBinarySensorComponent),
 | 
			
		||||
    vol.Required(CONF_PIN): pins.gpio_input_pin_schema
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    pin = None
 | 
			
		||||
    for pin in gpio_input_pin_expression(config[CONF_PIN]):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin)
 | 
			
		||||
    gpio = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    binary_sensor.setup_binary_sensor(gpio, config)
 | 
			
		||||
    setup_component(gpio, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_GPIO_BINARY_SENSOR'
 | 
			
		||||
							
								
								
									
										26
									
								
								esphome/components/binary_sensor/homeassistant.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								esphome/components/binary_sensor/homeassistant.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ENTITY_ID, CONF_ID, CONF_NAME
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['api']
 | 
			
		||||
 | 
			
		||||
HomeassistantBinarySensor = binary_sensor.binary_sensor_ns.class_('HomeassistantBinarySensor',
 | 
			
		||||
                                                                  binary_sensor.BinarySensor)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(HomeassistantBinarySensor),
 | 
			
		||||
    vol.Required(CONF_ENTITY_ID): cv.entity_id,
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_homeassistant_binary_sensor(config[CONF_NAME], config[CONF_ENTITY_ID])
 | 
			
		||||
    subs = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    binary_sensor.setup_binary_sensor(subs, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_HOMEASSISTANT_BINARY_SENSOR'
 | 
			
		||||
							
								
								
									
										24
									
								
								esphome/components/binary_sensor/mpr121.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								esphome/components/binary_sensor/mpr121.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
from esphome.components.mpr121 import MPR121Component, CONF_MPR121_ID
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_CHANNEL, CONF_NAME
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['mpr121']
 | 
			
		||||
MPR121Channel = binary_sensor.binary_sensor_ns.class_(
 | 
			
		||||
    'MPR121Channel', binary_sensor.BinarySensor)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(MPR121Channel),
 | 
			
		||||
    cv.GenerateID(CONF_MPR121_ID): cv.use_variable_id(MPR121Component),
 | 
			
		||||
    vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=0, max=11))
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    for hub in get_variable(config[CONF_MPR121_ID]):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = MPR121Channel.new(config[CONF_NAME], config[CONF_CHANNEL])
 | 
			
		||||
    binary_sensor.register_binary_sensor(hub.add_channel(rhs), config)
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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.cpp_generator import get_variable
 | 
			
		||||
from esphome.components import binary_sensor, display
 | 
			
		||||
from esphome.components.display.nextion import Nextion
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_COMPONENT_ID, CONF_NAME, CONF_PAGE_ID
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['display']
 | 
			
		||||
 | 
			
		||||
@@ -27,7 +27,3 @@ def to_code(config):
 | 
			
		||||
    rhs = hub.make_touch_component(config[CONF_NAME], config[CONF_PAGE_ID],
 | 
			
		||||
                                   config[CONF_COMPONENT_ID])
 | 
			
		||||
    binary_sensor.register_binary_sensor(rhs, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
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.cpp_generator import get_variable, ArrayInitializer
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
from esphome.components.pn532 import PN532Component
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_NAME, CONF_UID
 | 
			
		||||
from esphome.core import HexInt
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['pn532']
 | 
			
		||||
 | 
			
		||||
@@ -41,9 +41,5 @@ def to_code(config):
 | 
			
		||||
    for hub in get_variable(config[CONF_PN532_ID]):
 | 
			
		||||
        yield
 | 
			
		||||
    addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')]
 | 
			
		||||
    rhs = hub.make_tag(config[CONF_NAME], ArrayInitializer(*addr, multiline=False))
 | 
			
		||||
    rhs = hub.make_tag(config[CONF_NAME], addr)
 | 
			
		||||
    binary_sensor.register_binary_sensor(rhs, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
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.cpp_generator import get_variable
 | 
			
		||||
from esphome.components import binary_sensor, rdm6300
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_NAME, CONF_UID
 | 
			
		||||
from esphome.cpp_generator import get_variable
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['rdm6300']
 | 
			
		||||
 | 
			
		||||
@@ -24,7 +24,3 @@ def to_code(config):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = hub.make_card(config[CONF_NAME], config[CONF_UID])
 | 
			
		||||
    binary_sensor.register_binary_sensor(rhs, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
@@ -1,62 +1,84 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.components import binary_sensor
 | 
			
		||||
from esphomeyaml.components.remote_receiver import RemoteReceiverComponent, remote_ns
 | 
			
		||||
from esphomeyaml.components.remote_transmitter import RC_SWITCH_RAW_SCHEMA, \
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
from esphome.components.remote_receiver import RemoteReceiverComponent, remote_ns
 | 
			
		||||
from esphome.components.remote_transmitter import RC_SWITCH_RAW_SCHEMA, \
 | 
			
		||||
    RC_SWITCH_TYPE_A_SCHEMA, RC_SWITCH_TYPE_B_SCHEMA, RC_SWITCH_TYPE_C_SCHEMA, \
 | 
			
		||||
    RC_SWITCH_TYPE_D_SCHEMA, binary_code, build_rc_switch_protocol
 | 
			
		||||
from esphomeyaml.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAND, CONF_DATA, \
 | 
			
		||||
    CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, \
 | 
			
		||||
    CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, \
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAND, CONF_DATA, \
 | 
			
		||||
    CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_ID, CONF_JVC, CONF_LG, CONF_NAME, CONF_NBITS, \
 | 
			
		||||
    CONF_NEC, 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.cpp_generator import ArrayInitializer, get_variable, Pvariable
 | 
			
		||||
    CONF_STATE, CONF_RC5
 | 
			
		||||
from esphome.cpp_generator import Pvariable, get_variable, progmem_array
 | 
			
		||||
from esphome.cpp_types import int32
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['remote_receiver']
 | 
			
		||||
 | 
			
		||||
REMOTE_KEYS = [CONF_NEC, CONF_LG, CONF_SONY, CONF_PANASONIC, CONF_SAMSUNG, CONF_RAW,
 | 
			
		||||
REMOTE_KEYS = [CONF_JVC, CONF_NEC, CONF_LG, CONF_SONY, CONF_PANASONIC, CONF_SAMSUNG, 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_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_RC5]
 | 
			
		||||
 | 
			
		||||
CONF_REMOTE_RECEIVER_ID = 'remote_receiver_id'
 | 
			
		||||
CONF_RECEIVER_ID = 'receiver_id'
 | 
			
		||||
 | 
			
		||||
RemoteReceiver = remote_ns.class_('RemoteReceiver', binary_sensor.BinarySensor)
 | 
			
		||||
JVCReceiver = remote_ns.class_('JVCReceiver', RemoteReceiver)
 | 
			
		||||
LGReceiver = remote_ns.class_('LGReceiver', RemoteReceiver)
 | 
			
		||||
NECReceiver = remote_ns.class_('NECReceiver', RemoteReceiver)
 | 
			
		||||
PanasonicReceiver = remote_ns.class_('PanasonicReceiver', RemoteReceiver)
 | 
			
		||||
RawReceiver = remote_ns.class_('RawReceiver', RemoteReceiver)
 | 
			
		||||
SamsungReceiver = remote_ns.class_('SamsungReceiver', RemoteReceiver)
 | 
			
		||||
SonyReceiver = remote_ns.class_('SonyReceiver', RemoteReceiver)
 | 
			
		||||
RC5Receiver = remote_ns.class_('RC5Receiver', RemoteReceiver)
 | 
			
		||||
RCSwitchRawReceiver = remote_ns.class_('RCSwitchRawReceiver', RemoteReceiver)
 | 
			
		||||
RCSwitchTypeAReceiver = remote_ns.class_('RCSwitchTypeAReceiver', RCSwitchRawReceiver)
 | 
			
		||||
RCSwitchTypeBReceiver = remote_ns.class_('RCSwitchTypeBReceiver', RCSwitchRawReceiver)
 | 
			
		||||
RCSwitchTypeCReceiver = remote_ns.class_('RCSwitchTypeCReceiver', RCSwitchRawReceiver)
 | 
			
		||||
RCSwitchTypeDReceiver = remote_ns.class_('RCSwitchTypeDReceiver', RCSwitchRawReceiver)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_raw(value):
 | 
			
		||||
    if isinstance(value, dict):
 | 
			
		||||
        return cv.Schema({
 | 
			
		||||
            cv.GenerateID(): cv.declare_variable_id(int32),
 | 
			
		||||
            vol.Required(CONF_DATA): [vol.Any(vol.Coerce(int), cv.time_period_microseconds)],
 | 
			
		||||
        })(value)
 | 
			
		||||
    return validate_raw({
 | 
			
		||||
        CONF_DATA: value
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(RemoteReceiver),
 | 
			
		||||
    vol.Optional(CONF_LG): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_JVC): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_DATA): cv.hex_uint32_t,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_LG): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_DATA): cv.hex_uint32_t,
 | 
			
		||||
        vol.Optional(CONF_NBITS, default=28): cv.one_of(28, 32, int=True),
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_NEC): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_NEC): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
 | 
			
		||||
        vol.Required(CONF_COMMAND): cv.hex_uint16_t,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_SAMSUNG): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_SAMSUNG): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_DATA): cv.hex_uint32_t,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_SONY): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_SONY): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_DATA): cv.hex_uint32_t,
 | 
			
		||||
        vol.Optional(CONF_NBITS, default=12): cv.one_of(12, 15, 20, int=True),
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_PANASONIC): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_PANASONIC): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
 | 
			
		||||
        vol.Required(CONF_COMMAND): cv.hex_uint32_t,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_RAW): [vol.Any(vol.Coerce(int), cv.time_period_microseconds)],
 | 
			
		||||
    vol.Optional(CONF_RC5): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_ADDRESS): vol.All(cv.hex_int, vol.Range(min=0, max=0x1F)),
 | 
			
		||||
        vol.Required(CONF_COMMAND): vol.All(cv.hex_int, vol.Range(min=0, max=0x3F)),
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_RAW): validate_raw,
 | 
			
		||||
    vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA,
 | 
			
		||||
    vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA,
 | 
			
		||||
    vol.Optional(CONF_RC_SWITCH_TYPE_B): RC_SWITCH_TYPE_B_SCHEMA,
 | 
			
		||||
@@ -71,6 +93,8 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
 | 
			
		||||
def receiver_base(full_config):
 | 
			
		||||
    name = full_config[CONF_NAME]
 | 
			
		||||
    key, config = next((k, v) for k, v in full_config.items() if k in REMOTE_KEYS)
 | 
			
		||||
    if key == CONF_JVC:
 | 
			
		||||
        return JVCReceiver.new(name, config[CONF_DATA])
 | 
			
		||||
    if key == CONF_LG:
 | 
			
		||||
        return LGReceiver.new(name, config[CONF_DATA], config[CONF_NBITS])
 | 
			
		||||
    if key == CONF_NEC:
 | 
			
		||||
@@ -81,9 +105,11 @@ def receiver_base(full_config):
 | 
			
		||||
        return SamsungReceiver.new(name, config[CONF_DATA])
 | 
			
		||||
    if key == CONF_SONY:
 | 
			
		||||
        return SonyReceiver.new(name, config[CONF_DATA], config[CONF_NBITS])
 | 
			
		||||
    if key == CONF_RC5:
 | 
			
		||||
        return RC5Receiver.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
 | 
			
		||||
    if key == CONF_RAW:
 | 
			
		||||
        data = ArrayInitializer(*config, multiline=False)
 | 
			
		||||
        return RawReceiver.new(name, data)
 | 
			
		||||
        arr = progmem_array(config[CONF_ID], config[CONF_DATA])
 | 
			
		||||
        return RawReceiver.new(name, arr, len(config[CONF_DATA]))
 | 
			
		||||
    if key == CONF_RC_SWITCH_RAW:
 | 
			
		||||
        return RCSwitchRawReceiver.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]),
 | 
			
		||||
                                       binary_code(config[CONF_CODE]), len(config[CONF_CODE]))
 | 
			
		||||
@@ -119,7 +145,3 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return binary_sensor.core_to_hass_config(data, config)
 | 
			
		||||
							
								
								
									
										24
									
								
								esphome/components/binary_sensor/status.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								esphome/components/binary_sensor/status.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_NAME
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component
 | 
			
		||||
 | 
			
		||||
StatusBinarySensor = binary_sensor.binary_sensor_ns.class_('StatusBinarySensor',
 | 
			
		||||
                                                           binary_sensor.BinarySensor,
 | 
			
		||||
                                                           Component)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(StatusBinarySensor),
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_status_binary_sensor(config[CONF_NAME])
 | 
			
		||||
    status = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    binary_sensor.setup_binary_sensor(status, config)
 | 
			
		||||
    setup_component(status, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_STATUS_BINARY_SENSOR'
 | 
			
		||||
							
								
								
									
										56
									
								
								esphome/components/binary_sensor/template.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								esphome/components/binary_sensor/template.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_STATE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import Action, App, Component, bool_, optional
 | 
			
		||||
 | 
			
		||||
TemplateBinarySensor = binary_sensor.binary_sensor_ns.class_('TemplateBinarySensor',
 | 
			
		||||
                                                             binary_sensor.BinarySensor,
 | 
			
		||||
                                                             Component)
 | 
			
		||||
BinarySensorPublishAction = binary_sensor.binary_sensor_ns.class_('BinarySensorPublishAction',
 | 
			
		||||
                                                                  Action)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(TemplateBinarySensor),
 | 
			
		||||
    vol.Optional(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_template_binary_sensor(config[CONF_NAME])
 | 
			
		||||
    var = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    binary_sensor.setup_binary_sensor(var, config)
 | 
			
		||||
    setup_component(var, config)
 | 
			
		||||
 | 
			
		||||
    if CONF_LAMBDA in config:
 | 
			
		||||
        for template_ in process_lambda(config[CONF_LAMBDA], [],
 | 
			
		||||
                                        return_type=optional.template(bool_)):
 | 
			
		||||
            yield
 | 
			
		||||
        add(var.set_template(template_))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_TEMPLATE_BINARY_SENSOR'
 | 
			
		||||
 | 
			
		||||
CONF_BINARY_SENSOR_TEMPLATE_PUBLISH = 'binary_sensor.template.publish'
 | 
			
		||||
BINARY_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_ID): cv.use_variable_id(binary_sensor.BinarySensor),
 | 
			
		||||
    vol.Required(CONF_STATE): cv.templatable(cv.boolean),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_BINARY_SENSOR_TEMPLATE_PUBLISH,
 | 
			
		||||
                          BINARY_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA)
 | 
			
		||||
def binary_sensor_template_publish_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_binary_sensor_publish_action(template_arg)
 | 
			
		||||
    type = BinarySensorPublishAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    for template_ in templatable(config[CONF_STATE], args, bool_):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.set_state(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
@@ -1,18 +1,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_ID, CONF_INTERNAL, CONF_MQTT_ID
 | 
			
		||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable
 | 
			
		||||
from esphomeyaml.cpp_types import Action, Nameable, esphomelib_ns
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
 | 
			
		||||
from esphome.components import mqtt
 | 
			
		||||
from esphome.components.mqtt import setup_mqtt_component
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable
 | 
			
		||||
from esphome.cpp_types import Action, Nameable, esphome_ns
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
cover_ns = esphomelib_ns.namespace('cover')
 | 
			
		||||
cover_ns = esphome_ns.namespace('cover')
 | 
			
		||||
 | 
			
		||||
Cover = cover_ns.class_('Cover', Nameable)
 | 
			
		||||
MQTTCoverComponent = cover_ns.class_('MQTTCoverComponent', mqtt.MQTTComponent)
 | 
			
		||||
@@ -21,6 +22,12 @@ CoverState = cover_ns.class_('CoverState')
 | 
			
		||||
COVER_OPEN = cover_ns.COVER_OPEN
 | 
			
		||||
COVER_CLOSED = cover_ns.COVER_CLOSED
 | 
			
		||||
 | 
			
		||||
validate_cover_state = cv.one_of('OPEN', 'CLOSED', upper=True)
 | 
			
		||||
COVER_STATES = {
 | 
			
		||||
    'OPEN': COVER_OPEN,
 | 
			
		||||
    'CLOSED': COVER_CLOSED,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Actions
 | 
			
		||||
OpenAction = cover_ns.class_('OpenAction', Action)
 | 
			
		||||
CloseAction = cover_ns.class_('CloseAction', Action)
 | 
			
		||||
@@ -34,16 +41,14 @@ COVER_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
 | 
			
		||||
COVER_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(COVER_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_cover_core_(cover_var, mqtt_var, config):
 | 
			
		||||
def setup_cover_core_(cover_var, config):
 | 
			
		||||
    if CONF_INTERNAL in config:
 | 
			
		||||
        add(cover_var.set_internal(config[CONF_INTERNAL]))
 | 
			
		||||
    setup_mqtt_component(mqtt_var, config)
 | 
			
		||||
    setup_mqtt_component(cover_var.Pget_mqtt(), config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_cover(cover_obj, mqtt_obj, config):
 | 
			
		||||
    cover_var = Pvariable(config[CONF_ID], cover_obj, has_side_effects=False)
 | 
			
		||||
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
 | 
			
		||||
    setup_cover_core_(cover_var, mqtt_var, config)
 | 
			
		||||
def setup_cover(cover_obj, config):
 | 
			
		||||
    CORE.add_job(setup_cover_core_, cover_obj, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_COVER'
 | 
			
		||||
@@ -55,11 +60,11 @@ 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):
 | 
			
		||||
def cover_open_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_open_action(template_arg)
 | 
			
		||||
    type = OpenAction.template(arg_type)
 | 
			
		||||
    type = OpenAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -70,11 +75,11 @@ 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):
 | 
			
		||||
def cover_close_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_close_action(template_arg)
 | 
			
		||||
    type = CloseAction.template(arg_type)
 | 
			
		||||
    type = CloseAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -85,16 +90,9 @@ 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):
 | 
			
		||||
def cover_stop_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_stop_action(template_arg)
 | 
			
		||||
    type = StopAction.template(arg_type)
 | 
			
		||||
    type = StopAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def core_to_hass_config(data, config):
 | 
			
		||||
    ret = mqtt.build_hass_config(data, 'cover', config, include_state=True, include_command=True)
 | 
			
		||||
    if ret is None:
 | 
			
		||||
        return None
 | 
			
		||||
    return ret
 | 
			
		||||
							
								
								
									
										79
									
								
								esphome/components/cover/template.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								esphome/components/cover/template.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import automation
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY
 | 
			
		||||
from esphome.components import cover
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, CONF_NAME, \
 | 
			
		||||
    CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STATE, CONF_STOP_ACTION
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import Action, App, optional
 | 
			
		||||
from esphome.py_compat import string_types
 | 
			
		||||
 | 
			
		||||
TemplateCover = cover.cover_ns.class_('TemplateCover', cover.Cover)
 | 
			
		||||
CoverPublishAction = cover.cover_ns.class_('CoverPublishAction', Action)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(cover.COVER_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(TemplateCover),
 | 
			
		||||
    vol.Optional(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
    vol.Optional(CONF_OPTIMISTIC): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_ASSUMED_STATE): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_OPEN_ACTION): automation.validate_automation(single=True),
 | 
			
		||||
    vol.Optional(CONF_CLOSE_ACTION): automation.validate_automation(single=True),
 | 
			
		||||
    vol.Optional(CONF_STOP_ACTION): automation.validate_automation(single=True),
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_template_cover(config[CONF_NAME])
 | 
			
		||||
    var = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    cover.setup_cover(var, config)
 | 
			
		||||
    setup_component(var, config)
 | 
			
		||||
 | 
			
		||||
    if CONF_LAMBDA in config:
 | 
			
		||||
        for template_ in process_lambda(config[CONF_LAMBDA], [],
 | 
			
		||||
                                        return_type=optional.template(cover.CoverState)):
 | 
			
		||||
            yield
 | 
			
		||||
        add(var.set_state_lambda(template_))
 | 
			
		||||
    if CONF_OPEN_ACTION in config:
 | 
			
		||||
        automation.build_automations(var.get_open_trigger(), [],
 | 
			
		||||
                                     config[CONF_OPEN_ACTION])
 | 
			
		||||
    if CONF_CLOSE_ACTION in config:
 | 
			
		||||
        automation.build_automations(var.get_close_trigger(), [],
 | 
			
		||||
                                     config[CONF_CLOSE_ACTION])
 | 
			
		||||
    if CONF_STOP_ACTION in config:
 | 
			
		||||
        automation.build_automations(var.get_stop_trigger(), [],
 | 
			
		||||
                                     config[CONF_STOP_ACTION])
 | 
			
		||||
    if CONF_OPTIMISTIC in config:
 | 
			
		||||
        add(var.set_optimistic(config[CONF_OPTIMISTIC]))
 | 
			
		||||
    if CONF_ASSUMED_STATE in config:
 | 
			
		||||
        add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_TEMPLATE_COVER'
 | 
			
		||||
 | 
			
		||||
CONF_COVER_TEMPLATE_PUBLISH = 'cover.template.publish'
 | 
			
		||||
COVER_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_ID): cv.use_variable_id(cover.Cover),
 | 
			
		||||
    vol.Required(CONF_STATE): cv.templatable(cover.validate_cover_state),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_COVER_TEMPLATE_PUBLISH,
 | 
			
		||||
                          COVER_TEMPLATE_PUBLISH_ACTION_SCHEMA)
 | 
			
		||||
def cover_template_publish_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_cover_publish_action(template_arg)
 | 
			
		||||
    type = CoverPublishAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    state = config[CONF_STATE]
 | 
			
		||||
    if isinstance(state, string_types):
 | 
			
		||||
        template_ = cover.COVER_STATES[state]
 | 
			
		||||
    else:
 | 
			
		||||
        for template_ in templatable(state, args, cover.CoverState):
 | 
			
		||||
            yield None
 | 
			
		||||
    add(action.set_state(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
							
								
								
									
										33
									
								
								esphome/components/custom_component.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								esphome/components/custom_component.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_COMPONENTS, CONF_ID, CONF_LAMBDA
 | 
			
		||||
from esphome.cpp_generator import Pvariable, process_lambda, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import Component, ComponentPtr, esphome_ns, std_vector
 | 
			
		||||
 | 
			
		||||
CustomComponentConstructor = esphome_ns.class_('CustomComponentConstructor')
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(CustomComponentConstructor),
 | 
			
		||||
    vol.Required(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
    vol.Optional(CONF_COMPONENTS): cv.ensure_list(cv.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_config in enumerate(config.get(CONF_COMPONENTS, [])):
 | 
			
		||||
        comp = Pvariable(comp_config[CONF_ID], custom.get_component(i))
 | 
			
		||||
        setup_component(comp, comp_config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_CUSTOM_COMPONENT'
 | 
			
		||||
@@ -1,19 +1,19 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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.cpp_generator import Pvariable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, PollingComponent
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_PIN, CONF_UPDATE_INTERVAL
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent
 | 
			
		||||
 | 
			
		||||
DallasComponent = sensor.sensor_ns.class_('DallasComponent', PollingComponent)
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(DallasComponent),
 | 
			
		||||
    vol.Required(CONF_PIN): pins.input_pullup_pin,
 | 
			
		||||
    vol.Required(CONF_PIN): pins.input_pin,
 | 
			
		||||
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								esphome/components/debug.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								esphome/components/debug.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.cpp_generator import add
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['logger']
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    add(App.make_debug_component())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_DEBUG_COMPONENT'
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
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_MODE, CONF_NUMBER, CONF_PINS, CONF_RUN_CYCLES, \
 | 
			
		||||
from esphome import config_validation as cv, pins
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
 | 
			
		||||
from esphome.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
 | 
			
		||||
from esphome.cpp_generator import Pvariable, StructInitializer, add, get_variable
 | 
			
		||||
from esphome.cpp_helpers import gpio_input_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import Action, App, Component, esphome_ns, global_ns
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_pin_number(value):
 | 
			
		||||
@@ -17,11 +17,11 @@ def validate_pin_number(value):
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
DeepSleepComponent = esphomelib_ns.class_('DeepSleepComponent', Component)
 | 
			
		||||
EnterDeepSleepAction = esphomelib_ns.class_('EnterDeepSleepAction', Action)
 | 
			
		||||
PreventDeepSleepAction = esphomelib_ns.class_('PreventDeepSleepAction', Action)
 | 
			
		||||
DeepSleepComponent = esphome_ns.class_('DeepSleepComponent', Component)
 | 
			
		||||
EnterDeepSleepAction = esphome_ns.class_('EnterDeepSleepAction', Action)
 | 
			
		||||
PreventDeepSleepAction = esphome_ns.class_('PreventDeepSleepAction', Action)
 | 
			
		||||
 | 
			
		||||
WakeupPinMode = esphomelib_ns.enum('WakeupPinMode')
 | 
			
		||||
WakeupPinMode = esphome_ns.enum('WakeupPinMode')
 | 
			
		||||
WAKEUP_PIN_MODES = {
 | 
			
		||||
    'IGNORE': WakeupPinMode.WAKEUP_PIN_MODE_IGNORE,
 | 
			
		||||
    'KEEP_AWAKE': WakeupPinMode.WAKEUP_PIN_MODE_KEEP_AWAKE,
 | 
			
		||||
@@ -29,7 +29,7 @@ WAKEUP_PIN_MODES = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
esp_sleep_ext1_wakeup_mode_t = global_ns.enum('esp_sleep_ext1_wakeup_mode_t')
 | 
			
		||||
Ext1Wakeup = esphomelib_ns.struct('Ext1Wakeup')
 | 
			
		||||
Ext1Wakeup = esphome_ns.struct('Ext1Wakeup')
 | 
			
		||||
EXT1_WAKEUP_MODES = {
 | 
			
		||||
    'ALL_LOW': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ALL_LOW,
 | 
			
		||||
    'ANY_HIGH': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ANY_HIGH,
 | 
			
		||||
@@ -38,19 +38,22 @@ EXT1_WAKEUP_MODES = {
 | 
			
		||||
CONF_WAKEUP_PIN_MODE = 'wakeup_pin_mode'
 | 
			
		||||
CONF_ESP32_EXT1_WAKEUP = 'esp32_ext1_wakeup'
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(DeepSleepComponent),
 | 
			
		||||
    vol.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_WAKEUP_PIN): vol.All(cv.only_on_esp32, pins.internal_gpio_input_pin_schema,
 | 
			
		||||
                                           validate_pin_number),
 | 
			
		||||
    vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32,
 | 
			
		||||
                                                cv.one_of(*WAKEUP_PIN_MODES), upper=True),
 | 
			
		||||
    vol.Optional(CONF_ESP32_EXT1_WAKEUP): vol.All(cv.only_on_esp32, vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ESP32_EXT1_WAKEUP): vol.All(cv.only_on_esp32, cv.Schema({
 | 
			
		||||
        vol.Required(CONF_PINS): cv.ensure_list(pins.shorthand_input_pin, validate_pin_number),
 | 
			
		||||
        vol.Required(CONF_MODE): cv.one_of(*EXT1_WAKEUP_MODES, upper=True),
 | 
			
		||||
    })),
 | 
			
		||||
    vol.Optional(CONF_RUN_CYCLES): cv.positive_int,
 | 
			
		||||
    vol.Optional(CONF_RUN_DURATION): cv.positive_time_period_milliseconds,
 | 
			
		||||
 | 
			
		||||
    vol.Optional(CONF_RUN_CYCLES): cv.invalid("The run_cycles option has been removed in 1.11.0 as "
 | 
			
		||||
                                              "it was essentially the same as a run_duration of 0s."
 | 
			
		||||
                                              "Please use run_duration now.")
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -65,8 +68,6 @@ def to_code(config):
 | 
			
		||||
        add(deep_sleep.set_wakeup_pin(pin))
 | 
			
		||||
    if CONF_WAKEUP_PIN_MODE in config:
 | 
			
		||||
        add(deep_sleep.set_wakeup_pin_mode(WAKEUP_PIN_MODES[config[CONF_WAKEUP_PIN_MODE]]))
 | 
			
		||||
    if CONF_RUN_CYCLES in config:
 | 
			
		||||
        add(deep_sleep.set_run_cycles(config[CONF_RUN_CYCLES]))
 | 
			
		||||
    if CONF_RUN_DURATION in config:
 | 
			
		||||
        add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION]))
 | 
			
		||||
 | 
			
		||||
@@ -94,11 +95,11 @@ 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):
 | 
			
		||||
def deep_sleep_enter_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_enter_deep_sleep_action(template_arg)
 | 
			
		||||
    type = EnterDeepSleepAction.template(arg_type)
 | 
			
		||||
    type = EnterDeepSleepAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -109,9 +110,9 @@ 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):
 | 
			
		||||
def deep_sleep_prevent_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_prevent_deep_sleep_action(template_arg)
 | 
			
		||||
    type = PreventDeepSleepAction.template(arg_type)
 | 
			
		||||
    type = PreventDeepSleepAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
							
								
								
									
										127
									
								
								esphome/components/display/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								esphome/components/display/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,127 @@
 | 
			
		||||
# coding=utf-8
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import core
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_LAMBDA, CONF_ROTATION, CONF_UPDATE_INTERVAL, CONF_PAGES, CONF_ID
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import add, process_lambda, Pvariable, templatable, get_variable
 | 
			
		||||
from esphome.cpp_types import esphome_ns, void, Action
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
display_ns = esphome_ns.namespace('display')
 | 
			
		||||
DisplayBuffer = display_ns.class_('DisplayBuffer')
 | 
			
		||||
DisplayPage = display_ns.class_('DisplayPage')
 | 
			
		||||
DisplayPagePtr = DisplayPage.operator('ptr')
 | 
			
		||||
DisplayBufferRef = DisplayBuffer.operator('ref')
 | 
			
		||||
DisplayPageShowAction = display_ns.class_('DisplayPageShowAction', Action)
 | 
			
		||||
DisplayPageShowNextAction = display_ns.class_('DisplayPageShowNextAction', Action)
 | 
			
		||||
DisplayPageShowPrevAction = display_ns.class_('DisplayPageShowPrevAction', Action)
 | 
			
		||||
 | 
			
		||||
DISPLAY_ROTATIONS = {
 | 
			
		||||
    0: display_ns.DISPLAY_ROTATION_0_DEGREES,
 | 
			
		||||
    90: display_ns.DISPLAY_ROTATION_90_DEGREES,
 | 
			
		||||
    180: display_ns.DISPLAY_ROTATION_180_DEGREES,
 | 
			
		||||
    270: display_ns.DISPLAY_ROTATION_270_DEGREES,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_rotation(value):
 | 
			
		||||
    value = cv.string(value)
 | 
			
		||||
    if value.endswith(u"°"):
 | 
			
		||||
        value = value[:-1]
 | 
			
		||||
    try:
 | 
			
		||||
        value = int(value)
 | 
			
		||||
    except ValueError:
 | 
			
		||||
        raise vol.Invalid(u"Expected integer for rotation")
 | 
			
		||||
    return cv.one_of(*DISPLAY_ROTATIONS)(value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BASIC_DISPLAY_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
 | 
			
		||||
    vol.Optional(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
FULL_DISPLAY_PLATFORM_SCHEMA = BASIC_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_ROTATION): validate_rotation,
 | 
			
		||||
    vol.Optional(CONF_PAGES): vol.All(cv.ensure_list({
 | 
			
		||||
        cv.GenerateID(): cv.declare_variable_id(DisplayPage),
 | 
			
		||||
        vol.Required(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
    }), vol.Length(min=1)),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_display_core_(display_var, config):
 | 
			
		||||
    if CONF_UPDATE_INTERVAL in config:
 | 
			
		||||
        add(display_var.set_update_interval(config[CONF_UPDATE_INTERVAL]))
 | 
			
		||||
    if CONF_ROTATION in config:
 | 
			
		||||
        add(display_var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]]))
 | 
			
		||||
    if CONF_PAGES in config:
 | 
			
		||||
        pages = []
 | 
			
		||||
        for conf in config[CONF_PAGES]:
 | 
			
		||||
            for lambda_ in process_lambda(conf[CONF_LAMBDA], [(DisplayBufferRef, 'it')],
 | 
			
		||||
                                          return_type=void):
 | 
			
		||||
                yield
 | 
			
		||||
            var = Pvariable(conf[CONF_ID], DisplayPage.new(lambda_))
 | 
			
		||||
            pages.append(var)
 | 
			
		||||
        add(display_var.set_pages(pages))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_DISPLAY_PAGE_SHOW = 'display.page.show'
 | 
			
		||||
DISPLAY_PAGE_SHOW_ACTION_SCHEMA = maybe_simple_id({
 | 
			
		||||
    vol.Required(CONF_ID): cv.templatable(cv.use_variable_id(DisplayPage)),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_DISPLAY_PAGE_SHOW, DISPLAY_PAGE_SHOW_ACTION_SCHEMA)
 | 
			
		||||
def display_page_show_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    type = DisplayPageShowAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, type.new(), type=type)
 | 
			
		||||
    if isinstance(config[CONF_ID], core.Lambda):
 | 
			
		||||
        for template_ in templatable(config[CONF_ID], args, DisplayPagePtr):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_page(template_))
 | 
			
		||||
    else:
 | 
			
		||||
        for var in get_variable(config[CONF_ID]):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_page(var))
 | 
			
		||||
    yield action
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_DISPLAY_PAGE_SHOW_NEXT = 'display.page.show_next'
 | 
			
		||||
DISPLAY_PAGE_SHOW_NEXT_ACTION_SCHEMA = maybe_simple_id({
 | 
			
		||||
    vol.Required(CONF_ID): cv.templatable(cv.use_variable_id(DisplayBuffer)),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_DISPLAY_PAGE_SHOW_NEXT, DISPLAY_PAGE_SHOW_NEXT_ACTION_SCHEMA)
 | 
			
		||||
def display_page_show_next_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    type = DisplayPageShowNextAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, type.new(var), type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_DISPLAY_PAGE_SHOW_PREVIOUS = 'display.page.show_previous'
 | 
			
		||||
DISPLAY_PAGE_SHOW_PREVIOUS_ACTION_SCHEMA = maybe_simple_id({
 | 
			
		||||
    vol.Required(CONF_ID): cv.templatable(cv.use_variable_id(DisplayBuffer)),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_DISPLAY_PAGE_SHOW_PREVIOUS, DISPLAY_PAGE_SHOW_PREVIOUS_ACTION_SCHEMA)
 | 
			
		||||
def display_page_show_previous_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    type = DisplayPageShowPrevAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, type.new(var), type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_display(display_var, config):
 | 
			
		||||
    CORE.add_job(setup_display_core_, display_var, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_DISPLAY'
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import display
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_DATA_PINS, CONF_DIMENSIONS, CONF_ENABLE_PIN, CONF_ID, \
 | 
			
		||||
    CONF_LAMBDA, CONF_RS_PIN, CONF_RW_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, PollingComponent, void
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent, void
 | 
			
		||||
 | 
			
		||||
LCDDisplay = display.display_ns.class_('LCDDisplay', PollingComponent)
 | 
			
		||||
LCDDisplayRef = LCDDisplay.operator('ref')
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import display, i2c
 | 
			
		||||
from esphomeyaml.components.display.lcd_gpio import LCDDisplay, LCDDisplayRef, \
 | 
			
		||||
from esphome.components import display, i2c
 | 
			
		||||
from esphome.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.cpp_generator import Pvariable, add, process_lambda
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, void
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_DIMENSIONS, CONF_ID, CONF_LAMBDA
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, void
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['i2c']
 | 
			
		||||
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import display, spi
 | 
			
		||||
from esphome.components.spi import SPIComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_CS_PIN, CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_NUM_CHIPS, \
 | 
			
		||||
    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, void
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent, void
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['spi']
 | 
			
		||||
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
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.cpp_generator import Pvariable, add, get_variable, process_lambda
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, PollingComponent, void
 | 
			
		||||
from esphome.components import display, uart
 | 
			
		||||
from esphome.components.uart import UARTComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_UART_ID
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent, void
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['uart']
 | 
			
		||||
 | 
			
		||||
@@ -1,26 +1,26 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
from esphomeyaml.components import display
 | 
			
		||||
from esphomeyaml.components.display import ssd1306_spi
 | 
			
		||||
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, void
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import display
 | 
			
		||||
from esphome.components.display import ssd1306_spi
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_EXTERNAL_VCC, CONF_ID, CONF_LAMBDA, CONF_MODEL, \
 | 
			
		||||
    CONF_PAGES, CONF_RESET_PIN
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import App, void
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['i2c']
 | 
			
		||||
 | 
			
		||||
I2CSSD1306 = display.display_ns.class_('I2CSSD1306', ssd1306_spi.SSD1306)
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(I2CSSD1306),
 | 
			
		||||
    vol.Required(CONF_MODEL): ssd1306_spi.SSD1306_MODEL,
 | 
			
		||||
    vol.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
 | 
			
		||||
    vol.Optional(CONF_EXTERNAL_VCC): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_ADDRESS): cv.i2c_address,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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_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, void
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import display, spi
 | 
			
		||||
from esphome.components.spi import SPIComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_CS_PIN, CONF_DC_PIN, CONF_EXTERNAL_VCC, CONF_ID, CONF_LAMBDA, \
 | 
			
		||||
    CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID, CONF_PAGES
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent, void
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['spi']
 | 
			
		||||
 | 
			
		||||
@@ -29,7 +29,7 @@ MODELS = {
 | 
			
		||||
 | 
			
		||||
SSD1306_MODEL = cv.one_of(*MODELS, upper=True, space="_")
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(SPISSD1306),
 | 
			
		||||
    cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
 | 
			
		||||
    vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
 | 
			
		||||
@@ -37,7 +37,7 @@ PLATFORM_SCHEMA = display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Required(CONF_MODEL): SSD1306_MODEL,
 | 
			
		||||
    vol.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
 | 
			
		||||
    vol.Optional(CONF_EXTERNAL_VCC): cv.boolean,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
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_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.cpp_generator import get_variable, Pvariable, process_lambda, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, gpio_input_pin_expression, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import display, spi
 | 
			
		||||
from esphome.components.spi import SPIComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_FULL_UPDATE_EVERY, \
 | 
			
		||||
    CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_PAGES, CONF_RESET_PIN, CONF_SPI_ID
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda
 | 
			
		||||
from esphome.cpp_helpers import gpio_input_pin_expression, gpio_output_pin_expression, \
 | 
			
		||||
    setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import PollingComponent, App, void
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent, void
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['spi']
 | 
			
		||||
 | 
			
		||||
@@ -17,7 +17,6 @@ WaveshareEPaperTypeA = display.display_ns.WaveshareEPaperTypeA
 | 
			
		||||
WaveshareEPaper = display.display_ns.class_('WaveshareEPaper',
 | 
			
		||||
                                            PollingComponent, spi.SPIDevice, display.DisplayBuffer)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WaveshareEPaperTypeAModel = display.display_ns.enum('WaveshareEPaperTypeAModel')
 | 
			
		||||
WaveshareEPaperTypeBModel = display.display_ns.enum('WaveshareEPaperTypeBModel')
 | 
			
		||||
 | 
			
		||||
@@ -49,7 +48,8 @@ PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
 | 
			
		||||
    vol.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
 | 
			
		||||
    vol.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema), validate_full_update_every_only_type_a)
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema), validate_full_update_every_only_type_a,
 | 
			
		||||
                          cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
@@ -1,19 +1,19 @@
 | 
			
		||||
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.cpp_generator import ArrayInitializer, Pvariable, RawExpression, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
 | 
			
		||||
from esphome import config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_SCAN_INTERVAL, CONF_TYPE, CONF_UUID, ESP_PLATFORM_ESP32
 | 
			
		||||
from esphome.cpp_generator import Pvariable, RawExpression, add
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns
 | 
			
		||||
 | 
			
		||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
 | 
			
		||||
 | 
			
		||||
ESP32BLEBeacon = esphomelib_ns.class_('ESP32BLEBeacon', Component)
 | 
			
		||||
ESP32BLEBeacon = esphome_ns.class_('ESP32BLEBeacon', Component)
 | 
			
		||||
 | 
			
		||||
CONF_MAJOR = 'major'
 | 
			
		||||
CONF_MINOR = 'minor'
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(ESP32BLEBeacon),
 | 
			
		||||
    vol.Required(CONF_TYPE): cv.one_of('IBEACON', upper=True),
 | 
			
		||||
    vol.Required(CONF_UUID): cv.uuid,
 | 
			
		||||
@@ -26,7 +26,7 @@ CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    uuid = config[CONF_UUID].hex
 | 
			
		||||
    uuid_arr = [RawExpression('0x{}'.format(uuid[i:i + 2])) for i in range(0, len(uuid), 2)]
 | 
			
		||||
    rhs = App.make_esp32_ble_beacon(ArrayInitializer(*uuid_arr, multiline=False))
 | 
			
		||||
    rhs = App.make_esp32_ble_beacon(uuid_arr)
 | 
			
		||||
    ble = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    if CONF_MAJOR in config:
 | 
			
		||||
        add(ble.set_major(config[CONF_MAJOR]))
 | 
			
		||||
							
								
								
									
										40
									
								
								esphome/components/esp32_ble_tracker.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								esphome/components/esp32_ble_tracker.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import config_validation as cv
 | 
			
		||||
from esphome.components import sensor
 | 
			
		||||
from esphome.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32
 | 
			
		||||
from esphome.core import HexInt
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns
 | 
			
		||||
 | 
			
		||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
 | 
			
		||||
 | 
			
		||||
CONF_ESP32_BLE_ID = 'esp32_ble_id'
 | 
			
		||||
ESP32BLETracker = esphome_ns.class_('ESP32BLETracker', Component)
 | 
			
		||||
XiaomiSensor = esphome_ns.class_('XiaomiSensor', sensor.Sensor)
 | 
			
		||||
XiaomiDevice = esphome_ns.class_('XiaomiDevice')
 | 
			
		||||
XIAOMI_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(XiaomiSensor)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(ESP32BLETracker),
 | 
			
		||||
    vol.Optional(CONF_SCAN_INTERVAL): cv.positive_time_period_seconds,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def make_address_array(address):
 | 
			
		||||
    return [HexInt(i) for i in address.parts]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_esp32_ble_tracker()
 | 
			
		||||
    ble = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    if CONF_SCAN_INTERVAL in config:
 | 
			
		||||
        add(ble.set_scan_interval(config[CONF_SCAN_INTERVAL]))
 | 
			
		||||
 | 
			
		||||
    setup_component(ble, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_ESP32_BLE_TRACKER'
 | 
			
		||||
							
								
								
									
										130
									
								
								esphome/components/esp32_camera.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								esphome/components/esp32_camera.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,130 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import config_validation as cv, pins
 | 
			
		||||
from esphome.const import CONF_FREQUENCY, CONF_ID, CONF_NAME, CONF_PIN, CONF_SCL, CONF_SDA, \
 | 
			
		||||
    ESP_PLATFORM_ESP32
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_types import App, Nameable, PollingComponent, esphome_ns
 | 
			
		||||
 | 
			
		||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
 | 
			
		||||
 | 
			
		||||
ESP32Camera = esphome_ns.class_('ESP32Camera', PollingComponent, Nameable)
 | 
			
		||||
ESP32CameraFrameSize = esphome_ns.enum('ESP32CameraFrameSize')
 | 
			
		||||
FRAME_SIZES = {
 | 
			
		||||
    '160X120': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_160X120,
 | 
			
		||||
    'QQVGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_160X120,
 | 
			
		||||
    '128x160': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_128X160,
 | 
			
		||||
    'QQVGA2': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_128X160,
 | 
			
		||||
    '176X144': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_176X144,
 | 
			
		||||
    'QCIF': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_176X144,
 | 
			
		||||
    '240X176': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_240X176,
 | 
			
		||||
    'HQVGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_240X176,
 | 
			
		||||
    '320X240': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_320X240,
 | 
			
		||||
    'QVGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_320X240,
 | 
			
		||||
    '400X296': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_400X296,
 | 
			
		||||
    'CIF': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_400X296,
 | 
			
		||||
    '640X480': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_640X480,
 | 
			
		||||
    'VGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_640X480,
 | 
			
		||||
    '800X600': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_800X600,
 | 
			
		||||
    'SVGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_800X600,
 | 
			
		||||
    '1024X768': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1024X768,
 | 
			
		||||
    'XGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1024X768,
 | 
			
		||||
    '1280x1024': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1280X1024,
 | 
			
		||||
    'SXGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1280X1024,
 | 
			
		||||
    '1600X1200': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1600X1200,
 | 
			
		||||
    'UXGA': ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1600X1200,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CONF_DATA_PINS = 'data_pins'
 | 
			
		||||
CONF_VSYNC_PIN = 'vsync_pin'
 | 
			
		||||
CONF_HREF_PIN = 'href_pin'
 | 
			
		||||
CONF_PIXEL_CLOCK_PIN = 'pixel_clock_pin'
 | 
			
		||||
CONF_EXTERNAL_CLOCK = 'external_clock'
 | 
			
		||||
CONF_I2C_PINS = 'i2c_pins'
 | 
			
		||||
CONF_RESET_PIN = 'reset_pin'
 | 
			
		||||
CONF_POWER_DOWN_PIN = 'power_down_pin'
 | 
			
		||||
 | 
			
		||||
CONF_MAX_FRAMERATE = 'max_framerate'
 | 
			
		||||
CONF_IDLE_FRAMERATE = 'idle_framerate'
 | 
			
		||||
CONF_RESOLUTION = 'resolution'
 | 
			
		||||
CONF_JPEG_QUALITY = 'jpeg_quality'
 | 
			
		||||
CONF_VERTICAL_FLIP = 'vertical_flip'
 | 
			
		||||
CONF_HORIZONTAL_MIRROR = 'horizontal_mirror'
 | 
			
		||||
CONF_CONTRAST = 'contrast'
 | 
			
		||||
CONF_BRIGHTNESS = 'brightness'
 | 
			
		||||
CONF_SATURATION = 'saturation'
 | 
			
		||||
CONF_TEST_PATTERN = 'test_pattern'
 | 
			
		||||
 | 
			
		||||
camera_range_param = vol.All(cv.int_, vol.Range(min=-2, max=2))
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(ESP32Camera),
 | 
			
		||||
    vol.Required(CONF_NAME): cv.string,
 | 
			
		||||
    vol.Required(CONF_DATA_PINS): vol.All([pins.input_pin], vol.Length(min=8, max=8)),
 | 
			
		||||
    vol.Required(CONF_VSYNC_PIN): pins.input_pin,
 | 
			
		||||
    vol.Required(CONF_HREF_PIN): pins.input_pin,
 | 
			
		||||
    vol.Required(CONF_PIXEL_CLOCK_PIN): pins.input_pin,
 | 
			
		||||
    vol.Required(CONF_EXTERNAL_CLOCK): vol.Schema({
 | 
			
		||||
        vol.Required(CONF_PIN): pins.output_pin,
 | 
			
		||||
        vol.Optional(CONF_FREQUENCY, default='20MHz'): vol.All(cv.frequency, vol.In([20e6, 10e6])),
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Required(CONF_I2C_PINS): vol.Schema({
 | 
			
		||||
        vol.Required(CONF_SDA): pins.output_pin,
 | 
			
		||||
        vol.Required(CONF_SCL): pins.output_pin,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_RESET_PIN): pins.output_pin,
 | 
			
		||||
    vol.Optional(CONF_POWER_DOWN_PIN): pins.output_pin,
 | 
			
		||||
 | 
			
		||||
    vol.Optional(CONF_MAX_FRAMERATE, default='10 fps'): vol.All(cv.framerate,
 | 
			
		||||
                                                                vol.Range(min=0, min_included=False,
 | 
			
		||||
                                                                          max=60)),
 | 
			
		||||
    vol.Optional(CONF_IDLE_FRAMERATE, default='0.1 fps'): vol.All(cv.framerate,
 | 
			
		||||
                                                                  vol.Range(min=0, max=1)),
 | 
			
		||||
    vol.Optional(CONF_RESOLUTION, default='640X480'): cv.one_of(*FRAME_SIZES, upper=True),
 | 
			
		||||
    vol.Optional(CONF_JPEG_QUALITY, default=10): vol.All(cv.int_, vol.Range(min=10, max=63)),
 | 
			
		||||
    vol.Optional(CONF_CONTRAST, default=0): camera_range_param,
 | 
			
		||||
    vol.Optional(CONF_BRIGHTNESS, default=0): camera_range_param,
 | 
			
		||||
    vol.Optional(CONF_SATURATION, default=0): camera_range_param,
 | 
			
		||||
    vol.Optional(CONF_VERTICAL_FLIP, default=True): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_HORIZONTAL_MIRROR, default=True): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_TEST_PATTERN, default=False): cv.boolean,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
SETTERS = {
 | 
			
		||||
    CONF_DATA_PINS: 'set_data_pins',
 | 
			
		||||
    CONF_VSYNC_PIN: 'set_vsync_pin',
 | 
			
		||||
    CONF_HREF_PIN: 'set_href_pin',
 | 
			
		||||
    CONF_PIXEL_CLOCK_PIN: 'set_pixel_clock_pin',
 | 
			
		||||
    CONF_RESET_PIN: 'set_reset_pin',
 | 
			
		||||
    CONF_POWER_DOWN_PIN: 'set_power_down_pin',
 | 
			
		||||
    CONF_JPEG_QUALITY: 'set_jpeg_quality',
 | 
			
		||||
    CONF_VERTICAL_FLIP: 'set_vertical_flip',
 | 
			
		||||
    CONF_HORIZONTAL_MIRROR: 'set_horizontal_mirror',
 | 
			
		||||
    CONF_CONTRAST: 'set_contrast',
 | 
			
		||||
    CONF_BRIGHTNESS: 'set_brightness',
 | 
			
		||||
    CONF_SATURATION: 'set_saturation',
 | 
			
		||||
    CONF_TEST_PATTERN: 'set_test_pattern',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.register_component(ESP32Camera.new(config[CONF_NAME]))
 | 
			
		||||
    cam = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    for key, setter in SETTERS.items():
 | 
			
		||||
        if key in config:
 | 
			
		||||
            add(getattr(cam, setter)(config[key]))
 | 
			
		||||
 | 
			
		||||
    extclk = config[CONF_EXTERNAL_CLOCK]
 | 
			
		||||
    add(cam.set_external_clock(extclk[CONF_PIN], extclk[CONF_FREQUENCY]))
 | 
			
		||||
    i2c_pins = config[CONF_I2C_PINS]
 | 
			
		||||
    add(cam.set_i2c_pins(i2c_pins[CONF_SDA], i2c_pins[CONF_SCL]))
 | 
			
		||||
    add(cam.set_max_update_interval(1000 / config[CONF_MAX_FRAMERATE]))
 | 
			
		||||
    if config[CONF_IDLE_FRAMERATE] == 0:
 | 
			
		||||
        add(cam.set_idle_update_interval(0))
 | 
			
		||||
    else:
 | 
			
		||||
        add(cam.set_idle_update_interval(1000 / config[CONF_IDLE_FRAMERATE]))
 | 
			
		||||
    add(cam.set_frame_size(FRAME_SIZES[config[CONF_RESOLUTION]]))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_ESP32_CAMERA'
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import config_validation as cv
 | 
			
		||||
from esphomeyaml.components import binary_sensor
 | 
			
		||||
from esphomeyaml.const import CONF_HIGH_VOLTAGE_REFERENCE, CONF_ID, CONF_IIR_FILTER, \
 | 
			
		||||
from esphome import config_validation as cv
 | 
			
		||||
from esphome.components import binary_sensor
 | 
			
		||||
from esphome.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.cpp_generator import Pvariable, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, Component, global_ns
 | 
			
		||||
from esphome.core import TimePeriod
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component, global_ns
 | 
			
		||||
 | 
			
		||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
 | 
			
		||||
 | 
			
		||||
@@ -46,7 +46,7 @@ VOLTAGE_ATTENUATION = {
 | 
			
		||||
 | 
			
		||||
ESP32TouchComponent = binary_sensor.binary_sensor_ns.class_('ESP32TouchComponent', Component)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(ESP32TouchComponent),
 | 
			
		||||
    vol.Optional(CONF_SETUP_MODE): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_IIR_FILTER): cv.positive_time_period_milliseconds,
 | 
			
		||||
@@ -1,13 +1,14 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
from esphomeyaml.components import wifi
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_DOMAIN, CONF_HOSTNAME, CONF_ID, CONF_MANUAL_IP, CONF_TYPE, \
 | 
			
		||||
    ESP_PLATFORM_ESP32
 | 
			
		||||
from esphomeyaml.cpp_generator import Pvariable, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression
 | 
			
		||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import wifi
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_DOMAIN, CONF_ID, CONF_MANUAL_IP, CONF_STATIC_IP, CONF_TYPE, \
 | 
			
		||||
    CONF_USE_ADDRESS, ESP_PLATFORM_ESP32
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_helpers import gpio_output_pin_expression
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns, global_ns
 | 
			
		||||
 | 
			
		||||
CONFLICTS_WITH = ['wifi']
 | 
			
		||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
 | 
			
		||||
@@ -18,7 +19,7 @@ CONF_MDIO_PIN = 'mdio_pin'
 | 
			
		||||
CONF_CLK_MODE = 'clk_mode'
 | 
			
		||||
CONF_POWER_PIN = 'power_pin'
 | 
			
		||||
 | 
			
		||||
EthernetType = esphomelib_ns.enum('EthernetType')
 | 
			
		||||
EthernetType = esphome_ns.enum('EthernetType')
 | 
			
		||||
ETHERNET_TYPES = {
 | 
			
		||||
    'LAN8720': EthernetType.ETHERNET_TYPE_LAN8720,
 | 
			
		||||
    'TLK110': EthernetType.ETHERNET_TYPE_TLK110,
 | 
			
		||||
@@ -32,9 +33,20 @@ CLK_MODES = {
 | 
			
		||||
    'GPIO17_OUT': eth_clock_mode_t.ETH_CLOCK_GPIO17_OUT,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
EthernetComponent = esphomelib_ns.class_('EthernetComponent', Component)
 | 
			
		||||
EthernetComponent = esphome_ns.class_('EthernetComponent', Component)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
 | 
			
		||||
def validate(config):
 | 
			
		||||
    if CONF_USE_ADDRESS not in config:
 | 
			
		||||
        if CONF_MANUAL_IP in config:
 | 
			
		||||
            use_address = str(config[CONF_MANUAL_IP][CONF_STATIC_IP])
 | 
			
		||||
        else:
 | 
			
		||||
            use_address = CORE.name + config[CONF_DOMAIN]
 | 
			
		||||
        config[CONF_USE_ADDRESS] = use_address
 | 
			
		||||
    return config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.All(cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(EthernetComponent),
 | 
			
		||||
    vol.Required(CONF_TYPE): cv.one_of(*ETHERNET_TYPES, upper=True),
 | 
			
		||||
    vol.Required(CONF_MDC_PIN): pins.output_pin,
 | 
			
		||||
@@ -43,9 +55,11 @@ CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_PHY_ADDR, default=0): vol.All(cv.int_, vol.Range(min=0, max=31)),
 | 
			
		||||
    vol.Optional(CONF_POWER_PIN): pins.gpio_output_pin_schema,
 | 
			
		||||
    vol.Optional(CONF_MANUAL_IP): wifi.STA_MANUAL_IP_SCHEMA,
 | 
			
		||||
    vol.Optional(CONF_HOSTNAME): cv.hostname,
 | 
			
		||||
    vol.Optional(CONF_DOMAIN, default='.local'): cv.domain_name,
 | 
			
		||||
})
 | 
			
		||||
    vol.Optional(CONF_USE_ADDRESS): cv.string_strict,
 | 
			
		||||
 | 
			
		||||
    vol.Optional('hostname'): cv.invalid("The hostname option has been removed in 1.11.0"),
 | 
			
		||||
}), validate)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
@@ -57,15 +71,13 @@ def to_code(config):
 | 
			
		||||
    add(eth.set_mdio_pin(config[CONF_MDIO_PIN]))
 | 
			
		||||
    add(eth.set_type(ETHERNET_TYPES[config[CONF_TYPE]]))
 | 
			
		||||
    add(eth.set_clk_mode(CLK_MODES[config[CONF_CLK_MODE]]))
 | 
			
		||||
    add(eth.set_use_address(config[CONF_USE_ADDRESS]))
 | 
			
		||||
 | 
			
		||||
    if CONF_POWER_PIN in config:
 | 
			
		||||
        for pin in gpio_output_pin_expression(config[CONF_POWER_PIN]):
 | 
			
		||||
            yield
 | 
			
		||||
        add(eth.set_power_pin(pin))
 | 
			
		||||
 | 
			
		||||
    if CONF_HOSTNAME in config:
 | 
			
		||||
        add(eth.set_hostname(config[CONF_HOSTNAME]))
 | 
			
		||||
 | 
			
		||||
    if CONF_MANUAL_IP in config:
 | 
			
		||||
        add(eth.set_manual_ip(wifi.manual_ip(config[CONF_MANUAL_IP])))
 | 
			
		||||
 | 
			
		||||
@@ -1,20 +1,22 @@
 | 
			
		||||
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_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_
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
 | 
			
		||||
from esphome.components import mqtt
 | 
			
		||||
from esphome.components.mqtt import setup_mqtt_component
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_OSCILLATING, \
 | 
			
		||||
    CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED, \
 | 
			
		||||
    CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, templatable
 | 
			
		||||
from esphome.cpp_types import Action, Application, Component, Nameable, bool_, esphome_ns
 | 
			
		||||
from esphome.py_compat import string_types
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
fan_ns = esphomelib_ns.namespace('fan')
 | 
			
		||||
fan_ns = esphome_ns.namespace('fan')
 | 
			
		||||
FanState = fan_ns.class_('FanState', Nameable, Component)
 | 
			
		||||
MQTTFanComponent = fan_ns.class_('MQTTFanComponent', mqtt.MQTTComponent)
 | 
			
		||||
MakeFan = Application.struct('MakeFan')
 | 
			
		||||
@@ -49,25 +51,25 @@ FAN_SPEEDS = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_fan_core_(fan_var, mqtt_var, config):
 | 
			
		||||
def setup_fan_core_(fan_var, config):
 | 
			
		||||
    if CONF_INTERNAL in config:
 | 
			
		||||
        add(fan_var.set_internal(config[CONF_INTERNAL]))
 | 
			
		||||
 | 
			
		||||
    mqtt_ = fan_var.Pget_mqtt()
 | 
			
		||||
    if CONF_OSCILLATION_STATE_TOPIC in config:
 | 
			
		||||
        add(mqtt_var.set_custom_oscillation_state_topic(config[CONF_OSCILLATION_STATE_TOPIC]))
 | 
			
		||||
        add(mqtt_.set_custom_oscillation_state_topic(config[CONF_OSCILLATION_STATE_TOPIC]))
 | 
			
		||||
    if CONF_OSCILLATION_COMMAND_TOPIC in config:
 | 
			
		||||
        add(mqtt_var.set_custom_oscillation_command_topic(config[CONF_OSCILLATION_COMMAND_TOPIC]))
 | 
			
		||||
        add(mqtt_.set_custom_oscillation_command_topic(config[CONF_OSCILLATION_COMMAND_TOPIC]))
 | 
			
		||||
    if CONF_SPEED_STATE_TOPIC in config:
 | 
			
		||||
        add(mqtt_var.set_custom_speed_state_topic(config[CONF_SPEED_STATE_TOPIC]))
 | 
			
		||||
        add(mqtt_.set_custom_speed_state_topic(config[CONF_SPEED_STATE_TOPIC]))
 | 
			
		||||
    if CONF_SPEED_COMMAND_TOPIC in config:
 | 
			
		||||
        add(mqtt_var.set_custom_speed_command_topic(config[CONF_SPEED_COMMAND_TOPIC]))
 | 
			
		||||
    setup_mqtt_component(mqtt_var, config)
 | 
			
		||||
        add(mqtt_.set_custom_speed_command_topic(config[CONF_SPEED_COMMAND_TOPIC]))
 | 
			
		||||
    setup_mqtt_component(mqtt_, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_fan(fan_obj, mqtt_obj, config):
 | 
			
		||||
def setup_fan(fan_obj, config):
 | 
			
		||||
    fan_var = Pvariable(config[CONF_ID], fan_obj, has_side_effects=False)
 | 
			
		||||
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
 | 
			
		||||
    setup_fan_core_(fan_var, mqtt_var, config)
 | 
			
		||||
    CORE.add_job(setup_fan_core_, fan_var, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_FAN'
 | 
			
		||||
@@ -79,11 +81,11 @@ 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):
 | 
			
		||||
def fan_toggle_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_toggle_action(template_arg)
 | 
			
		||||
    type = ToggleAction.template(arg_type)
 | 
			
		||||
    type = ToggleAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -94,11 +96,11 @@ 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):
 | 
			
		||||
def fan_turn_off_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_turn_off_action(template_arg)
 | 
			
		||||
    type = TurnOffAction.template(arg_type)
 | 
			
		||||
    type = TurnOffAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -111,30 +113,20 @@ 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):
 | 
			
		||||
def fan_turn_on_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_turn_on_action(template_arg)
 | 
			
		||||
    type = TurnOnAction.template(arg_type)
 | 
			
		||||
    type = TurnOnAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    if CONF_OSCILLATING in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_OSCILLATING], arg_type, bool_):
 | 
			
		||||
        for template_ in templatable(config[CONF_OSCILLATING], args, bool_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_oscillating(template_))
 | 
			
		||||
    if CONF_SPEED in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_SPEED], arg_type, FanSpeed):
 | 
			
		||||
        for template_ in templatable(config[CONF_SPEED], args, FanSpeed):
 | 
			
		||||
            yield None
 | 
			
		||||
        if isinstance(template_, string_types):
 | 
			
		||||
            template_ = FAN_SPEEDS[template_]
 | 
			
		||||
        add(action.set_speed(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def core_to_hass_config(data, config):
 | 
			
		||||
    ret = mqtt.build_hass_config(data, 'fan', config, include_state=True, include_command=True)
 | 
			
		||||
    if ret is None:
 | 
			
		||||
        return None
 | 
			
		||||
    if CONF_OSCILLATION_OUTPUT in config:
 | 
			
		||||
        default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'oscillation/state')
 | 
			
		||||
        ret['oscillation_state_topic'] = config.get(CONF_OSCILLATION_STATE_TOPIC, default)
 | 
			
		||||
        default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'oscillation/command')
 | 
			
		||||
        ret['oscillation_command__topic'] = config.get(CONF_OSCILLATION_COMMAND_TOPIC, default)
 | 
			
		||||
    return ret
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
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.cpp_generator import get_variable, variable, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome.components import fan, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_MAKE_ID, CONF_NAME, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT
 | 
			
		||||
from esphome.cpp_generator import add, get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(fan.MakeFan),
 | 
			
		||||
@@ -26,9 +26,5 @@ def to_code(config):
 | 
			
		||||
            yield
 | 
			
		||||
        add(fan_struct.Poutput.set_oscillation(oscillation_output))
 | 
			
		||||
 | 
			
		||||
    fan.setup_fan(fan_struct.Pstate, fan_struct.Pmqtt, config)
 | 
			
		||||
    fan.setup_fan(fan_struct.Pstate, config)
 | 
			
		||||
    setup_component(fan_struct.Poutput, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return fan.core_to_hass_config(data, config)
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.components import fan, mqtt, output
 | 
			
		||||
from esphomeyaml.const import CONF_HIGH, CONF_LOW, CONF_MAKE_ID, CONF_MEDIUM, CONF_NAME, \
 | 
			
		||||
from esphome.components import fan, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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.cpp_generator import get_variable, variable, add
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome.cpp_generator import add, get_variable, variable
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(fan.MakeFan),
 | 
			
		||||
@@ -14,7 +14,7 @@ PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_SPEED_STATE_TOPIC): cv.publish_topic,
 | 
			
		||||
    vol.Optional(CONF_SPEED_COMMAND_TOPIC): cv.subscribe_topic,
 | 
			
		||||
    vol.Optional(CONF_OSCILLATION_OUTPUT): cv.use_variable_id(output.BinaryOutput),
 | 
			
		||||
    vol.Optional(CONF_SPEED): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_SPEED): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_LOW): cv.percentage,
 | 
			
		||||
        vol.Required(CONF_MEDIUM): cv.percentage,
 | 
			
		||||
        vol.Required(CONF_HIGH): cv.percentage,
 | 
			
		||||
@@ -41,15 +41,4 @@ def to_code(config):
 | 
			
		||||
            yield
 | 
			
		||||
        add(fan_struct.Poutput.set_oscillation(oscillation_output))
 | 
			
		||||
 | 
			
		||||
    fan.setup_fan(fan_struct.Pstate, fan_struct.Pmqtt, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    ret = fan.core_to_hass_config(data, config)
 | 
			
		||||
    if ret is None:
 | 
			
		||||
        return None
 | 
			
		||||
    default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'speed/state')
 | 
			
		||||
    ret['speed_state_topic'] = config.get(CONF_SPEED_STATE_TOPIC, default)
 | 
			
		||||
    default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'speed/command')
 | 
			
		||||
    ret['speed_command__topic'] = config.get(CONF_SPEED_COMMAND_TOPIC, default)
 | 
			
		||||
    return ret
 | 
			
		||||
    fan.setup_fan(fan_struct.Pstate, config)
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
# coding=utf-8
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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 CORE, HexInt
 | 
			
		||||
from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawExpression, add
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphomeyaml.py_compat import sort_by_cmp
 | 
			
		||||
from esphome import core
 | 
			
		||||
from esphome.components import display
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_FILE, CONF_GLYPHS, CONF_ID, CONF_SIZE
 | 
			
		||||
from esphome.core import CORE, HexInt
 | 
			
		||||
from esphome.cpp_generator import Pvariable, progmem_array, safe_exp
 | 
			
		||||
from esphome.cpp_types import App, uint8
 | 
			
		||||
from esphome.py_compat import sort_by_cmp
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['display']
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
@@ -19,8 +19,8 @@ Glyph = display.display_ns.class_('Glyph')
 | 
			
		||||
 | 
			
		||||
def validate_glyphs(value):
 | 
			
		||||
    if isinstance(value, list):
 | 
			
		||||
        value = vol.Schema([cv.string])(value)
 | 
			
		||||
    value = vol.Schema([cv.string])(list(value))
 | 
			
		||||
        value = cv.Schema([cv.string])(value)
 | 
			
		||||
    value = cv.Schema([cv.string])(list(value))
 | 
			
		||||
 | 
			
		||||
    def comparator(x, y):
 | 
			
		||||
        x_ = x.encode('utf-8')
 | 
			
		||||
@@ -69,12 +69,12 @@ def validate_truetype_file(value):
 | 
			
		||||
DEFAULT_GLYPHS = u' !"%()+,-.:0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz°'
 | 
			
		||||
CONF_RAW_DATA_ID = 'raw_data_id'
 | 
			
		||||
 | 
			
		||||
FONT_SCHEMA = vol.Schema({
 | 
			
		||||
FONT_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_ID): cv.declare_variable_id(Font),
 | 
			
		||||
    vol.Required(CONF_FILE): validate_truetype_file,
 | 
			
		||||
    vol.Optional(CONF_GLYPHS, default=DEFAULT_GLYPHS): validate_glyphs,
 | 
			
		||||
    vol.Optional(CONF_SIZE, default=20): vol.All(cv.int_, vol.Range(min=1)),
 | 
			
		||||
    cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
 | 
			
		||||
    cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(uint8),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.All(validate_pillow_installed, FONT_SCHEMA)
 | 
			
		||||
@@ -87,7 +87,7 @@ def to_code(config):
 | 
			
		||||
    try:
 | 
			
		||||
        font = ImageFont.truetype(path, config[CONF_SIZE])
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        raise core.EsphomeyamlError(u"Could not load truetype file {}: {}".format(path, e))
 | 
			
		||||
        raise core.EsphomeError(u"Could not load truetype file {}: {}".format(path, e))
 | 
			
		||||
 | 
			
		||||
    ascent, descent = font.getmetrics()
 | 
			
		||||
 | 
			
		||||
@@ -108,14 +108,12 @@ def to_code(config):
 | 
			
		||||
        glyph_args[glyph] = (len(data), offset_x, offset_y, width, height)
 | 
			
		||||
        data += glyph_data
 | 
			
		||||
 | 
			
		||||
    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 = safe_exp([HexInt(x) for x in data])
 | 
			
		||||
    prog_arr = progmem_array(config[CONF_RAW_DATA_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    glyphs = []
 | 
			
		||||
    for glyph in config[CONF_GLYPHS]:
 | 
			
		||||
        glyphs.append(Glyph(glyph, raw_data, *glyph_args[glyph]))
 | 
			
		||||
        glyphs.append(Glyph(glyph, prog_arr, *glyph_args[glyph]))
 | 
			
		||||
 | 
			
		||||
    rhs = App.make_font(ArrayInitializer(*glyphs), ascent, ascent + descent)
 | 
			
		||||
    rhs = App.make_font(glyphs, ascent, ascent + descent)
 | 
			
		||||
    Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
@@ -1,16 +1,16 @@
 | 
			
		||||
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.cpp_generator import Pvariable, RawExpression, TemplateArguments, add
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
 | 
			
		||||
from esphome import config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, CONF_TYPE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, RawExpression, TemplateArguments, add
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns
 | 
			
		||||
 | 
			
		||||
GlobalVariableComponent = esphomelib_ns.class_('GlobalVariableComponent', Component)
 | 
			
		||||
GlobalVariableComponent = esphome_ns.class_('GlobalVariableComponent', Component)
 | 
			
		||||
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.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,
 | 
			
		||||
@@ -1,22 +1,22 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_FREQUENCY, CONF_ID, CONF_RECEIVE_TIMEOUT, CONF_SCAN, CONF_SCL, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns
 | 
			
		||||
 | 
			
		||||
I2CComponent = esphomelib_ns.class_('I2CComponent', Component)
 | 
			
		||||
I2CComponent = esphome_ns.class_('I2CComponent', Component)
 | 
			
		||||
I2CDevice = pins.I2CDevice
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(I2CComponent),
 | 
			
		||||
    vol.Optional(CONF_SDA, default='SDA'): pins.input_pullup_pin,
 | 
			
		||||
    vol.Optional(CONF_SCL, default='SCL'): pins.input_pullup_pin,
 | 
			
		||||
    vol.Optional(CONF_SDA, default='SDA'): pins.input_pin,
 | 
			
		||||
    vol.Optional(CONF_SCL, default='SCL'): pins.input_pin,
 | 
			
		||||
    vol.Optional(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=0, min_included=False)),
 | 
			
		||||
    vol.Optional(CONF_SCAN): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_SCAN, default=True): cv.boolean,
 | 
			
		||||
 | 
			
		||||
    vol.Optional(CONF_RECEIVE_TIMEOUT): cv.invalid("The receive_timeout option has been removed "
 | 
			
		||||
                                                   "because timeouts are already handled by the "
 | 
			
		||||
@@ -3,13 +3,13 @@ import logging
 | 
			
		||||
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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 CORE, HexInt
 | 
			
		||||
from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawExpression, add
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome import core
 | 
			
		||||
from esphome.components import display, font
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_FILE, CONF_ID, CONF_RESIZE
 | 
			
		||||
from esphome.core import CORE, HexInt
 | 
			
		||||
from esphome.cpp_generator import Pvariable, progmem_array, safe_exp
 | 
			
		||||
from esphome.cpp_types import App, uint8
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
@@ -20,11 +20,11 @@ Image_ = display.display_ns.class_('Image')
 | 
			
		||||
 | 
			
		||||
CONF_RAW_DATA_ID = 'raw_data_id'
 | 
			
		||||
 | 
			
		||||
IMAGE_SCHEMA = vol.Schema({
 | 
			
		||||
IMAGE_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_ID): cv.declare_variable_id(Image_),
 | 
			
		||||
    vol.Required(CONF_FILE): cv.file_,
 | 
			
		||||
    vol.Optional(CONF_RESIZE): cv.dimensions,
 | 
			
		||||
    cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
 | 
			
		||||
    cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(uint8),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.All(font.validate_pillow_installed, IMAGE_SCHEMA)
 | 
			
		||||
@@ -37,7 +37,7 @@ def to_code(config):
 | 
			
		||||
    try:
 | 
			
		||||
        image = Image.open(path)
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        raise core.EsphomeyamlError(u"Could not load image file {}: {}".format(path, e))
 | 
			
		||||
        raise core.EsphomeError(u"Could not load image file {}: {}".format(path, e))
 | 
			
		||||
 | 
			
		||||
    if CONF_RESIZE in config:
 | 
			
		||||
        image.thumbnail(config[CONF_RESIZE])
 | 
			
		||||
@@ -56,10 +56,8 @@ def to_code(config):
 | 
			
		||||
            pos = x + y * width8
 | 
			
		||||
            data[pos // 8] |= 0x80 >> (pos % 8)
 | 
			
		||||
 | 
			
		||||
    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 = safe_exp([HexInt(x) for x in data])
 | 
			
		||||
    prog_arr = progmem_array(config[CONF_RAW_DATA_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    rhs = App.make_image(raw_data, width, height)
 | 
			
		||||
    rhs = App.make_image(prog_arr, width, height)
 | 
			
		||||
    Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
							
								
								
									
										24
									
								
								esphome/components/interval.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								esphome/components/interval.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import automation
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_INTERVAL
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, PollingComponent, Trigger, esphome_ns
 | 
			
		||||
 | 
			
		||||
IntervalTrigger = esphome_ns.class_('IntervalTrigger', Trigger.template(), PollingComponent)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = automation.validate_automation(cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(IntervalTrigger),
 | 
			
		||||
    vol.Required(CONF_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    for conf in config:
 | 
			
		||||
        rhs = App.register_component(IntervalTrigger.new(conf[CONF_INTERVAL]))
 | 
			
		||||
        trigger = Pvariable(conf[CONF_ID], rhs)
 | 
			
		||||
        setup_component(trigger, conf)
 | 
			
		||||
 | 
			
		||||
        automation.build_automations(trigger, [], conf)
 | 
			
		||||
@@ -1,28 +1,29 @@
 | 
			
		||||
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_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, void
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
 | 
			
		||||
from esphome.components import mqtt
 | 
			
		||||
from esphome.components.mqtt import setup_mqtt_component
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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 esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, StructInitializer, add, get_variable, process_lambda, \
 | 
			
		||||
    templatable
 | 
			
		||||
from esphome.cpp_types import Action, Application, Component, Nameable, esphome_ns, float_, \
 | 
			
		||||
    std_string, uint32, void
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
# Base
 | 
			
		||||
light_ns = esphomelib_ns.namespace('light')
 | 
			
		||||
light_ns = esphome_ns.namespace('light')
 | 
			
		||||
LightState = light_ns.class_('LightState', Nameable, Component)
 | 
			
		||||
# Fake class for addressable lights
 | 
			
		||||
AddressableLightState = light_ns.class_('LightState', LightState)
 | 
			
		||||
MakeLight = Application.struct('MakeLight')
 | 
			
		||||
LightOutput = light_ns.class_('LightOutput')
 | 
			
		||||
AddressableLight = light_ns.class_('AddressableLight')
 | 
			
		||||
@@ -87,22 +88,22 @@ ADDRESSABLE_EFFECTS = RGB_EFFECTS + [CONF_ADDRESSABLE_LAMBDA, CONF_ADDRESSABLE_R
 | 
			
		||||
                                     CONF_ADDRESSABLE_TWINKLE, CONF_ADDRESSABLE_RANDOM_TWINKLE,
 | 
			
		||||
                                     CONF_ADDRESSABLE_FIREWORKS, CONF_ADDRESSABLE_FLICKER]
 | 
			
		||||
 | 
			
		||||
EFFECTS_SCHEMA = vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_LAMBDA): vol.Schema({
 | 
			
		||||
EFFECTS_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Optional(CONF_LAMBDA): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_NAME): cv.string,
 | 
			
		||||
        vol.Required(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
        vol.Optional(CONF_UPDATE_INTERVAL, default='0ms'): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_RANDOM): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_RANDOM): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(RandomLightEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Random"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_TRANSITION_LENGTH): cv.positive_time_period_milliseconds,
 | 
			
		||||
        vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_STROBE): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_STROBE): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(StrobeLightEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Strobe"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_COLORS): vol.All(cv.ensure_list(vol.Schema({
 | 
			
		||||
        vol.Optional(CONF_COLORS): vol.All(cv.ensure_list(cv.Schema({
 | 
			
		||||
            vol.Optional(CONF_STATE, default=True): cv.boolean,
 | 
			
		||||
            vol.Optional(CONF_BRIGHTNESS, default=1.0): cv.percentage,
 | 
			
		||||
            vol.Optional(CONF_RED, default=1.0): cv.percentage,
 | 
			
		||||
@@ -113,24 +114,24 @@ EFFECTS_SCHEMA = vol.Schema({
 | 
			
		||||
        }), cv.has_at_least_one_key(CONF_STATE, CONF_BRIGHTNESS, CONF_RED, CONF_GREEN, CONF_BLUE,
 | 
			
		||||
                                    CONF_WHITE)), vol.Length(min=2)),
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_FLICKER): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_FLICKER): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(FlickerLightEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Flicker"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_ALPHA): cv.percentage,
 | 
			
		||||
        vol.Optional(CONF_INTENSITY): cv.percentage,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_LAMBDA): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_LAMBDA): cv.Schema({
 | 
			
		||||
        vol.Required(CONF_NAME): cv.string,
 | 
			
		||||
        vol.Required(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
        vol.Optional(CONF_UPDATE_INTERVAL, default='0ms'): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_RAINBOW): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_RAINBOW): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableRainbowLightEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Rainbow"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_SPEED): cv.uint32_t,
 | 
			
		||||
        vol.Optional(CONF_WIDTH): cv.uint32_t,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_COLOR_WIPE): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_COLOR_WIPE): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableColorWipeEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Color Wipe"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_COLORS): cv.ensure_list({
 | 
			
		||||
@@ -144,24 +145,24 @@ EFFECTS_SCHEMA = vol.Schema({
 | 
			
		||||
        vol.Optional(CONF_ADD_LED_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
        vol.Optional(CONF_REVERSE): cv.boolean,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_SCAN): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_SCAN): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableScanEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Scan"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_MOVE_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_TWINKLE): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_TWINKLE): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableTwinkleEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Twinkle"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_TWINKLE_PROBABILITY): cv.percentage,
 | 
			
		||||
        vol.Optional(CONF_PROGRESS_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_RANDOM_TWINKLE): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_RANDOM_TWINKLE): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableRandomTwinkleEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Random Twinkle"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_TWINKLE_PROBABILITY): cv.percentage,
 | 
			
		||||
        vol.Optional(CONF_PROGRESS_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_FIREWORKS): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_FIREWORKS): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableFireworksEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Fireworks"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
@@ -169,7 +170,7 @@ EFFECTS_SCHEMA = vol.Schema({
 | 
			
		||||
        vol.Optional(CONF_USE_RANDOM_COLOR): cv.boolean,
 | 
			
		||||
        vol.Optional(CONF_FADE_OUT_RATE): cv.uint8_t,
 | 
			
		||||
    }),
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_FLICKER): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_ADDRESSABLE_FLICKER): cv.Schema({
 | 
			
		||||
        cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(AddressableFlickerEffect),
 | 
			
		||||
        vol.Optional(CONF_NAME, default="Addressable Flicker"): cv.string,
 | 
			
		||||
        vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
 | 
			
		||||
@@ -279,7 +280,7 @@ def build_effect(full_config):
 | 
			
		||||
                ('duration', color[CONF_DURATION]),
 | 
			
		||||
            ))
 | 
			
		||||
        if colors:
 | 
			
		||||
            add(effect.set_colors(ArrayInitializer(*colors)))
 | 
			
		||||
            add(effect.set_colors(colors))
 | 
			
		||||
        yield effect
 | 
			
		||||
    elif key == CONF_FLICKER:
 | 
			
		||||
        rhs = FlickerLightEffect.new(config[CONF_NAME])
 | 
			
		||||
@@ -322,7 +323,7 @@ def build_effect(full_config):
 | 
			
		||||
                ('num_leds', color[CONF_NUM_LEDS]),
 | 
			
		||||
            ))
 | 
			
		||||
        if colors:
 | 
			
		||||
            add(effect.set_colors(ArrayInitializer(*colors)))
 | 
			
		||||
            add(effect.set_colors(colors))
 | 
			
		||||
        yield effect
 | 
			
		||||
    elif key == CONF_ADDRESSABLE_SCAN:
 | 
			
		||||
        rhs = AddressableScanEffect.new(config[CONF_NAME])
 | 
			
		||||
@@ -370,7 +371,7 @@ def build_effect(full_config):
 | 
			
		||||
        raise NotImplementedError("Effect {} not implemented".format(next(config.keys())))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_light_core_(light_var, mqtt_var, config):
 | 
			
		||||
def setup_light_core_(light_var, config):
 | 
			
		||||
    if CONF_INTERNAL in config:
 | 
			
		||||
        add(light_var.set_internal(config[CONF_INTERNAL]))
 | 
			
		||||
    if CONF_DEFAULT_TRANSITION_LENGTH in config:
 | 
			
		||||
@@ -383,15 +384,14 @@ def setup_light_core_(light_var, mqtt_var, config):
 | 
			
		||||
            yield
 | 
			
		||||
        effects.append(effect)
 | 
			
		||||
    if effects:
 | 
			
		||||
        add(light_var.add_effects(ArrayInitializer(*effects)))
 | 
			
		||||
        add(light_var.add_effects(effects))
 | 
			
		||||
 | 
			
		||||
    setup_mqtt_component(mqtt_var, config)
 | 
			
		||||
    setup_mqtt_component(light_var.Pget_mqtt(), config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_light(light_obj, mqtt_obj, config):
 | 
			
		||||
def setup_light(light_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)
 | 
			
		||||
    CORE.add_job(setup_light_core_, light_var, mqtt_var, config)
 | 
			
		||||
    CORE.add_job(setup_light_core_, light_var, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_LIGHT'
 | 
			
		||||
@@ -404,14 +404,14 @@ 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):
 | 
			
		||||
def light_toggle_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_toggle_action(template_arg)
 | 
			
		||||
    type = ToggleAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    if CONF_TRANSITION_LENGTH in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32):
 | 
			
		||||
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_transition_length(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
@@ -425,14 +425,14 @@ 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):
 | 
			
		||||
def light_turn_off_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_turn_off_action(template_arg)
 | 
			
		||||
    type = TurnOffAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    if CONF_TRANSITION_LENGTH in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32):
 | 
			
		||||
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_transition_length(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
@@ -456,67 +456,46 @@ 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):
 | 
			
		||||
def light_turn_on_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_turn_on_action(template_arg)
 | 
			
		||||
    type = TurnOnAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    if CONF_TRANSITION_LENGTH in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32):
 | 
			
		||||
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_transition_length(template_))
 | 
			
		||||
    if CONF_FLASH_LENGTH in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_FLASH_LENGTH], arg_type, uint32):
 | 
			
		||||
        for template_ in templatable(config[CONF_FLASH_LENGTH], args, uint32):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_flash_length(template_))
 | 
			
		||||
    if CONF_BRIGHTNESS in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_BRIGHTNESS], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_BRIGHTNESS], args, float_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_brightness(template_))
 | 
			
		||||
    if CONF_RED in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_RED], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_RED], args, float_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_red(template_))
 | 
			
		||||
    if CONF_GREEN in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_GREEN], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_GREEN], args, float_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_green(template_))
 | 
			
		||||
    if CONF_BLUE in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_BLUE], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_BLUE], args, float_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_blue(template_))
 | 
			
		||||
    if CONF_WHITE in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_WHITE], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_WHITE], args, float_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_white(template_))
 | 
			
		||||
    if CONF_COLOR_TEMPERATURE in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_COLOR_TEMPERATURE], arg_type, float_):
 | 
			
		||||
        for template_ in templatable(config[CONF_COLOR_TEMPERATURE], args, float_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_color_temperature(template_))
 | 
			
		||||
    if CONF_EFFECT in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_EFFECT], arg_type, std_string):
 | 
			
		||||
        for template_ in templatable(config[CONF_EFFECT], args, std_string):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_effect(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=True,
 | 
			
		||||
                        white_value=True):
 | 
			
		||||
    ret = mqtt.build_hass_config(data, 'light', config, include_state=True, include_command=True)
 | 
			
		||||
    if ret is None:
 | 
			
		||||
        return None
 | 
			
		||||
    ret['schema'] = 'json'
 | 
			
		||||
    if brightness:
 | 
			
		||||
        ret['brightness'] = True
 | 
			
		||||
    if rgb:
 | 
			
		||||
        ret['rgb'] = True
 | 
			
		||||
    if color_temp:
 | 
			
		||||
        ret['color_temp'] = True
 | 
			
		||||
    if white_value:
 | 
			
		||||
        ret['white_value'] = True
 | 
			
		||||
    for effect in config.get(CONF_EFFECTS, []):
 | 
			
		||||
        ret["effect"] = True
 | 
			
		||||
        effects = ret.setdefault("effect_list", [])
 | 
			
		||||
        effects.append(next(x for x in effect.values())[CONF_NAME])
 | 
			
		||||
    return ret
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
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.cpp_generator import get_variable, variable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome.components import light, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_EFFECTS, CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
 | 
			
		||||
@@ -19,10 +19,5 @@ def to_code(config):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = App.make_binary_light(config[CONF_NAME], output_)
 | 
			
		||||
    light_struct = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, config)
 | 
			
		||||
    setup_component(light_struct.Pstate, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=False, rgb=False, color_temp=False,
 | 
			
		||||
                                     white_value=False)
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.components import light, output
 | 
			
		||||
from esphomeyaml.components.light.rgbww import validate_cold_white_colder, \
 | 
			
		||||
from esphome.components import light, output
 | 
			
		||||
from esphome.components.light.rgbww import validate_cold_white_colder, \
 | 
			
		||||
    validate_color_temperature
 | 
			
		||||
from esphomeyaml.const import CONF_COLD_WHITE, CONF_COLD_WHITE_COLOR_TEMPERATURE, \
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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.cpp_generator import get_variable, variable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
 | 
			
		||||
@@ -33,10 +33,5 @@ def to_code(config):
 | 
			
		||||
                              config[CONF_WARM_WHITE_COLOR_TEMPERATURE],
 | 
			
		||||
                              cold_white, warm_white)
 | 
			
		||||
    light_struct = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, config)
 | 
			
		||||
    setup_component(light_struct.Pstate, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=True, rgb=False, color_temp=True,
 | 
			
		||||
                                     white_value=False)
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
from esphomeyaml.components import light
 | 
			
		||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_CHIPSET, CONF_COLOR_CORRECT, CONF_DEFAULT_TRANSITION_LENGTH, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import light
 | 
			
		||||
from esphome.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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
 | 
			
		||||
from esphome.cpp_generator import RawExpression, TemplateArguments, add, get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Application
 | 
			
		||||
 | 
			
		||||
TYPES = [
 | 
			
		||||
    'NEOPIXEL',
 | 
			
		||||
@@ -57,6 +57,7 @@ def validate(value):
 | 
			
		||||
MakeFastLEDLight = Application.struct('MakeFastLEDLight')
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(light.AddressableLightState),
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeFastLEDLight),
 | 
			
		||||
 | 
			
		||||
    vol.Required(CONF_CHIPSET): cv.one_of(*TYPES, upper=True),
 | 
			
		||||
@@ -98,15 +99,10 @@ def to_code(config):
 | 
			
		||||
        r, g, b = config[CONF_COLOR_CORRECT]
 | 
			
		||||
        add(fast_led.set_correction(r, g, b))
 | 
			
		||||
 | 
			
		||||
    light.setup_light(make.Pstate, make.Pmqtt, config)
 | 
			
		||||
    light.setup_light(make.Pstate, config)
 | 
			
		||||
    setup_component(fast_led, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT'
 | 
			
		||||
REQUIRED_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,
 | 
			
		||||
                                     white_value=False)
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
from esphomeyaml.components import light
 | 
			
		||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_CHIPSET, CONF_CLOCK_PIN, CONF_COLOR_CORRECT, CONF_DATA_PIN, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import light
 | 
			
		||||
from esphome.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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
 | 
			
		||||
from esphome.cpp_generator import RawExpression, TemplateArguments, add, get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Application
 | 
			
		||||
 | 
			
		||||
CHIPSETS = [
 | 
			
		||||
    'LPD8806',
 | 
			
		||||
@@ -34,6 +34,7 @@ RGB_ORDERS = [
 | 
			
		||||
MakeFastLEDLight = Application.struct('MakeFastLEDLight')
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(light.AddressableLightState),
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeFastLEDLight),
 | 
			
		||||
 | 
			
		||||
    vol.Required(CONF_CHIPSET): cv.one_of(*CHIPSETS, upper=True),
 | 
			
		||||
@@ -78,15 +79,10 @@ def to_code(config):
 | 
			
		||||
        r, g, b = config[CONF_COLOR_CORRECT]
 | 
			
		||||
        add(fast_led.set_correction(r, g, b))
 | 
			
		||||
 | 
			
		||||
    light.setup_light(make.Pstate, make.Pmqtt, config)
 | 
			
		||||
    light.setup_light(make.Pstate, config)
 | 
			
		||||
    setup_component(fast_led, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT'
 | 
			
		||||
REQUIRED_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,
 | 
			
		||||
                                     white_value=False)
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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, \
 | 
			
		||||
from esphome.components import light, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, \
 | 
			
		||||
    CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
 | 
			
		||||
from esphomeyaml.cpp_generator import get_variable, variable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
 | 
			
		||||
@@ -22,10 +22,5 @@ def to_code(config):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = App.make_monochromatic_light(config[CONF_NAME], output_)
 | 
			
		||||
    light_struct = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, config)
 | 
			
		||||
    setup_component(light_struct.Pstate, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=True, rgb=False, color_temp=False,
 | 
			
		||||
                                     white_value=False)
 | 
			
		||||
@@ -1,17 +1,17 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
from esphomeyaml.components import light
 | 
			
		||||
from esphomeyaml.components.light import AddressableLight
 | 
			
		||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_CLOCK_PIN, CONF_COLOR_CORRECT, CONF_DATA_PIN, \
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import light
 | 
			
		||||
from esphome.components.light import AddressableLight
 | 
			
		||||
from esphome.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_CLOCK_PIN, CONF_COLOR_CORRECT, CONF_DATA_PIN, \
 | 
			
		||||
    CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_MAKE_ID, CONF_METHOD, \
 | 
			
		||||
    CONF_NAME, CONF_NUM_LEDS, CONF_PIN, CONF_POWER_SUPPLY, CONF_TYPE, CONF_VARIANT
 | 
			
		||||
from esphomeyaml.core import CORE
 | 
			
		||||
from esphomeyaml.cpp_generator import TemplateArguments, add, get_variable, variable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App, Application, Component, global_ns
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import TemplateArguments, add, get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Application, Component, global_ns
 | 
			
		||||
 | 
			
		||||
NeoPixelBusLightOutputBase = light.light_ns.class_('NeoPixelBusLightOutputBase', Component,
 | 
			
		||||
                                                   AddressableLight)
 | 
			
		||||
@@ -60,6 +60,30 @@ def validate_method(value):
 | 
			
		||||
    raise NotImplementedError
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_method_pin(value):
 | 
			
		||||
    method = value[CONF_METHOD]
 | 
			
		||||
    method_pins = {
 | 
			
		||||
        'ESP8266_DMA': [3],
 | 
			
		||||
        'ESP8266_UART0': [1],
 | 
			
		||||
        'ESP8266_ASYNC_UART0': [1],
 | 
			
		||||
        'ESP8266_UART1': [2],
 | 
			
		||||
        'ESP8266_ASYNC_UART1': [2],
 | 
			
		||||
        'ESP32_I2S_0': list(range(0, 32)),
 | 
			
		||||
        'ESP32_I2S_1': list(range(0, 32)),
 | 
			
		||||
    }
 | 
			
		||||
    if CORE.is_esp8266:
 | 
			
		||||
        method_pins['BIT_BANG'] = list(range(0, 16))
 | 
			
		||||
    elif CORE.is_esp32:
 | 
			
		||||
        method_pins['BIT_BANG'] = list(range(0, 32))
 | 
			
		||||
    pins_ = method_pins[method]
 | 
			
		||||
    for opt in (CONF_PIN, CONF_CLOCK_PIN, CONF_DATA_PIN):
 | 
			
		||||
        if opt in value and value[opt] not in pins_:
 | 
			
		||||
            raise vol.Invalid("Method {} only supports pin(s) {}".format(
 | 
			
		||||
                method, ', '.join('GPIO{}'.format(x) for x in pins_)
 | 
			
		||||
            ), path=[CONF_METHOD])
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
VARIANTS = {
 | 
			
		||||
    'WS2812X': 'Ws2812x',
 | 
			
		||||
    'SK6812': 'Sk6812',
 | 
			
		||||
@@ -107,6 +131,7 @@ def validate(config):
 | 
			
		||||
MakeNeoPixelBusLight = Application.struct('MakeNeoPixelBusLight')
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(light.AddressableLightState),
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeNeoPixelBusLight),
 | 
			
		||||
 | 
			
		||||
    vol.Optional(CONF_TYPE, default='GRB'): validate_type,
 | 
			
		||||
@@ -123,7 +148,7 @@ PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent),
 | 
			
		||||
    vol.Optional(CONF_EFFECTS): light.validate_effects(light.ADDRESSABLE_EFFECTS),
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema), validate)
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema), validate, validate_method_pin)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
@@ -156,15 +181,10 @@ def to_code(config):
 | 
			
		||||
    if CONF_COLOR_CORRECT in config:
 | 
			
		||||
        add(output.set_correction(*config[CONF_COLOR_CORRECT]))
 | 
			
		||||
 | 
			
		||||
    light.setup_light(make.Pstate, make.Pmqtt, config)
 | 
			
		||||
    light.setup_light(make.Pstate, config)
 | 
			
		||||
    setup_component(output, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_NEO_PIXEL_BUS_LIGHT'
 | 
			
		||||
REQUIRED_BUILD_FLAGS = '-DUSE_NEO_PIXEL_BUS_LIGHT'
 | 
			
		||||
 | 
			
		||||
LIB_DEPS = 'NeoPixelBus@2.4.1'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False,
 | 
			
		||||
                                     white_value='W' in config[CONF_TYPE])
 | 
			
		||||
							
								
								
									
										48
									
								
								esphome/components/light/partition.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								esphome/components/light/partition.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome.components import light
 | 
			
		||||
from esphome.components.light import AddressableLight
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_FROM, CONF_ID, \
 | 
			
		||||
    CONF_MAKE_ID, CONF_NAME, CONF_SEGMENTS, CONF_TO
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_types import App, Application
 | 
			
		||||
 | 
			
		||||
AddressableSegment = light.light_ns.class_('AddressableSegment')
 | 
			
		||||
PartitionLightOutput = light.light_ns.class_('PartitionLightOutput', AddressableLight)
 | 
			
		||||
MakePartitionLight = Application.struct('MakePartitionLight')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_from_to(value):
 | 
			
		||||
    if value[CONF_FROM] > value[CONF_TO]:
 | 
			
		||||
        raise vol.Invalid(u"From ({}) must not be larger than to ({})"
 | 
			
		||||
                          u"".format(value[CONF_FROM], value[CONF_TO]))
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(light.AddressableLightState),
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakePartitionLight),
 | 
			
		||||
 | 
			
		||||
    vol.Required(CONF_SEGMENTS): vol.All(cv.ensure_list({
 | 
			
		||||
        vol.Required(CONF_ID): cv.use_variable_id(light.AddressableLightState),
 | 
			
		||||
        vol.Required(CONF_FROM): cv.positive_int,
 | 
			
		||||
        vol.Required(CONF_TO): cv.positive_int,
 | 
			
		||||
    }, validate_from_to), vol.Length(min=1)),
 | 
			
		||||
 | 
			
		||||
    vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds,
 | 
			
		||||
    vol.Optional(CONF_EFFECTS): light.validate_effects(light.ADDRESSABLE_EFFECTS),
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    segments = []
 | 
			
		||||
    for conf in config[CONF_SEGMENTS]:
 | 
			
		||||
        for var in get_variable(conf[CONF_ID]):
 | 
			
		||||
            yield
 | 
			
		||||
        segments.append(AddressableSegment(var, conf[CONF_FROM],
 | 
			
		||||
                                           conf[CONF_TO] - conf[CONF_FROM] + 1))
 | 
			
		||||
 | 
			
		||||
    rhs = App.make_partition_light(config[CONF_NAME], segments)
 | 
			
		||||
    make = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(make.Pstate, config)
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import light, output
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, \
 | 
			
		||||
from esphome.components import light, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
 | 
			
		||||
@@ -28,10 +28,5 @@ def to_code(config):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue)
 | 
			
		||||
    light_struct = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, config)
 | 
			
		||||
    setup_component(light_struct.Pstate, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False,
 | 
			
		||||
                                     white_value=False)
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.components import light, output
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, \
 | 
			
		||||
from esphome.components import light, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
 | 
			
		||||
@@ -31,10 +31,5 @@ def to_code(config):
 | 
			
		||||
        yield
 | 
			
		||||
    rhs = App.make_rgbw_light(config[CONF_NAME], red, green, blue, white)
 | 
			
		||||
    light_struct = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, config)
 | 
			
		||||
    setup_component(light_struct.Pstate, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False,
 | 
			
		||||
                                     white_value=True)
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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, \
 | 
			
		||||
from esphome.components import light, output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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.cpp_generator import get_variable, variable
 | 
			
		||||
from esphomeyaml.cpp_helpers import setup_component
 | 
			
		||||
from esphomeyaml.cpp_types import App
 | 
			
		||||
from esphome.cpp_generator import get_variable, variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_color_temperature(value):
 | 
			
		||||
@@ -61,10 +61,5 @@ def to_code(config):
 | 
			
		||||
                               config[CONF_WARM_WHITE_COLOR_TEMPERATURE],
 | 
			
		||||
                               red, green, blue, cold_white, warm_white)
 | 
			
		||||
    light_struct = variable(config[CONF_MAKE_ID], rhs)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
 | 
			
		||||
    light.setup_light(light_struct.Pstate, config)
 | 
			
		||||
    setup_component(light_struct.Pstate, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_hass_config(data, config):
 | 
			
		||||
    return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=True,
 | 
			
		||||
                                     white_value=True)
 | 
			
		||||
@@ -2,24 +2,23 @@ import re
 | 
			
		||||
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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, CORE
 | 
			
		||||
from esphomeyaml.cpp_generator import Pvariable, RawExpression, add, process_lambda, statement
 | 
			
		||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns, void
 | 
			
		||||
 | 
			
		||||
from esphomeyaml.py_compat import text_type
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, LambdaAction
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ARGS, CONF_BAUD_RATE, CONF_FORMAT, CONF_HARDWARE_UART, CONF_ID, \
 | 
			
		||||
    CONF_LEVEL, CONF_LOGS, CONF_TAG, CONF_TX_BUFFER_SIZE
 | 
			
		||||
from esphome.core import CORE, EsphomeError, Lambda
 | 
			
		||||
from esphome.cpp_generator import Pvariable, RawExpression, add, process_lambda, statement
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns, global_ns, void
 | 
			
		||||
from esphome.py_compat import text_type
 | 
			
		||||
 | 
			
		||||
LOG_LEVELS = {
 | 
			
		||||
    'NONE': global_ns.ESPHOMELIB_LOG_LEVEL_NONE,
 | 
			
		||||
    'ERROR': global_ns.ESPHOMELIB_LOG_LEVEL_ERROR,
 | 
			
		||||
    'WARN': global_ns.ESPHOMELIB_LOG_LEVEL_WARN,
 | 
			
		||||
    'INFO': global_ns.ESPHOMELIB_LOG_LEVEL_INFO,
 | 
			
		||||
    'DEBUG': global_ns.ESPHOMELIB_LOG_LEVEL_DEBUG,
 | 
			
		||||
    'VERBOSE': global_ns.ESPHOMELIB_LOG_LEVEL_VERBOSE,
 | 
			
		||||
    'VERY_VERBOSE': global_ns.ESPHOMELIB_LOG_LEVEL_VERY_VERBOSE,
 | 
			
		||||
    'NONE': global_ns.ESPHOME_LOG_LEVEL_NONE,
 | 
			
		||||
    'ERROR': global_ns.ESPHOME_LOG_LEVEL_ERROR,
 | 
			
		||||
    'WARN': global_ns.ESPHOME_LOG_LEVEL_WARN,
 | 
			
		||||
    'INFO': global_ns.ESPHOME_LOG_LEVEL_INFO,
 | 
			
		||||
    'DEBUG': global_ns.ESPHOME_LOG_LEVEL_DEBUG,
 | 
			
		||||
    'VERBOSE': global_ns.ESPHOME_LOG_LEVEL_VERBOSE,
 | 
			
		||||
    'VERY_VERBOSE': global_ns.ESPHOME_LOG_LEVEL_VERY_VERBOSE,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LOG_LEVEL_TO_ESP_LOG = {
 | 
			
		||||
@@ -33,37 +32,64 @@ LOG_LEVEL_TO_ESP_LOG = {
 | 
			
		||||
 | 
			
		||||
LOG_LEVEL_SEVERITY = ['NONE', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'VERBOSE', 'VERY_VERBOSE']
 | 
			
		||||
 | 
			
		||||
UART_SELECTION_ESP32 = ['UART0', 'UART1', 'UART2']
 | 
			
		||||
 | 
			
		||||
UART_SELECTION_ESP8266 = ['UART0', 'UART0_SWAP', 'UART1']
 | 
			
		||||
 | 
			
		||||
HARDWARE_UART_TO_UART_SELECTION = {
 | 
			
		||||
    'UART0': global_ns.UART_SELECTION_UART0,
 | 
			
		||||
    'UART0_SWAP': global_ns.UART_SELECTION_UART0_SWAP,
 | 
			
		||||
    'UART1': global_ns.UART_SELECTION_UART1,
 | 
			
		||||
    'UART2': global_ns.UART_SELECTION_UART2,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HARDWARE_UART_TO_SERIAL = {
 | 
			
		||||
    'UART0': 'Serial',
 | 
			
		||||
    'UART0_SWAP': 'Serial',
 | 
			
		||||
    'UART1': 'Serial1',
 | 
			
		||||
    'UART2': 'Serial2',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# pylint: disable=invalid-name
 | 
			
		||||
is_log_level = cv.one_of(*LOG_LEVELS, upper=True)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def uart_selection(value):
 | 
			
		||||
    if CORE.is_esp32:
 | 
			
		||||
        return cv.one_of(*UART_SELECTION_ESP32, upper=True)(value)
 | 
			
		||||
    if CORE.is_esp8266:
 | 
			
		||||
        return cv.one_of(*UART_SELECTION_ESP8266, upper=True)(value)
 | 
			
		||||
    raise NotImplementedError
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_local_no_higher_than_global(value):
 | 
			
		||||
    global_level = value.get(CONF_LEVEL, 'DEBUG')
 | 
			
		||||
    for tag, level in value.get(CONF_LOGS, {}).items():
 | 
			
		||||
        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 "
 | 
			
		||||
                                   u"global log level {}.".format(level, tag, global_level))
 | 
			
		||||
            raise EsphomeError(u"The local log level {} for {} must be less severe than the "
 | 
			
		||||
                               u"global log level {}.".format(level, tag, global_level))
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
LogComponent = esphomelib_ns.class_('LogComponent', Component)
 | 
			
		||||
LogComponent = esphome_ns.class_('LogComponent', Component)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.All(vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = vol.All(cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(LogComponent),
 | 
			
		||||
    vol.Optional(CONF_BAUD_RATE, default=115200): cv.positive_int,
 | 
			
		||||
    vol.Optional(CONF_TX_BUFFER_SIZE): cv.validate_bytes,
 | 
			
		||||
    vol.Optional(CONF_TX_BUFFER_SIZE, default=512): cv.validate_bytes,
 | 
			
		||||
    vol.Optional(CONF_HARDWARE_UART, default='UART0'): uart_selection,
 | 
			
		||||
    vol.Optional(CONF_LEVEL): is_log_level,
 | 
			
		||||
    vol.Optional(CONF_LOGS): vol.Schema({
 | 
			
		||||
    vol.Optional(CONF_LOGS): cv.Schema({
 | 
			
		||||
        cv.string: is_log_level,
 | 
			
		||||
    })
 | 
			
		||||
}), validate_local_no_higher_than_global)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.init_log(config.get(CONF_BAUD_RATE))
 | 
			
		||||
    rhs = App.init_log(config.get(CONF_BAUD_RATE),
 | 
			
		||||
                       config.get(CONF_TX_BUFFER_SIZE),
 | 
			
		||||
                       HARDWARE_UART_TO_UART_SELECTION[config.get(CONF_HARDWARE_UART)])
 | 
			
		||||
    log = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    if CONF_TX_BUFFER_SIZE in config:
 | 
			
		||||
        add(log.set_tx_buffer_size(config[CONF_TX_BUFFER_SIZE]))
 | 
			
		||||
    if CONF_LEVEL in config:
 | 
			
		||||
        add(log.set_global_log_level(LOG_LEVELS[config[CONF_LEVEL]]))
 | 
			
		||||
    for tag, level in config.get(CONF_LOGS, {}).items():
 | 
			
		||||
@@ -73,13 +99,16 @@ def to_code(config):
 | 
			
		||||
def required_build_flags(config):
 | 
			
		||||
    flags = []
 | 
			
		||||
    if CONF_LEVEL in config:
 | 
			
		||||
        flags.append(u'-DESPHOMELIB_LOG_LEVEL={}'.format(str(LOG_LEVELS[config[CONF_LEVEL]])))
 | 
			
		||||
        flags.append(u'-DESPHOME_LOG_LEVEL={}'.format(str(LOG_LEVELS[config[CONF_LEVEL]])))
 | 
			
		||||
        this_severity = LOG_LEVEL_SEVERITY.index(config[CONF_LEVEL])
 | 
			
		||||
        verbose_severity = LOG_LEVEL_SEVERITY.index('VERBOSE')
 | 
			
		||||
        very_verbose_severity = LOG_LEVEL_SEVERITY.index('VERY_VERBOSE')
 | 
			
		||||
        is_at_least_verbose = this_severity >= verbose_severity
 | 
			
		||||
        is_at_least_very_verbose = this_severity >= very_verbose_severity
 | 
			
		||||
        has_serial_logging = config.get(CONF_BAUD_RATE) != 0
 | 
			
		||||
        if CORE.is_esp8266 and has_serial_logging and is_at_least_verbose:
 | 
			
		||||
            flags.append(u"-DDEBUG_ESP_PORT=Serial")
 | 
			
		||||
            debug_serial_port = HARDWARE_UART_TO_SERIAL[config.get(CONF_HARDWARE_UART)]
 | 
			
		||||
            flags.append(u"-DDEBUG_ESP_PORT={}".format(debug_serial_port))
 | 
			
		||||
            flags.append(u"-DLWIP_DEBUG")
 | 
			
		||||
            DEBUG_COMPONENTS = {
 | 
			
		||||
                'HTTP_CLIENT',
 | 
			
		||||
@@ -95,6 +124,8 @@ def required_build_flags(config):
 | 
			
		||||
                flags.append(u"-DDEBUG_ESP_{}".format(comp))
 | 
			
		||||
        if CORE.is_esp32 and is_at_least_verbose:
 | 
			
		||||
            flags.append('-DCORE_DEBUG_LEVEL=5')
 | 
			
		||||
        if CORE.is_esp32 and is_at_least_very_verbose:
 | 
			
		||||
            flags.append('-DENABLE_I2C_DEBUG_BUFFER')
 | 
			
		||||
 | 
			
		||||
    return flags
 | 
			
		||||
 | 
			
		||||
@@ -102,8 +133,8 @@ def required_build_flags(config):
 | 
			
		||||
def maybe_simple_message(schema):
 | 
			
		||||
    def validator(value):
 | 
			
		||||
        if isinstance(value, dict):
 | 
			
		||||
            return vol.Schema(schema)(value)
 | 
			
		||||
        return vol.Schema(schema)({CONF_FORMAT: value})
 | 
			
		||||
            return cv.Schema(schema)(value)
 | 
			
		||||
        return cv.Schema(schema)({CONF_FORMAT: value})
 | 
			
		||||
 | 
			
		||||
    return validator
 | 
			
		||||
 | 
			
		||||
@@ -140,13 +171,13 @@ 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):
 | 
			
		||||
def logger_log_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    esp_log = LOG_LEVEL_TO_ESP_LOG[config[CONF_LEVEL]]
 | 
			
		||||
    args = [RawExpression(text_type(x)) for x in config[CONF_ARGS]]
 | 
			
		||||
    args_ = [RawExpression(text_type(x)) for x in config[CONF_ARGS]]
 | 
			
		||||
 | 
			
		||||
    text = text_type(statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args)))
 | 
			
		||||
    text = text_type(statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args_)))
 | 
			
		||||
 | 
			
		||||
    for lambda_ in process_lambda(Lambda(text), [(arg_type, 'x')], return_type=void):
 | 
			
		||||
    for lambda_ in process_lambda(Lambda(text), args, return_type=void):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = LambdaAction.new(template_arg, lambda_)
 | 
			
		||||
    type = LambdaAction.template(template_arg)
 | 
			
		||||
							
								
								
									
										35
									
								
								esphome/components/mcp23017.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								esphome/components/mcp23017.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome import pins
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_ID
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, GPIOInputPin, GPIOOutputPin, io_ns, esphome_ns
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['i2c']
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
MCP23017GPIOMode = esphome_ns.enum('MCP23017GPIOMode')
 | 
			
		||||
MCP23017_GPIO_MODES = {
 | 
			
		||||
    'INPUT': MCP23017GPIOMode.MCP23017_INPUT,
 | 
			
		||||
    'INPUT_PULLUP': MCP23017GPIOMode.MCP23017_INPUT_PULLUP,
 | 
			
		||||
    'OUTPUT': MCP23017GPIOMode.MCP23017_OUTPUT,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MCP23017GPIOInputPin = io_ns.class_('MCP23017GPIOInputPin', GPIOInputPin)
 | 
			
		||||
MCP23017GPIOOutputPin = io_ns.class_('MCP23017GPIOOutputPin', GPIOOutputPin)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_ID): cv.declare_variable_id(pins.MCP23017),
 | 
			
		||||
    vol.Optional(CONF_ADDRESS, default=0x20): cv.i2c_address,
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_mcp23017_component(config[CONF_ADDRESS])
 | 
			
		||||
    var = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
    setup_component(var, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_MCP23017'
 | 
			
		||||
							
								
								
									
										29
									
								
								esphome/components/mpr121.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								esphome/components/mpr121.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome.components import i2c, binary_sensor
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ADDRESS, CONF_ID
 | 
			
		||||
from esphome.cpp_generator import Pvariable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['i2c']
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
CONF_MPR121_ID = 'mpr121_id'
 | 
			
		||||
MPR121Component = binary_sensor.binary_sensor_ns.class_('MPR121Component', Component, i2c.I2CDevice)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(MPR121Component),
 | 
			
		||||
    vol.Optional(CONF_ADDRESS): cv.i2c_address
 | 
			
		||||
}).extend(cv.COMPONENT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    rhs = App.make_mpr121(config.get(CONF_ADDRESS))
 | 
			
		||||
    var = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    setup_component(var, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_MPR121'
 | 
			
		||||
@@ -1,24 +1,22 @@
 | 
			
		||||
from collections import OrderedDict
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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_AVAILABILITY, CONF_BIRTH_MESSAGE, CONF_BROKER, CONF_CLIENT_ID, \
 | 
			
		||||
from esphome import automation
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, CONDITION_REGISTRY, Condition
 | 
			
		||||
from esphome.components import logger
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.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, void
 | 
			
		||||
    CONF_ID, CONF_KEEPALIVE, CONF_LEVEL, CONF_LOG_TOPIC, 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 esphome.cpp_generator import Pvariable, RawExpression, StructInitializer, TemplateArguments, \
 | 
			
		||||
    add, get_variable, process_lambda, templatable
 | 
			
		||||
from esphome.cpp_types import Action, App, Component, JsonObjectConstRef, JsonObjectRef, \
 | 
			
		||||
    Trigger, bool_, esphome_ns, optional, std_string, uint8, void
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_message_just_topic(value):
 | 
			
		||||
@@ -26,7 +24,7 @@ def validate_message_just_topic(value):
 | 
			
		||||
    return MQTT_MESSAGE_BASE({CONF_TOPIC: value})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
MQTT_MESSAGE_BASE = vol.Schema({
 | 
			
		||||
MQTT_MESSAGE_BASE = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_TOPIC): cv.publish_topic,
 | 
			
		||||
    vol.Optional(CONF_QOS, default=0): cv.mqtt_qos,
 | 
			
		||||
    vol.Optional(CONF_RETAIN, default=True): cv.boolean,
 | 
			
		||||
@@ -38,7 +36,7 @@ MQTT_MESSAGE_SCHEMA = vol.Any(None, MQTT_MESSAGE_BASE.extend({
 | 
			
		||||
    vol.Required(CONF_PAYLOAD): cv.mqtt_payload,
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
mqtt_ns = esphomelib_ns.namespace('mqtt')
 | 
			
		||||
mqtt_ns = esphome_ns.namespace('mqtt')
 | 
			
		||||
MQTTMessage = mqtt_ns.struct('MQTTMessage')
 | 
			
		||||
MQTTClientComponent = mqtt_ns.class_('MQTTClientComponent', Component)
 | 
			
		||||
MQTTPublishAction = mqtt_ns.class_('MQTTPublishAction', Action)
 | 
			
		||||
@@ -47,6 +45,7 @@ MQTTMessageTrigger = mqtt_ns.class_('MQTTMessageTrigger', Trigger.template(std_s
 | 
			
		||||
MQTTJsonMessageTrigger = mqtt_ns.class_('MQTTJsonMessageTrigger',
 | 
			
		||||
                                        Trigger.template(JsonObjectConstRef))
 | 
			
		||||
MQTTComponent = mqtt_ns.class_('MQTTComponent', Component)
 | 
			
		||||
MQTTConnectedCondition = mqtt_ns.class_('MQTTConnectedCondition', Condition)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_config(value):
 | 
			
		||||
@@ -67,7 +66,7 @@ def validate_fingerprint(value):
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.All(vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = vol.All(cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(MQTTClientComponent),
 | 
			
		||||
    vol.Required(CONF_BROKER): cv.string_strict,
 | 
			
		||||
    vol.Optional(CONF_PORT): cv.port,
 | 
			
		||||
@@ -163,13 +162,13 @@ def to_code(config):
 | 
			
		||||
        else:
 | 
			
		||||
            add(mqtt.set_log_message_template(exp_mqtt_message(log_topic)))
 | 
			
		||||
 | 
			
		||||
            if CONF_LEVEL in config:
 | 
			
		||||
                add(mqtt.set_log_level(logger.LOG_LEVELS[config[CONF_LEVEL]]))
 | 
			
		||||
            if CONF_LEVEL in log_topic:
 | 
			
		||||
                add(mqtt.set_log_level(logger.LOG_LEVELS[log_topic[CONF_LEVEL]]))
 | 
			
		||||
 | 
			
		||||
    if CONF_SSL_FINGERPRINTS in config:
 | 
			
		||||
        for fingerprint in config[CONF_SSL_FINGERPRINTS]:
 | 
			
		||||
            arr = [RawExpression("0x{}".format(fingerprint[i:i + 2])) for i in range(0, 40, 2)]
 | 
			
		||||
            add(mqtt.add_ssl_fingerprint(ArrayInitializer(*arr, multiline=False)))
 | 
			
		||||
            add(mqtt.add_ssl_fingerprint(arr))
 | 
			
		||||
 | 
			
		||||
    if CONF_KEEPALIVE in config:
 | 
			
		||||
        add(mqtt.set_keep_alive(config[CONF_KEEPALIVE]))
 | 
			
		||||
@@ -184,16 +183,17 @@ def to_code(config):
 | 
			
		||||
            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)
 | 
			
		||||
        automation.build_automations(trigger, [(std_string, 'x')], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_JSON_MESSAGE, []):
 | 
			
		||||
        rhs = mqtt.make_json_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
 | 
			
		||||
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
 | 
			
		||||
        automation.build_automation(trigger, JsonObjectConstRef, conf)
 | 
			
		||||
        automation.build_automations(trigger, [(JsonObjectConstRef, 'x')], conf)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_MQTT_PUBLISH = 'mqtt.publish'
 | 
			
		||||
MQTT_PUBLISH_ACTION_SCHEMA = vol.Schema({
 | 
			
		||||
MQTT_PUBLISH_ACTION_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.use_variable_id(MQTTClientComponent),
 | 
			
		||||
    vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic),
 | 
			
		||||
    vol.Required(CONF_PAYLOAD): cv.templatable(cv.mqtt_payload),
 | 
			
		||||
    vol.Optional(CONF_QOS): cv.templatable(cv.mqtt_qos),
 | 
			
		||||
@@ -202,30 +202,33 @@ 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):
 | 
			
		||||
    rhs = App.Pget_mqtt_client().Pmake_publish_action(template_arg)
 | 
			
		||||
def mqtt_publish_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_publish_action(template_arg)
 | 
			
		||||
    type = MQTTPublishAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    for template_ in templatable(config[CONF_TOPIC], arg_type, std_string):
 | 
			
		||||
    for template_ in templatable(config[CONF_TOPIC], args, std_string):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.set_topic(template_))
 | 
			
		||||
 | 
			
		||||
    for template_ in templatable(config[CONF_PAYLOAD], arg_type, std_string):
 | 
			
		||||
    for template_ in templatable(config[CONF_PAYLOAD], args, std_string):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.set_payload(template_))
 | 
			
		||||
    if CONF_QOS in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_QOS], arg_type, uint8):
 | 
			
		||||
        for template_ in templatable(config[CONF_QOS], args, uint8):
 | 
			
		||||
            yield
 | 
			
		||||
        add(action.set_qos(template_))
 | 
			
		||||
    if CONF_RETAIN in config:
 | 
			
		||||
        for template_ in templatable(config[CONF_RETAIN], arg_type, bool_):
 | 
			
		||||
        for template_ in templatable(config[CONF_RETAIN], args, bool_):
 | 
			
		||||
            yield None
 | 
			
		||||
        add(action.set_retain(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_MQTT_PUBLISH_JSON = 'mqtt.publish_json'
 | 
			
		||||
MQTT_PUBLISH_JSON_ACTION_SCHEMA = vol.Schema({
 | 
			
		||||
MQTT_PUBLISH_JSON_ACTION_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.use_variable_id(MQTTClientComponent),
 | 
			
		||||
    vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic),
 | 
			
		||||
    vol.Required(CONF_PAYLOAD): cv.lambda_,
 | 
			
		||||
    vol.Optional(CONF_QOS): cv.mqtt_qos,
 | 
			
		||||
@@ -234,16 +237,18 @@ 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):
 | 
			
		||||
    rhs = App.Pget_mqtt_client().Pmake_publish_json_action(template_arg)
 | 
			
		||||
def mqtt_publish_json_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_publish_json_action(template_arg)
 | 
			
		||||
    type = MQTTPublishJsonAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    for template_ in templatable(config[CONF_TOPIC], arg_type, std_string):
 | 
			
		||||
    for template_ in templatable(config[CONF_TOPIC], args, std_string):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.set_topic(template_))
 | 
			
		||||
 | 
			
		||||
    for lambda_ in process_lambda(config[CONF_PAYLOAD], [(arg_type, 'x'), (JsonObjectRef, 'root')],
 | 
			
		||||
                                  return_type=void):
 | 
			
		||||
    args_ = args + [(JsonObjectRef, 'root')]
 | 
			
		||||
    for lambda_ in process_lambda(config[CONF_PAYLOAD], args_, return_type=void):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.set_payload(lambda_))
 | 
			
		||||
    if CONF_QOS in config:
 | 
			
		||||
@@ -266,61 +271,6 @@ def get_default_topic_for(data, component_type, name, suffix):
 | 
			
		||||
                                sanitized_name, suffix)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_hass_config(data, component_type, config, include_state=True, include_command=True):
 | 
			
		||||
    if config.get(CONF_INTERNAL, False):
 | 
			
		||||
        return None
 | 
			
		||||
    ret = OrderedDict()
 | 
			
		||||
    ret['platform'] = 'mqtt'
 | 
			
		||||
    ret['name'] = config[CONF_NAME]
 | 
			
		||||
    if include_state:
 | 
			
		||||
        default = get_default_topic_for(data, component_type, config[CONF_NAME], 'state')
 | 
			
		||||
        ret['state_topic'] = config.get(CONF_STATE_TOPIC, default)
 | 
			
		||||
    if include_command:
 | 
			
		||||
        default = get_default_topic_for(data, component_type, config[CONF_NAME], 'command')
 | 
			
		||||
        ret['command_topic'] = config.get(CONF_STATE_TOPIC, default)
 | 
			
		||||
    avail = config.get(CONF_AVAILABILITY, data.availability)
 | 
			
		||||
    if avail:
 | 
			
		||||
        ret['availability_topic'] = avail[CONF_TOPIC]
 | 
			
		||||
        payload_available = avail[CONF_PAYLOAD_AVAILABLE]
 | 
			
		||||
        if payload_available != 'online':
 | 
			
		||||
            ret['payload_available'] = payload_available
 | 
			
		||||
        payload_not_available = avail[CONF_PAYLOAD_NOT_AVAILABLE]
 | 
			
		||||
        if payload_not_available != 'offline':
 | 
			
		||||
            ret['payload_not_available'] = payload_not_available
 | 
			
		||||
    return ret
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class GenerateHassConfigData(object):
 | 
			
		||||
    def __init__(self, config):
 | 
			
		||||
        if 'mqtt' not in config:
 | 
			
		||||
            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])
 | 
			
		||||
        birth_message = mqtt.get(CONF_BIRTH_MESSAGE)
 | 
			
		||||
        if CONF_BIRTH_MESSAGE not in mqtt:
 | 
			
		||||
            birth_message = {
 | 
			
		||||
                CONF_TOPIC: self.topic_prefix + '/status',
 | 
			
		||||
                CONF_PAYLOAD: 'online',
 | 
			
		||||
            }
 | 
			
		||||
        will_message = mqtt.get(CONF_WILL_MESSAGE)
 | 
			
		||||
        if CONF_WILL_MESSAGE not in mqtt:
 | 
			
		||||
            will_message = {
 | 
			
		||||
                CONF_TOPIC: self.topic_prefix + '/status',
 | 
			
		||||
                CONF_PAYLOAD: 'offline'
 | 
			
		||||
            }
 | 
			
		||||
        if not birth_message or not will_message:
 | 
			
		||||
            self.availability = None
 | 
			
		||||
        elif birth_message[CONF_TOPIC] != will_message[CONF_TOPIC]:
 | 
			
		||||
            self.availability = None
 | 
			
		||||
        else:
 | 
			
		||||
            self.availability = {
 | 
			
		||||
                CONF_TOPIC: birth_message[CONF_TOPIC],
 | 
			
		||||
                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]))
 | 
			
		||||
@@ -337,3 +287,17 @@ def setup_mqtt_component(obj, config):
 | 
			
		||||
        else:
 | 
			
		||||
            add(obj.set_availability(availability[CONF_TOPIC], availability[CONF_PAYLOAD_AVAILABLE],
 | 
			
		||||
                                     availability[CONF_PAYLOAD_NOT_AVAILABLE]))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
LIB_DEPS = 'AsyncMqttClient@0.8.2'
 | 
			
		||||
BUILD_FLAGS = '-DUSE_MQTT'
 | 
			
		||||
 | 
			
		||||
CONF_MQTT_CONNECTED = 'mqtt.connected'
 | 
			
		||||
MQTT_CONNECTED_CONDITION_SCHEMA = cv.Schema({})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@CONDITION_REGISTRY.register(CONF_MQTT_CONNECTED, MQTT_CONNECTED_CONDITION_SCHEMA)
 | 
			
		||||
def mqtt_connected_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    rhs = MQTTConnectedCondition.new(template_arg)
 | 
			
		||||
    type = MQTTConnectedCondition.template(template_arg)
 | 
			
		||||
    yield Pvariable(condition_id, rhs, type=type)
 | 
			
		||||
@@ -1,18 +1,18 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphomeyaml import pins
 | 
			
		||||
from esphomeyaml.components import output
 | 
			
		||||
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
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.components import output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import (CONF_BIT_DEPTH, CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID,
 | 
			
		||||
                           CONF_NUM_CHANNELS, CONF_NUM_CHIPS, CONF_UPDATE_ON_BOOT)
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
 | 
			
		||||
from esphome.cpp_types import App, Component
 | 
			
		||||
 | 
			
		||||
MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component)
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.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,
 | 
			
		||||
@@ -2,17 +2,17 @@ import logging
 | 
			
		||||
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
import esphomeyaml.config_validation as cv
 | 
			
		||||
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
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_OTA, CONF_PASSWORD, CONF_PORT, CONF_SAFE_MODE
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add
 | 
			
		||||
from esphome.cpp_types import App, Component, esphome_ns
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
OTAComponent = esphomelib_ns.class_('OTAComponent', Component)
 | 
			
		||||
OTAComponent = esphome_ns.class_('OTAComponent', Component)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = vol.Schema({
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(OTAComponent),
 | 
			
		||||
    vol.Optional(CONF_SAFE_MODE, default=True): cv.boolean,
 | 
			
		||||
    vol.Optional(CONF_PORT): cv.port,
 | 
			
		||||
@@ -51,7 +51,7 @@ REQUIRED_BUILD_FLAGS = '-DUSE_NEW_OTA'
 | 
			
		||||
 | 
			
		||||
def lib_deps(config):
 | 
			
		||||
    if CORE.is_esp32:
 | 
			
		||||
        return ['Update', 'ESPmDNS']
 | 
			
		||||
        return ['Update']
 | 
			
		||||
    if CORE.is_esp8266:
 | 
			
		||||
        return ['Hash', 'ESP8266mDNS']
 | 
			
		||||
        return ['Hash']
 | 
			
		||||
    raise NotImplementedError
 | 
			
		||||
@@ -1,18 +1,19 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
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.core import CORE
 | 
			
		||||
from esphomeyaml.cpp_generator import add, get_variable, Pvariable, templatable
 | 
			
		||||
from esphomeyaml.cpp_types import esphomelib_ns, Action, float_
 | 
			
		||||
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
 | 
			
		||||
from esphome.components.power_supply import PowerSupplyComponent
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_INVERTED, CONF_LEVEL, CONF_MAX_POWER, \
 | 
			
		||||
    CONF_MIN_POWER, CONF_POWER_SUPPLY
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, add, get_variable, templatable
 | 
			
		||||
from esphome.cpp_types import Action, esphome_ns, float_
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
BINARY_OUTPUT_SCHEMA = vol.Schema({
 | 
			
		||||
BINARY_OUTPUT_SCHEMA = cv.Schema({
 | 
			
		||||
    vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent),
 | 
			
		||||
    vol.Optional(CONF_INVERTED): cv.boolean,
 | 
			
		||||
})
 | 
			
		||||
@@ -21,11 +22,12 @@ BINARY_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(BINARY_OUTPUT_SCHEMA.sche
 | 
			
		||||
 | 
			
		||||
FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({
 | 
			
		||||
    vol.Optional(CONF_MAX_POWER): cv.percentage,
 | 
			
		||||
    vol.Optional(CONF_MIN_POWER): cv.percentage,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(FLOAT_OUTPUT_SCHEMA.schema)
 | 
			
		||||
 | 
			
		||||
output_ns = esphomelib_ns.namespace('output')
 | 
			
		||||
output_ns = esphome_ns.namespace('output')
 | 
			
		||||
BinaryOutput = output_ns.class_('BinaryOutput')
 | 
			
		||||
BinaryOutputPtr = BinaryOutput.operator('ptr')
 | 
			
		||||
FloatOutput = output_ns.class_('FloatOutput', BinaryOutput)
 | 
			
		||||
@@ -47,6 +49,8 @@ def setup_output_platform_(obj, config, skip_power_supply=False):
 | 
			
		||||
        add(obj.set_power_supply(power_supply))
 | 
			
		||||
    if CONF_MAX_POWER in config:
 | 
			
		||||
        add(obj.set_max_power(config[CONF_MAX_POWER]))
 | 
			
		||||
    if CONF_MIN_POWER in config:
 | 
			
		||||
        add(obj.set_min_power(config[CONF_MIN_POWER]))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_output_platform(obj, config, skip_power_supply=False):
 | 
			
		||||
@@ -60,7 +64,6 @@ def register_output(var, config):
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_OUTPUT'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_OUTPUT_TURN_ON = 'output.turn_on'
 | 
			
		||||
OUTPUT_TURN_ON_ACTION = maybe_simple_id({
 | 
			
		||||
    vol.Required(CONF_ID): cv.use_variable_id(BinaryOutput),
 | 
			
		||||
@@ -68,11 +71,11 @@ 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):
 | 
			
		||||
def output_turn_on_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_turn_on_action(template_arg)
 | 
			
		||||
    type = TurnOnAction.template(arg_type)
 | 
			
		||||
    type = TurnOnAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -83,29 +86,29 @@ 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):
 | 
			
		||||
def output_turn_off_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_turn_off_action(template_arg)
 | 
			
		||||
    type = TurnOffAction.template(arg_type)
 | 
			
		||||
    type = TurnOffAction.template(template_arg)
 | 
			
		||||
    yield Pvariable(action_id, rhs, type=type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONF_OUTPUT_SET_LEVEL = 'output.set_level'
 | 
			
		||||
OUTPUT_SET_LEVEL_ACTION = vol.Schema({
 | 
			
		||||
OUTPUT_SET_LEVEL_ACTION = cv.Schema({
 | 
			
		||||
    vol.Required(CONF_ID): cv.use_variable_id(FloatOutput),
 | 
			
		||||
    vol.Required(CONF_LEVEL): cv.templatable(cv.percentage),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ACTION_REGISTRY.register(CONF_OUTPUT_SET_LEVEL, OUTPUT_SET_LEVEL_ACTION)
 | 
			
		||||
def output_set_level_to_code(config, action_id, arg_type, template_arg):
 | 
			
		||||
def output_set_level_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    for var in get_variable(config[CONF_ID]):
 | 
			
		||||
        yield None
 | 
			
		||||
    rhs = var.make_set_level_action(template_arg)
 | 
			
		||||
    type = SetLevelAction.template(arg_type)
 | 
			
		||||
    type = SetLevelAction.template(template_arg)
 | 
			
		||||
    action = Pvariable(action_id, rhs, type=type)
 | 
			
		||||
    for template_ in templatable(config[CONF_LEVEL], arg_type, float_):
 | 
			
		||||
    for template_ in templatable(config[CONF_LEVEL], args, float_):
 | 
			
		||||
        yield None
 | 
			
		||||
    add(action.set_level(template_))
 | 
			
		||||
    yield action
 | 
			
		||||
							
								
								
									
										58
									
								
								esphome/components/output/copy.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								esphome/components/output/copy.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
import voluptuous as vol
 | 
			
		||||
 | 
			
		||||
from esphome.components import output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_OUTPUTS, CONF_TYPE
 | 
			
		||||
from esphome.cpp_generator import Pvariable, get_variable
 | 
			
		||||
from esphome.cpp_helpers import setup_component
 | 
			
		||||
 | 
			
		||||
BinaryCopyOutput = output.output_ns.class_('BinaryCopyOutput', output.BinaryOutput)
 | 
			
		||||
FloatCopyOutput = output.output_ns.class_('FloatCopyOutput', output.FloatOutput)
 | 
			
		||||
 | 
			
		||||
BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Required(CONF_ID): cv.declare_variable_id(BinaryCopyOutput),
 | 
			
		||||
    vol.Required(CONF_TYPE): 'binary',
 | 
			
		||||
    vol.Required(CONF_OUTPUTS): cv.ensure_list(cv.use_variable_id(output.BinaryOutput)),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
FLOAT_SCHEMA = output.PLATFORM_SCHEMA.extend({
 | 
			
		||||
    vol.Required(CONF_ID): cv.declare_variable_id(FloatCopyOutput),
 | 
			
		||||
    vol.Required(CONF_TYPE): 'float',
 | 
			
		||||
    vol.Required(CONF_OUTPUTS): cv.ensure_list(cv.use_variable_id(output.FloatOutput)),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_copy_output(value):
 | 
			
		||||
    if not isinstance(value, dict):
 | 
			
		||||
        raise vol.Invalid("Value must be dict")
 | 
			
		||||
    type = cv.string_strict(value.get(CONF_TYPE, 'float')).lower()
 | 
			
		||||
    value[CONF_TYPE] = type
 | 
			
		||||
    if type == 'binary':
 | 
			
		||||
        return BINARY_SCHEMA(value)
 | 
			
		||||
    if type == 'float':
 | 
			
		||||
        return FLOAT_SCHEMA(value)
 | 
			
		||||
    raise vol.Invalid("type must either be binary or float, not {}!".format(type))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PLATFORM_SCHEMA = validate_copy_output
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    outputs = []
 | 
			
		||||
    for out in config[CONF_OUTPUTS]:
 | 
			
		||||
        for var in get_variable(out):
 | 
			
		||||
            yield
 | 
			
		||||
        outputs.append(var)
 | 
			
		||||
 | 
			
		||||
    klass = {
 | 
			
		||||
        'binary': BinaryCopyOutput,
 | 
			
		||||
        'float': FloatCopyOutput,
 | 
			
		||||
    }[config[CONF_TYPE]]
 | 
			
		||||
    rhs = klass.new(outputs)
 | 
			
		||||
    gpio = Pvariable(config[CONF_ID], rhs)
 | 
			
		||||
 | 
			
		||||
    output.setup_output_platform(gpio, config)
 | 
			
		||||
    setup_component(gpio, config)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_COPY_OUTPUT'
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
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
 | 
			
		||||
from esphome.components import output
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE
 | 
			
		||||
from esphome.cpp_generator import process_lambda, variable
 | 
			
		||||
from esphome.cpp_types import std_vector
 | 
			
		||||
 | 
			
		||||
CustomBinaryOutputConstructor = output.output_ns.class_('CustomBinaryOutputConstructor')
 | 
			
		||||
CustomFloatOutputConstructor = output.output_ns.class_('CustomFloatOutputConstructor')
 | 
			
		||||
@@ -12,6 +12,7 @@ CustomFloatOutputConstructor = output.output_ns.class_('CustomFloatOutputConstru
 | 
			
		||||
BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(CustomBinaryOutputConstructor),
 | 
			
		||||
    vol.Required(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
    vol.Required(CONF_TYPE): 'binary',
 | 
			
		||||
    vol.Required(CONF_OUTPUTS):
 | 
			
		||||
        cv.ensure_list(output.BINARY_OUTPUT_SCHEMA.extend({
 | 
			
		||||
            cv.GenerateID(): cv.declare_variable_id(output.BinaryOutput),
 | 
			
		||||
@@ -21,8 +22,9 @@ BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({
 | 
			
		||||
FLOAT_SCHEMA = output.PLATFORM_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_variable_id(CustomFloatOutputConstructor),
 | 
			
		||||
    vol.Required(CONF_LAMBDA): cv.lambda_,
 | 
			
		||||
    vol.Required(CONF_TYPE): 'float',
 | 
			
		||||
    vol.Required(CONF_OUTPUTS):
 | 
			
		||||
        cv.ensure_list(output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
 | 
			
		||||
        cv.ensure_list(output.FLOAT_OUTPUT_SCHEMA.extend({
 | 
			
		||||
            cv.GenerateID(): cv.declare_variable_id(output.FloatOutput),
 | 
			
		||||
        })),
 | 
			
		||||
})
 | 
			
		||||
@@ -59,8 +61,8 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
    for i, conf in enumerate(config[CONF_OUTPUTS]):
 | 
			
		||||
        output.register_output(custom.get_output(i), conf)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BUILD_FLAGS = '-DUSE_CUSTOM_OUTPUT'
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user