mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	Compare commits
	
		
			56 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					642bc91a76 | ||
| 
						 | 
					d69926ee56 | ||
| 
						 | 
					4758403d44 | ||
| 
						 | 
					4b0ec5c28a | ||
| 
						 | 
					4b2a9e5e49 | ||
| 
						 | 
					1449c51d49 | ||
| 
						 | 
					a451705e0b | ||
| 
						 | 
					2e6db39173 | ||
| 
						 | 
					373f75253c | ||
| 
						 | 
					724842084e | ||
| 
						 | 
					8f3635b167 | ||
| 
						 | 
					11605a36f7 | ||
| 
						 | 
					533f81d625 | ||
| 
						 | 
					aacb9e44e8 | ||
| 
						 | 
					c6e3f1bca6 | ||
| 
						 | 
					a933d4aeb6 | ||
| 
						 | 
					caa5b20791 | ||
| 
						 | 
					e2ad9ed746 | ||
| 
						 | 
					32c0e7c2ae | ||
| 
						 | 
					6c564c7b7f | ||
| 
						 | 
					c81e3a3be4 | ||
| 
						 | 
					6b1b9ef7ec | ||
| 
						 | 
					c26a8b8718 | ||
| 
						 | 
					4a89a475bd | ||
| 
						 | 
					8cf15c7f5c | ||
| 
						 | 
					adc76ca1b8 | ||
| 
						 | 
					8f8892440c | ||
| 
						 | 
					570843150d | ||
| 
						 | 
					f3fc9e4142 | ||
| 
						 | 
					075fcb77a8 | ||
| 
						 | 
					e5899ff717 | ||
| 
						 | 
					2fb3970027 | ||
| 
						 | 
					1a4efa1b8c | ||
| 
						 | 
					72f656ffef | ||
| 
						 | 
					b60239d5e5 | ||
| 
						 | 
					d02e280c3c | ||
| 
						 | 
					6535b0966e | ||
| 
						 | 
					82dbacbee5 | ||
| 
						 | 
					2432901974 | ||
| 
						 | 
					ebb5d58c14 | ||
| 
						 | 
					605e365405 | ||
| 
						 | 
					5ab995d8ca | ||
| 
						 | 
					4248741b11 | ||
| 
						 | 
					4b8ecc7634 | ||
| 
						 | 
					25d04c759c | ||
| 
						 | 
					b4ec84030e | ||
| 
						 | 
					29e8761373 | ||
| 
						 | 
					a04299c59e | ||
| 
						 | 
					d7bf3c51d9 | ||
| 
						 | 
					ac0b095941 | ||
| 
						 | 
					cda9bad233 | ||
| 
						 | 
					41db8a1264 | ||
| 
						 | 
					e7e785fd60 | ||
| 
						 | 
					300d3a1f46 | ||
| 
						 | 
					356554c08d | ||
| 
						 | 
					ced28ad006 | 
@@ -3,7 +3,7 @@
 | 
			
		||||
variables:
 | 
			
		||||
  DOCKER_DRIVER: overlay2
 | 
			
		||||
  DOCKER_HOST: tcp://docker:2375/
 | 
			
		||||
  BASE_VERSION: '1.5.1'
 | 
			
		||||
  BASE_VERSION: '1.8.3'
 | 
			
		||||
  TZ: UTC
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
sudo: false
 | 
			
		||||
language: python
 | 
			
		||||
python: '2.7'
 | 
			
		||||
install: script/setup
 | 
			
		||||
cache:
 | 
			
		||||
  directories:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
ARG BUILD_FROM=esphome/esphome-base-amd64:1.5.1
 | 
			
		||||
ARG BUILD_FROM=esphome/esphome-base-amd64:1.8.3
 | 
			
		||||
FROM ${BUILD_FROM}
 | 
			
		||||
 | 
			
		||||
COPY . .
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
FROM esphome/esphome-base-amd64:1.5.1
 | 
			
		||||
FROM esphome/esphome-base-amd64:1.8.3
 | 
			
		||||
 | 
			
		||||
RUN \
 | 
			
		||||
    apt-get update \
 | 
			
		||||
@@ -12,7 +12,7 @@ RUN \
 | 
			
		||||
        /var/lib/apt/lists/*
 | 
			
		||||
 | 
			
		||||
COPY requirements_test.txt /requirements_test.txt
 | 
			
		||||
RUN pip2 install -r /requirements_test.txt
 | 
			
		||||
RUN pip2 install --no-cache-dir wheel && pip2 install --no-cache-dir -r /requirements_test.txt
 | 
			
		||||
 | 
			
		||||
VOLUME ["/esphome"]
 | 
			
		||||
WORKDIR /esphome
 | 
			
		||||
 
 | 
			
		||||
@@ -1,21 +0,0 @@
 | 
			
		||||
FROM ubuntu:bionic
 | 
			
		||||
 | 
			
		||||
RUN apt-get update && apt-get install -y --no-install-recommends \
 | 
			
		||||
        python \
 | 
			
		||||
        python-pip \
 | 
			
		||||
        python-setuptools \
 | 
			
		||||
        python-pil \
 | 
			
		||||
        git \
 | 
			
		||||
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \
 | 
			
		||||
    pip install --no-cache-dir platformio && \
 | 
			
		||||
    platformio settings set enable_telemetry No && \
 | 
			
		||||
    platformio settings set check_libraries_interval 1000000 && \
 | 
			
		||||
    platformio settings set check_platformio_interval 1000000 && \
 | 
			
		||||
    platformio settings set check_platforms_interval 1000000
 | 
			
		||||
 | 
			
		||||
COPY docker/platformio.ini /pio/platformio.ini
 | 
			
		||||
RUN platformio run -d /pio; rm -rf /pio
 | 
			
		||||
 | 
			
		||||
COPY requirements.txt /requirements.txt
 | 
			
		||||
 | 
			
		||||
RUN pip install --no-cache-dir -r /requirements.txt
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
; This file allows the docker build file to install the required platformio
 | 
			
		||||
; platforms
 | 
			
		||||
 | 
			
		||||
[env:espressif8266]
 | 
			
		||||
platform = espressif8266@1.8.0
 | 
			
		||||
board = nodemcuv2
 | 
			
		||||
framework = arduino
 | 
			
		||||
 | 
			
		||||
[env:espressif32]
 | 
			
		||||
platform = espressif32@1.5.0
 | 
			
		||||
board = nodemcu-32s
 | 
			
		||||
framework = arduino
 | 
			
		||||
@@ -4,6 +4,11 @@ server {
 | 
			
		||||
    include /etc/nginx/includes/server_params.conf;
 | 
			
		||||
    include /etc/nginx/includes/proxy_params.conf;
 | 
			
		||||
    include /etc/nginx/includes/ssl_params.conf;
 | 
			
		||||
 | 
			
		||||
    ssl on;
 | 
			
		||||
    ssl_certificate /ssl/%%certfile%%;
 | 
			
		||||
    ssl_certificate_key /ssl/%%keyfile%%;
 | 
			
		||||
 | 
			
		||||
    # Clear Hass.io Ingress header
 | 
			
		||||
    proxy_set_header X-Hassio-Ingress "";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -108,7 +108,6 @@ class APIClient(threading.Thread):
 | 
			
		||||
        self._message_handlers = []
 | 
			
		||||
        self._keepalive = 5
 | 
			
		||||
        self._ping_timer = None
 | 
			
		||||
        self._refresh_ping()
 | 
			
		||||
 | 
			
		||||
        self.on_disconnect = None
 | 
			
		||||
        self.on_connect = None
 | 
			
		||||
@@ -132,8 +131,8 @@ class APIClient(threading.Thread):
 | 
			
		||||
            if self._connected:
 | 
			
		||||
                try:
 | 
			
		||||
                    self.ping()
 | 
			
		||||
                except APIConnectionError:
 | 
			
		||||
                    self._fatal_error()
 | 
			
		||||
                except APIConnectionError as err:
 | 
			
		||||
                    self._fatal_error(err)
 | 
			
		||||
                else:
 | 
			
		||||
                    self._refresh_ping()
 | 
			
		||||
 | 
			
		||||
@@ -175,7 +174,7 @@ class APIClient(threading.Thread):
 | 
			
		||||
            raise APIConnectionError("You need to call start() first!")
 | 
			
		||||
 | 
			
		||||
        if self._connected:
 | 
			
		||||
            raise APIConnectionError("Already connected!")
 | 
			
		||||
            self.disconnect(on_disconnect=False)
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            ip = resolve_ip_address(self._address)
 | 
			
		||||
@@ -193,8 +192,9 @@ class APIClient(threading.Thread):
 | 
			
		||||
        try:
 | 
			
		||||
            self._socket.connect((ip, self._port))
 | 
			
		||||
        except socket.error as err:
 | 
			
		||||
            self._fatal_error()
 | 
			
		||||
            raise APIConnectionError("Error connecting to {}: {}".format(ip, err))
 | 
			
		||||
            err = APIConnectionError("Error connecting to {}: {}".format(ip, err))
 | 
			
		||||
            self._fatal_error(err)
 | 
			
		||||
            raise err
 | 
			
		||||
        self._socket.settimeout(0.1)
 | 
			
		||||
 | 
			
		||||
        self._socket_open_event.set()
 | 
			
		||||
@@ -204,18 +204,20 @@ class APIClient(threading.Thread):
 | 
			
		||||
        try:
 | 
			
		||||
            resp = self._send_message_await_response(hello, pb.HelloResponse)
 | 
			
		||||
        except APIConnectionError as err:
 | 
			
		||||
            self._fatal_error()
 | 
			
		||||
            self._fatal_error(err)
 | 
			
		||||
            raise err
 | 
			
		||||
        _LOGGER.debug("Successfully connected to %s ('%s' API=%s.%s)", self._address,
 | 
			
		||||
                      resp.server_info, resp.api_version_major, resp.api_version_minor)
 | 
			
		||||
        self._connected = True
 | 
			
		||||
        self._refresh_ping()
 | 
			
		||||
        if self.on_connect is not None:
 | 
			
		||||
            self.on_connect()
 | 
			
		||||
 | 
			
		||||
    def _check_connected(self):
 | 
			
		||||
        if not self._connected:
 | 
			
		||||
            self._fatal_error()
 | 
			
		||||
            raise APIConnectionError("Must be connected!")
 | 
			
		||||
            err = APIConnectionError("Must be connected!")
 | 
			
		||||
            self._fatal_error(err)
 | 
			
		||||
            raise err
 | 
			
		||||
 | 
			
		||||
    def login(self):
 | 
			
		||||
        self._check_connected()
 | 
			
		||||
@@ -233,13 +235,13 @@ class APIClient(threading.Thread):
 | 
			
		||||
        if self.on_login is not None:
 | 
			
		||||
            self.on_login()
 | 
			
		||||
 | 
			
		||||
    def _fatal_error(self):
 | 
			
		||||
    def _fatal_error(self, err):
 | 
			
		||||
        was_connected = self._connected
 | 
			
		||||
 | 
			
		||||
        self._close_socket()
 | 
			
		||||
 | 
			
		||||
        if was_connected and self.on_disconnect is not None:
 | 
			
		||||
            self.on_disconnect()
 | 
			
		||||
            self.on_disconnect(err)
 | 
			
		||||
 | 
			
		||||
    def _write(self, data):  # type: (bytes) -> None
 | 
			
		||||
        if self._socket is None:
 | 
			
		||||
@@ -250,8 +252,9 @@ class APIClient(threading.Thread):
 | 
			
		||||
            try:
 | 
			
		||||
                self._socket.sendall(data)
 | 
			
		||||
            except socket.error as err:
 | 
			
		||||
                self._fatal_error()
 | 
			
		||||
                raise APIConnectionError("Error while writing data: {}".format(err))
 | 
			
		||||
                err = APIConnectionError("Error while writing data: {}".format(err))
 | 
			
		||||
                self._fatal_error(err)
 | 
			
		||||
                raise err
 | 
			
		||||
 | 
			
		||||
    def _send_message(self, msg):
 | 
			
		||||
        # type: (message.Message) -> None
 | 
			
		||||
@@ -271,7 +274,6 @@ class APIClient(threading.Thread):
 | 
			
		||||
        req += _varuint_to_bytes(message_type)
 | 
			
		||||
        req += encoded
 | 
			
		||||
        self._write(req)
 | 
			
		||||
        self._refresh_ping()
 | 
			
		||||
 | 
			
		||||
    def _send_message_await_response_complex(self, send_msg, do_append, do_stop, timeout=1):
 | 
			
		||||
        event = threading.Event()
 | 
			
		||||
@@ -309,7 +311,7 @@ class APIClient(threading.Thread):
 | 
			
		||||
        self._check_connected()
 | 
			
		||||
        return self._send_message_await_response(pb.PingRequest(), pb.PingResponse)
 | 
			
		||||
 | 
			
		||||
    def disconnect(self):
 | 
			
		||||
    def disconnect(self, on_disconnect=True):
 | 
			
		||||
        self._check_connected()
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
@@ -318,7 +320,7 @@ class APIClient(threading.Thread):
 | 
			
		||||
            pass
 | 
			
		||||
        self._close_socket()
 | 
			
		||||
 | 
			
		||||
        if self.on_disconnect is not None:
 | 
			
		||||
        if self.on_disconnect is not None and on_disconnect:
 | 
			
		||||
            self.on_disconnect()
 | 
			
		||||
 | 
			
		||||
    def _check_authenticated(self):
 | 
			
		||||
@@ -387,7 +389,6 @@ class APIClient(threading.Thread):
 | 
			
		||||
        for msg_handler in self._message_handlers[:]:
 | 
			
		||||
            msg_handler(msg)
 | 
			
		||||
        self._handle_internal_messages(msg)
 | 
			
		||||
        self._refresh_ping()
 | 
			
		||||
 | 
			
		||||
    def run(self):
 | 
			
		||||
        self._running_event.set()
 | 
			
		||||
@@ -399,7 +400,7 @@ class APIClient(threading.Thread):
 | 
			
		||||
                    break
 | 
			
		||||
                if self._connected:
 | 
			
		||||
                    _LOGGER.error("Error while reading incoming messages: %s", err)
 | 
			
		||||
                    self._fatal_error()
 | 
			
		||||
                    self._fatal_error(err)
 | 
			
		||||
        self._running_event.clear()
 | 
			
		||||
 | 
			
		||||
    def _handle_internal_messages(self, msg):
 | 
			
		||||
@@ -431,12 +432,12 @@ def run_logs(config, address):
 | 
			
		||||
 | 
			
		||||
    has_connects = []
 | 
			
		||||
 | 
			
		||||
    def try_connect(tries=0, is_disconnect=True):
 | 
			
		||||
    def try_connect(err, tries=0):
 | 
			
		||||
        if stopping:
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        if is_disconnect:
 | 
			
		||||
            _LOGGER.warning(u"Disconnected from API.")
 | 
			
		||||
        if err:
 | 
			
		||||
            _LOGGER.warning(u"Disconnected from API: %s", err)
 | 
			
		||||
 | 
			
		||||
        while retry_timer:
 | 
			
		||||
            retry_timer.pop(0).cancel()
 | 
			
		||||
@@ -445,8 +446,8 @@ def run_logs(config, address):
 | 
			
		||||
        try:
 | 
			
		||||
            cli.connect()
 | 
			
		||||
            cli.login()
 | 
			
		||||
        except APIConnectionError as err:  # noqa
 | 
			
		||||
            error = err
 | 
			
		||||
        except APIConnectionError as err2:  # noqa
 | 
			
		||||
            error = err2
 | 
			
		||||
 | 
			
		||||
        if error is None:
 | 
			
		||||
            _LOGGER.info("Successfully connected to %s", address)
 | 
			
		||||
@@ -460,7 +461,7 @@ def run_logs(config, address):
 | 
			
		||||
        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 = threading.Timer(wait_time, functools.partial(try_connect, None, tries + 1))
 | 
			
		||||
        timer.start()
 | 
			
		||||
        retry_timer.append(timer)
 | 
			
		||||
 | 
			
		||||
@@ -484,7 +485,7 @@ def run_logs(config, address):
 | 
			
		||||
    cli.start()
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        try_connect(is_disconnect=False)
 | 
			
		||||
        try_connect(None)
 | 
			
		||||
        while True:
 | 
			
		||||
            time.sleep(1)
 | 
			
		||||
    except KeyboardInterrupt:
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ UpdateComponentAction = cg.esphome_ns.class_('UpdateComponentAction', Action)
 | 
			
		||||
Automation = cg.esphome_ns.class_('Automation')
 | 
			
		||||
 | 
			
		||||
LambdaCondition = cg.esphome_ns.class_('LambdaCondition', Condition)
 | 
			
		||||
ForCondition = cg.esphome_ns.class_('ForCondition', Condition)
 | 
			
		||||
ForCondition = cg.esphome_ns.class_('ForCondition', Condition, cg.Component)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_automation(extra_schema=None, extra_validators=None, single=False):
 | 
			
		||||
 
 | 
			
		||||
@@ -144,7 +144,7 @@ float ADS1115Component::request_measurement(ADS1115Sensor *sensor) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  this->status_clear_warning();
 | 
			
		||||
  return millivolts / 1e4f;
 | 
			
		||||
  return millivolts / 1e3f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t ADS1115Sensor::get_multiplexer() const { return this->multiplexer_; }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
#include "esphome/core/util.h"
 | 
			
		||||
#include "esphome/core/defines.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
 | 
			
		||||
#ifdef USE_DEEP_SLEEP
 | 
			
		||||
#include "esphome/components/deep_sleep/deep_sleep_component.h"
 | 
			
		||||
@@ -712,12 +713,12 @@ bool APIConnection::send_buffer(APIMessageType type) {
 | 
			
		||||
  size_t needed_space = this->send_buffer_.size() + header_len;
 | 
			
		||||
 | 
			
		||||
  if (needed_space > this->client_->space()) {
 | 
			
		||||
    delay(5);
 | 
			
		||||
    delay(0);
 | 
			
		||||
    if (needed_space > this->client_->space()) {
 | 
			
		||||
      if (type != APIMessageType::SUBSCRIBE_LOGS_RESPONSE) {
 | 
			
		||||
        ESP_LOGV(TAG, "Cannot send message because of TCP buffer space");
 | 
			
		||||
      }
 | 
			
		||||
      delay(5);
 | 
			
		||||
      delay(0);
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -25,4 +25,4 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
    wwhite = yield cg.get_variable(config[CONF_WARM_WHITE])
 | 
			
		||||
    cg.add(var.set_warm_white(wwhite))
 | 
			
		||||
    cg.add(var.set_warm_white_temperature(config[CONF_COLD_WHITE_COLOR_TEMPERATURE]))
 | 
			
		||||
    cg.add(var.set_warm_white_temperature(config[CONF_WARM_WHITE_COLOR_TEMPERATURE]))
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/helpers.h"
 | 
			
		||||
#include "esphome/core/defines.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
 | 
			
		||||
#ifdef ARDUINO_ARCH_ESP32
 | 
			
		||||
#include <rom/rtc.h>
 | 
			
		||||
@@ -19,7 +20,7 @@ void DebugComponent::dump_config() {
 | 
			
		||||
  return;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  ESP_LOGD(TAG, "ESPHome Core version %s", ESPHOME_VERSION);
 | 
			
		||||
  ESP_LOGD(TAG, "ESPHome version %s", ESPHOME_VERSION);
 | 
			
		||||
  this->free_heap_ = ESP.getFreeHeap();
 | 
			
		||||
  ESP_LOGD(TAG, "Free Heap Size: %u bytes", this->free_heap_);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -87,7 +87,7 @@ void DeepSleepComponent::begin_sleep(bool manual) {
 | 
			
		||||
  ESP.deepSleep(*this->sleep_duration_);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
float DeepSleepComponent::get_setup_priority() const { return -100.0f; }
 | 
			
		||||
float DeepSleepComponent::get_setup_priority() const { return setup_priority::LATE; }
 | 
			
		||||
void DeepSleepComponent::prevent_deep_sleep() { this->prevent_ = true; }
 | 
			
		||||
 | 
			
		||||
}  // namespace deep_sleep
 | 
			
		||||
 
 | 
			
		||||
@@ -164,11 +164,18 @@ bool HOT DHT::read_sensor_(float *temperature, float *humidity, bool report_erro
 | 
			
		||||
  } else {
 | 
			
		||||
    uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
 | 
			
		||||
    uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF);
 | 
			
		||||
    *humidity = raw_humidity * 0.1f;
 | 
			
		||||
 | 
			
		||||
    if ((raw_temperature & 0x8000) != 0)
 | 
			
		||||
      raw_temperature = ~(raw_temperature & 0x7FFF);
 | 
			
		||||
 | 
			
		||||
    if (raw_temperature == 1 && raw_humidity == 10) {
 | 
			
		||||
      if (report_errors) {
 | 
			
		||||
        ESP_LOGE(TAG, "Invalid temperature+humidity! Sensor reported 1°C and 1%% Hum");
 | 
			
		||||
      }
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *humidity = raw_humidity * 0.1f;
 | 
			
		||||
    *temperature = int16_t(raw_temperature) * 0.1f;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
#include "esp32_ble_tracker.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
 | 
			
		||||
#ifdef ARDUINO_ARCH_ESP32
 | 
			
		||||
 | 
			
		||||
@@ -162,6 +163,11 @@ void ESP32BLETracker::start_scan(bool first) {
 | 
			
		||||
 | 
			
		||||
  esp_ble_gap_set_scan_params(&this->scan_params_);
 | 
			
		||||
  esp_ble_gap_start_scanning(this->scan_interval_);
 | 
			
		||||
 | 
			
		||||
  this->set_timeout("scan", this->scan_interval_ * 2000, []() {
 | 
			
		||||
    ESP_LOGW(TAG, "ESP-IDF BLE scan never terminated, rebooting to restore BLE stack...");
 | 
			
		||||
    App.reboot();
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ESP32BLETracker::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ FanSpeed = fan_ns.enum('FanSpeed')
 | 
			
		||||
FAN_SPEEDS = {
 | 
			
		||||
    'OFF': FanSpeed.FAN_SPEED_OFF,
 | 
			
		||||
    'LOW': FanSpeed.FAN_SPEED_LOW,
 | 
			
		||||
    'MEDIuM': FanSpeed.FAN_SPEED_MEDIUM,
 | 
			
		||||
    'MEDIUM': FanSpeed.FAN_SPEED_MEDIUM,
 | 
			
		||||
    'HIGH': FanSpeed.FAN_SPEED_HIGH,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,7 @@ from esphome.const import CONF_OUTPUT_ID, CONF_NUM_LEDS, CONF_RGB_ORDER, CONF_MA
 | 
			
		||||
from esphome.core import coroutine
 | 
			
		||||
 | 
			
		||||
fastled_base_ns = cg.esphome_ns.namespace('fastled_base')
 | 
			
		||||
FastLEDLightOutput = fastled_base_ns.class_('FastLEDLightOutput', cg.Component,
 | 
			
		||||
                                            light.AddressableLight)
 | 
			
		||||
FastLEDLightOutput = fastled_base_ns.class_('FastLEDLightOutput', light.AddressableLight)
 | 
			
		||||
 | 
			
		||||
RGB_ORDERS = [
 | 
			
		||||
    'RGB',
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace fastled_base {
 | 
			
		||||
 | 
			
		||||
class FastLEDLightOutput : public Component, public light::AddressableLight {
 | 
			
		||||
class FastLEDLightOutput : public light::AddressableLight {
 | 
			
		||||
 public:
 | 
			
		||||
  /// Only for custom effects: Get the internal controller.
 | 
			
		||||
  CLEDController *get_controller() const { return this->controller_; }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
#include "hx711.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/helpers.h"
 | 
			
		||||
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace hx711 {
 | 
			
		||||
@@ -10,6 +11,7 @@ void HX711Sensor::setup() {
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "Setting up HX711 '%s'...", this->name_.c_str());
 | 
			
		||||
  this->sck_pin_->setup();
 | 
			
		||||
  this->dout_pin_->setup();
 | 
			
		||||
  this->sck_pin_->digital_write(false);
 | 
			
		||||
 | 
			
		||||
  // Read sensor once without publishing to set the gain
 | 
			
		||||
  this->read_sensor_(nullptr);
 | 
			
		||||
@@ -25,8 +27,9 @@ float HX711Sensor::get_setup_priority() const { return setup_priority::DATA; }
 | 
			
		||||
void HX711Sensor::update() {
 | 
			
		||||
  uint32_t result;
 | 
			
		||||
  if (this->read_sensor_(&result)) {
 | 
			
		||||
    ESP_LOGD(TAG, "'%s': Got value %u", this->name_.c_str(), result);
 | 
			
		||||
    this->publish_state(result);
 | 
			
		||||
    int32_t value = static_cast<int32_t>(result);
 | 
			
		||||
    ESP_LOGD(TAG, "'%s': Got value %d", this->name_.c_str(), value);
 | 
			
		||||
    this->publish_state(value);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
bool HX711Sensor::read_sensor_(uint32_t *result) {
 | 
			
		||||
@@ -39,10 +42,11 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
 | 
			
		||||
  this->status_clear_warning();
 | 
			
		||||
  uint32_t data = 0;
 | 
			
		||||
 | 
			
		||||
  disable_interrupts();
 | 
			
		||||
  for (uint8_t i = 0; i < 24; i++) {
 | 
			
		||||
    this->sck_pin_->digital_write(true);
 | 
			
		||||
    delayMicroseconds(1);
 | 
			
		||||
    data |= uint32_t(this->dout_pin_->digital_read()) << (24 - i);
 | 
			
		||||
    data |= uint32_t(this->dout_pin_->digital_read()) << (23 - i);
 | 
			
		||||
    this->sck_pin_->digital_write(false);
 | 
			
		||||
    delayMicroseconds(1);
 | 
			
		||||
  }
 | 
			
		||||
@@ -50,10 +54,16 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
 | 
			
		||||
  // Cycle clock pin for gain setting
 | 
			
		||||
  for (uint8_t i = 0; i < this->gain_; i++) {
 | 
			
		||||
    this->sck_pin_->digital_write(true);
 | 
			
		||||
    delayMicroseconds(1);
 | 
			
		||||
    this->sck_pin_->digital_write(false);
 | 
			
		||||
    delayMicroseconds(1);
 | 
			
		||||
  }
 | 
			
		||||
  enable_interrupts();
 | 
			
		||||
 | 
			
		||||
  if (data & 0x800000ULL) {
 | 
			
		||||
    data |= 0xFF000000ULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  data ^= 0x800000;
 | 
			
		||||
  if (result != nullptr)
 | 
			
		||||
    *result = data;
 | 
			
		||||
  return true;
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ void I2CComponent::dump_config() {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
float I2CComponent::get_setup_priority() const { return setup_priority::HARDWARE; }
 | 
			
		||||
float I2CComponent::get_setup_priority() const { return setup_priority::BUS; }
 | 
			
		||||
 | 
			
		||||
void I2CComponent::raw_begin_transmission(uint8_t address) {
 | 
			
		||||
  ESP_LOGVV(TAG, "Beginning Transmission to 0x%02X:", address);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ import esphome.codegen as cg
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome import automation
 | 
			
		||||
from esphome.components import sensor
 | 
			
		||||
from esphome.const import CONF_ID, CONF_TIME_ID, CONF_SENSOR, CONF_RESTORE
 | 
			
		||||
from esphome.const import CONF_ID, CONF_SENSOR, CONF_RESTORE
 | 
			
		||||
 | 
			
		||||
integration_ns = cg.esphome_ns.namespace('integration')
 | 
			
		||||
IntegrationSensor = integration_ns.class_('IntegrationSensor', sensor.Sensor, cg.Component)
 | 
			
		||||
@@ -26,7 +26,6 @@ INTEGRATION_METHODS = {
 | 
			
		||||
CONF_TIME_UNIT = 'time_unit'
 | 
			
		||||
CONF_INTEGRATION_METHOD = 'integration_method'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_id(IntegrationSensor),
 | 
			
		||||
    cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
 | 
			
		||||
@@ -45,7 +44,7 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
    sens = yield cg.get_variable(config[CONF_SENSOR])
 | 
			
		||||
    cg.add(var.set_sensor(sens))
 | 
			
		||||
    cg.add(var.set_time(config[CONF_TIME_ID]))
 | 
			
		||||
    cg.add(var.set_time(config[CONF_TIME_UNIT]))
 | 
			
		||||
    cg.add(var.set_method(config[CONF_INTEGRATION_METHOD]))
 | 
			
		||||
    cg.add(var.set_restore(config[CONF_RESTORE]))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace light {
 | 
			
		||||
 | 
			
		||||
static const char *TAG = "light.addressable";
 | 
			
		||||
 | 
			
		||||
const ESPColor ESPColor::BLACK = ESPColor(0, 0, 0, 0);
 | 
			
		||||
const ESPColor ESPColor::WHITE = ESPColor(255, 255, 255, 255);
 | 
			
		||||
 | 
			
		||||
@@ -80,11 +82,78 @@ void ESPRangeView::set(const ESPColor &color) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
ESPColorView ESPRangeView::operator[](int32_t index) const {
 | 
			
		||||
  index = interpret_index(index, this->size());
 | 
			
		||||
  index = interpret_index(index, this->size()) + this->begin_;
 | 
			
		||||
  return (*this->parent_)[index];
 | 
			
		||||
}
 | 
			
		||||
ESPRangeIterator ESPRangeView::begin() { return {*this, this->begin_}; }
 | 
			
		||||
ESPRangeIterator ESPRangeView::end() { return {*this, this->end_}; }
 | 
			
		||||
void ESPRangeView::set_red(uint8_t red) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.set_red(red);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::set_green(uint8_t green) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.set_green(green);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::set_blue(uint8_t blue) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.set_blue(blue);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::set_white(uint8_t white) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.set_white(white);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::set_effect_data(uint8_t effect_data) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.set_effect_data(effect_data);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::fade_to_white(uint8_t amnt) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.fade_to_white(amnt);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::fade_to_black(uint8_t amnt) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.fade_to_white(amnt);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::lighten(uint8_t delta) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.lighten(delta);
 | 
			
		||||
}
 | 
			
		||||
void ESPRangeView::darken(uint8_t delta) {
 | 
			
		||||
  for (auto c : *this)
 | 
			
		||||
    c.darken(delta);
 | 
			
		||||
}
 | 
			
		||||
ESPRangeView &ESPRangeView::operator=(const ESPRangeView &rhs) {
 | 
			
		||||
  // If size doesn't match, error (todo warning)
 | 
			
		||||
  if (rhs.size() != this->size())
 | 
			
		||||
    return *this;
 | 
			
		||||
 | 
			
		||||
ESPColorView ESPRangeView::Iterator::operator*() const { return (*this->range_->parent_)[this->i_]; }
 | 
			
		||||
  if (this->parent_ != rhs.parent_) {
 | 
			
		||||
    for (int32_t i = 0; i < this->size(); i++)
 | 
			
		||||
      (*this)[i].set(rhs[i].get());
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // If both equal, already done
 | 
			
		||||
  if (rhs.begin_ == this->begin_)
 | 
			
		||||
    return *this;
 | 
			
		||||
 | 
			
		||||
  if (rhs.begin_ > this->begin_) {
 | 
			
		||||
    // Copy from left
 | 
			
		||||
    for (int32_t i = 0; i < this->size(); i++) {
 | 
			
		||||
      (*this)[i].set(rhs[i].get());
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    // Copy from right
 | 
			
		||||
    for (int32_t i = this->size() - 1; i >= 0; i--) {
 | 
			
		||||
      (*this)[i].set(rhs[i].get());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return *this;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ESPColorView ESPRangeIterator::operator*() const { return this->range_.parent_->get(this->i_); }
 | 
			
		||||
 | 
			
		||||
int32_t HOT interpret_index(int32_t index, int32_t size) {
 | 
			
		||||
  if (index < 0)
 | 
			
		||||
@@ -92,5 +161,24 @@ int32_t HOT interpret_index(int32_t index, int32_t size) {
 | 
			
		||||
  return index;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AddressableLight::call_setup() {
 | 
			
		||||
  this->setup_internal_();
 | 
			
		||||
  this->setup();
 | 
			
		||||
 | 
			
		||||
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
 | 
			
		||||
  this->set_interval(5000, [this]() {
 | 
			
		||||
    const char *name = this->state_parent_ == nullptr ? "" : this->state_parent_->get_name().c_str();
 | 
			
		||||
    ESP_LOGVV(TAG, "Addressable Light '%s' (effect_active=%s next_show=%s)", name, YESNO(this->effect_active_),
 | 
			
		||||
              YESNO(this->next_show_));
 | 
			
		||||
    for (int i = 0; i < this->size(); i++) {
 | 
			
		||||
      auto color = this->get(i);
 | 
			
		||||
      ESP_LOGVV(TAG, "  [%2d] Color: R=%3u G=%3u B=%3u W=%3u", i, color.get_red_raw(), color.get_green_raw(),
 | 
			
		||||
                color.get_blue_raw(), color.get_white_raw());
 | 
			
		||||
    }
 | 
			
		||||
    ESP_LOGVV(TAG, "");
 | 
			
		||||
  });
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace light
 | 
			
		||||
}  // namespace esphome
 | 
			
		||||
 
 | 
			
		||||
@@ -335,13 +335,21 @@ class ESPColorView : public ESPColorSettable {
 | 
			
		||||
  void darken(uint8_t delta) override { this->set(this->get().darken(delta)); }
 | 
			
		||||
  ESPColor get() const { return ESPColor(this->get_red(), this->get_green(), this->get_blue(), this->get_white()); }
 | 
			
		||||
  uint8_t get_red() const { return this->color_correction_->color_uncorrect_red(*this->red_); }
 | 
			
		||||
  uint8_t get_red_raw() const { return *this->red_; }
 | 
			
		||||
  uint8_t get_green() const { return this->color_correction_->color_uncorrect_green(*this->green_); }
 | 
			
		||||
  uint8_t get_green_raw() const { return *this->green_; }
 | 
			
		||||
  uint8_t get_blue() const { return this->color_correction_->color_uncorrect_blue(*this->blue_); }
 | 
			
		||||
  uint8_t get_blue_raw() const { return *this->blue_; }
 | 
			
		||||
  uint8_t get_white() const {
 | 
			
		||||
    if (this->white_ == nullptr)
 | 
			
		||||
      return 0;
 | 
			
		||||
    return this->color_correction_->color_uncorrect_white(*this->white_);
 | 
			
		||||
  }
 | 
			
		||||
  uint8_t get_white_raw() const {
 | 
			
		||||
    if (this->white_ == nullptr)
 | 
			
		||||
      return 0;
 | 
			
		||||
    return *this->white_;
 | 
			
		||||
  }
 | 
			
		||||
  uint8_t get_effect_data() const {
 | 
			
		||||
    if (this->effect_data_ == nullptr)
 | 
			
		||||
      return 0;
 | 
			
		||||
@@ -364,23 +372,10 @@ class AddressableLight;
 | 
			
		||||
 | 
			
		||||
int32_t interpret_index(int32_t index, int32_t size);
 | 
			
		||||
 | 
			
		||||
class ESPRangeIterator;
 | 
			
		||||
 | 
			
		||||
class ESPRangeView : public ESPColorSettable {
 | 
			
		||||
 public:
 | 
			
		||||
  class Iterator {
 | 
			
		||||
   public:
 | 
			
		||||
    Iterator(ESPRangeView *range, int32_t i) : range_(range), i_(i) {}
 | 
			
		||||
    Iterator operator++() {
 | 
			
		||||
      this->i_++;
 | 
			
		||||
      return *this;
 | 
			
		||||
    }
 | 
			
		||||
    bool operator!=(const Iterator &other) const { return this->i_ != other.i_; }
 | 
			
		||||
    ESPColorView operator*() const;
 | 
			
		||||
 | 
			
		||||
   protected:
 | 
			
		||||
    ESPRangeView *range_;
 | 
			
		||||
    int32_t i_;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  ESPRangeView(AddressableLight *parent, int32_t begin, int32_t an_end) : parent_(parent), begin_(begin), end_(an_end) {
 | 
			
		||||
    if (this->end_ < this->begin_) {
 | 
			
		||||
      this->end_ = this->begin_;
 | 
			
		||||
@@ -388,8 +383,8 @@ class ESPRangeView : public ESPColorSettable {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ESPColorView operator[](int32_t index) const;
 | 
			
		||||
  Iterator begin() { return {this, this->begin_}; }
 | 
			
		||||
  Iterator end() { return {this, this->end_}; }
 | 
			
		||||
  ESPRangeIterator begin();
 | 
			
		||||
  ESPRangeIterator end();
 | 
			
		||||
 | 
			
		||||
  void set(const ESPColor &color) override;
 | 
			
		||||
  ESPRangeView &operator=(const ESPColor &rhs) {
 | 
			
		||||
@@ -404,78 +399,42 @@ class ESPRangeView : public ESPColorSettable {
 | 
			
		||||
    this->set_hsv(rhs);
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
  ESPRangeView &operator=(const ESPRangeView &rhs) {
 | 
			
		||||
    // If size doesn't match, error (todo warning)
 | 
			
		||||
    if (rhs.size() != this->size())
 | 
			
		||||
      return *this;
 | 
			
		||||
 | 
			
		||||
    if (this->parent_ != rhs.parent_) {
 | 
			
		||||
      for (int32_t i = 0; i < this->size(); i++)
 | 
			
		||||
        (*this)[i].set(rhs[i].get());
 | 
			
		||||
      return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // If both equal, already done
 | 
			
		||||
    if (rhs.begin_ == this->begin_)
 | 
			
		||||
      return *this;
 | 
			
		||||
 | 
			
		||||
    if (rhs.begin_ < this->begin_) {
 | 
			
		||||
      // Copy into rhs
 | 
			
		||||
      for (int32_t i = 0; i < this->size(); i++)
 | 
			
		||||
        rhs[i].set((*this)[i].get());
 | 
			
		||||
    } else {
 | 
			
		||||
      // Copy into this
 | 
			
		||||
      for (int32_t i = 0; i < this->size(); i++)
 | 
			
		||||
        (*this)[i].set(rhs[i].get());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
  void set_red(uint8_t red) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.set_red(red);
 | 
			
		||||
  }
 | 
			
		||||
  void set_green(uint8_t green) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.set_green(green);
 | 
			
		||||
  }
 | 
			
		||||
  void set_blue(uint8_t blue) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.set_blue(blue);
 | 
			
		||||
  }
 | 
			
		||||
  void set_white(uint8_t white) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.set_white(white);
 | 
			
		||||
  }
 | 
			
		||||
  void set_effect_data(uint8_t effect_data) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.set_effect_data(effect_data);
 | 
			
		||||
  }
 | 
			
		||||
  void fade_to_white(uint8_t amnt) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.fade_to_white(amnt);
 | 
			
		||||
  }
 | 
			
		||||
  void fade_to_black(uint8_t amnt) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.fade_to_white(amnt);
 | 
			
		||||
  }
 | 
			
		||||
  void lighten(uint8_t delta) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.lighten(delta);
 | 
			
		||||
  }
 | 
			
		||||
  void darken(uint8_t delta) override {
 | 
			
		||||
    for (auto c : *this)
 | 
			
		||||
      c.darken(delta);
 | 
			
		||||
  }
 | 
			
		||||
  ESPRangeView &operator=(const ESPRangeView &rhs);
 | 
			
		||||
  void set_red(uint8_t red) override;
 | 
			
		||||
  void set_green(uint8_t green) override;
 | 
			
		||||
  void set_blue(uint8_t blue) override;
 | 
			
		||||
  void set_white(uint8_t white) override;
 | 
			
		||||
  void set_effect_data(uint8_t effect_data) override;
 | 
			
		||||
  void fade_to_white(uint8_t amnt) override;
 | 
			
		||||
  void fade_to_black(uint8_t amnt) override;
 | 
			
		||||
  void lighten(uint8_t delta) override;
 | 
			
		||||
  void darken(uint8_t delta) override;
 | 
			
		||||
  int32_t size() const { return this->end_ - this->begin_; }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  friend ESPRangeIterator;
 | 
			
		||||
 | 
			
		||||
  AddressableLight *parent_;
 | 
			
		||||
  int32_t begin_;
 | 
			
		||||
  int32_t end_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class AddressableLight : public LightOutput {
 | 
			
		||||
class ESPRangeIterator {
 | 
			
		||||
 public:
 | 
			
		||||
  ESPRangeIterator(const ESPRangeView &range, int32_t i) : range_(range), i_(i) {}
 | 
			
		||||
  ESPRangeIterator operator++() {
 | 
			
		||||
    this->i_++;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
  bool operator!=(const ESPRangeIterator &other) const { return this->i_ != other.i_; }
 | 
			
		||||
  ESPColorView operator*() const;
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  ESPRangeView range_;
 | 
			
		||||
  int32_t i_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class AddressableLight : public LightOutput, public Component {
 | 
			
		||||
 public:
 | 
			
		||||
  virtual int32_t size() const = 0;
 | 
			
		||||
  ESPColorView operator[](int32_t index) const { return this->get_view_internal(interpret_index(index, this->size())); }
 | 
			
		||||
@@ -487,8 +446,8 @@ class AddressableLight : public LightOutput {
 | 
			
		||||
    return ESPRangeView(this, from, to);
 | 
			
		||||
  }
 | 
			
		||||
  ESPRangeView all() { return ESPRangeView(this, 0, this->size()); }
 | 
			
		||||
  ESPRangeView::Iterator begin() { return this->all().begin(); }
 | 
			
		||||
  ESPRangeView::Iterator end() { return this->all().end(); }
 | 
			
		||||
  ESPRangeIterator begin() { return this->all().begin(); }
 | 
			
		||||
  ESPRangeIterator end() { return this->all().end(); }
 | 
			
		||||
  void shift_left(int32_t amnt) {
 | 
			
		||||
    if (amnt < 0) {
 | 
			
		||||
      this->shift_right(-amnt);
 | 
			
		||||
@@ -530,13 +489,18 @@ class AddressableLight : public LightOutput {
 | 
			
		||||
    this->correction_.set_max_brightness(ESPColor(uint8_t(roundf(red * 255.0f)), uint8_t(roundf(green * 255.0f)),
 | 
			
		||||
                                                  uint8_t(roundf(blue * 255.0f)), uint8_t(roundf(white * 255.0f))));
 | 
			
		||||
  }
 | 
			
		||||
  void setup_state(LightState *state) override { this->correction_.calculate_gamma_table(state->get_gamma_correct()); }
 | 
			
		||||
  void setup_state(LightState *state) override {
 | 
			
		||||
    this->correction_.calculate_gamma_table(state->get_gamma_correct());
 | 
			
		||||
    this->state_parent_ = state;
 | 
			
		||||
  }
 | 
			
		||||
  void schedule_show() { this->next_show_ = true; }
 | 
			
		||||
 | 
			
		||||
#ifdef USE_POWER_SUPPLY
 | 
			
		||||
  void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  void call_setup() override;
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  bool should_show_() const { return this->effect_active_ || this->next_show_; }
 | 
			
		||||
  void mark_shown_() {
 | 
			
		||||
@@ -559,6 +523,7 @@ class AddressableLight : public LightOutput {
 | 
			
		||||
#ifdef USE_POWER_SUPPLY
 | 
			
		||||
  power_supply::PowerSupplyRequester power_;
 | 
			
		||||
#endif
 | 
			
		||||
  LightState *state_parent_{nullptr};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace light
 | 
			
		||||
 
 | 
			
		||||
@@ -113,7 +113,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
 | 
			
		||||
      it.shift_right(1);
 | 
			
		||||
    const AddressableColorWipeEffectColor color = this->colors_[this->at_color_];
 | 
			
		||||
    const ESPColor esp_color = ESPColor(color.r, color.g, color.b, color.w);
 | 
			
		||||
    if (!this->reverse_)
 | 
			
		||||
    if (this->reverse_)
 | 
			
		||||
      it[-1] = esp_color;
 | 
			
		||||
    else
 | 
			
		||||
      it[0] = esp_color;
 | 
			
		||||
@@ -308,14 +308,15 @@ class AddressableFlickerEffect : public AddressableLightEffect {
 | 
			
		||||
  explicit AddressableFlickerEffect(const std::string &name) : AddressableLightEffect(name) {}
 | 
			
		||||
  void apply(AddressableLight &it, const ESPColor ¤t_color) override {
 | 
			
		||||
    const uint32_t now = millis();
 | 
			
		||||
    const uint8_t delta_intensity = 255 - this->intensity_;
 | 
			
		||||
    const uint8_t intensity = this->intensity_;
 | 
			
		||||
    const uint8_t inv_intensity = 255 - intensity;
 | 
			
		||||
    if (now - this->last_update_ < this->update_interval_)
 | 
			
		||||
      return;
 | 
			
		||||
    this->last_update_ = now;
 | 
			
		||||
    fast_random_set_seed(random_uint32());
 | 
			
		||||
    for (auto var : it) {
 | 
			
		||||
      const uint8_t flicker = fast_random_8() % this->intensity_;
 | 
			
		||||
      var = (var.get() * delta_intensity) + (current_color * flicker);
 | 
			
		||||
      const uint8_t flicker = fast_random_8() % intensity;
 | 
			
		||||
      var = (var.get() * inv_intensity) + (current_color * flicker);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  void set_update_interval(uint32_t update_interval) { this->update_interval_ = update_interval; }
 | 
			
		||||
 
 | 
			
		||||
@@ -155,6 +155,6 @@ def light_addressable_set_to_code(config, action_id, template_arg, args):
 | 
			
		||||
                               automation.maybe_simple_id({
 | 
			
		||||
                                   cv.Required(CONF_ID): cv.use_id(LightState),
 | 
			
		||||
                               }))
 | 
			
		||||
def binary_sensor_is_on_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
def light_is_on_off_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    paren = yield cg.get_variable(config[CONF_ID])
 | 
			
		||||
    yield cg.new_Pvariable(condition_id, template_arg, paren)
 | 
			
		||||
 
 | 
			
		||||
@@ -129,7 +129,7 @@ class FlickerLightEffect : public LightEffect {
 | 
			
		||||
    LightColorValues out;
 | 
			
		||||
    const float alpha = this->alpha_;
 | 
			
		||||
    const float beta = 1.0f - alpha;
 | 
			
		||||
    out.set_state(remote.get_state());
 | 
			
		||||
    out.set_state(true);
 | 
			
		||||
    out.set_brightness(remote.get_brightness() * beta + current.get_brightness() * alpha +
 | 
			
		||||
                       (random_cubic_float() * this->intensity_));
 | 
			
		||||
    out.set_red(remote.get_red() * beta + current.get_red() * alpha + (random_cubic_float() * this->intensity_));
 | 
			
		||||
@@ -144,6 +144,7 @@ class FlickerLightEffect : public LightEffect {
 | 
			
		||||
    if (traits.get_supports_brightness())
 | 
			
		||||
      call.set_transition_length(0);
 | 
			
		||||
    call.from_light_color_values(out);
 | 
			
		||||
    call.set_state(true);
 | 
			
		||||
    call.perform();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ LightState = light_ns.class_('LightState', cg.Nameable, cg.Component)
 | 
			
		||||
# Fake class for addressable lights
 | 
			
		||||
AddressableLightState = light_ns.class_('LightState', LightState)
 | 
			
		||||
LightOutput = light_ns.class_('LightOutput')
 | 
			
		||||
AddressableLight = light_ns.class_('AddressableLight')
 | 
			
		||||
AddressableLight = light_ns.class_('AddressableLight', cg.Component)
 | 
			
		||||
AddressableLightRef = AddressableLight.operator('ref')
 | 
			
		||||
LightColorValues = light_ns.class_('LightColorValues')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,8 @@ MQTTClientComponent = mqtt_ns.class_('MQTTClientComponent', cg.Component)
 | 
			
		||||
MQTTPublishAction = mqtt_ns.class_('MQTTPublishAction', automation.Action)
 | 
			
		||||
MQTTPublishJsonAction = mqtt_ns.class_('MQTTPublishJsonAction', automation.Action)
 | 
			
		||||
MQTTMessageTrigger = mqtt_ns.class_('MQTTMessageTrigger',
 | 
			
		||||
                                    automation.Trigger.template(cg.std_string))
 | 
			
		||||
                                    automation.Trigger.template(cg.std_string),
 | 
			
		||||
                                    cg.Component)
 | 
			
		||||
MQTTJsonMessageTrigger = mqtt_ns.class_('MQTTJsonMessageTrigger',
 | 
			
		||||
                                        automation.Trigger.template(cg.JsonObjectConstRef))
 | 
			
		||||
MQTTComponent = mqtt_ns.class_('MQTTComponent', cg.Component)
 | 
			
		||||
@@ -104,7 +105,7 @@ CONFIG_SCHEMA = cv.All(cv.Schema({
 | 
			
		||||
    cv.Optional(CONF_PORT, default=1883): cv.port,
 | 
			
		||||
    cv.Optional(CONF_USERNAME, default=''): cv.string,
 | 
			
		||||
    cv.Optional(CONF_PASSWORD, default=''): cv.string,
 | 
			
		||||
    cv.Optional(CONF_CLIENT_ID, default=lambda: CORE.name): cv.string,
 | 
			
		||||
    cv.Optional(CONF_CLIENT_ID): cv.string,
 | 
			
		||||
    cv.Optional(CONF_DISCOVERY, default=True): cv.Any(cv.boolean, cv.one_of("CLEAN", upper=True)),
 | 
			
		||||
    cv.Optional(CONF_DISCOVERY_RETAIN, default=True): cv.boolean,
 | 
			
		||||
    cv.Optional(CONF_DISCOVERY_PREFIX, default="homeassistant"): cv.publish_topic,
 | 
			
		||||
@@ -161,7 +162,8 @@ def to_code(config):
 | 
			
		||||
    cg.add(var.set_broker_port(config[CONF_PORT]))
 | 
			
		||||
    cg.add(var.set_username(config[CONF_USERNAME]))
 | 
			
		||||
    cg.add(var.set_password(config[CONF_PASSWORD]))
 | 
			
		||||
    cg.add(var.set_client_id(config[CONF_CLIENT_ID]))
 | 
			
		||||
    if CONF_CLIENT_ID in config:
 | 
			
		||||
        cg.add(var.set_client_id(config[CONF_CLIENT_ID]))
 | 
			
		||||
 | 
			
		||||
    discovery = config[CONF_DISCOVERY]
 | 
			
		||||
    discovery_retain = config[CONF_DISCOVERY_RETAIN]
 | 
			
		||||
@@ -216,6 +218,7 @@ def to_code(config):
 | 
			
		||||
        cg.add(trig.set_qos(conf[CONF_QOS]))
 | 
			
		||||
        if CONF_PAYLOAD in conf:
 | 
			
		||||
            cg.add(trig.set_payload(conf[CONF_PAYLOAD]))
 | 
			
		||||
        yield cg.register_component(trig, conf)
 | 
			
		||||
        yield automation.build_automation(trig, [(cg.std_string, 'x')], conf)
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_JSON_MESSAGE, []):
 | 
			
		||||
 
 | 
			
		||||
@@ -19,15 +19,19 @@ void MQTTBinarySensorComponent::dump_config() {
 | 
			
		||||
  LOG_MQTT_COMPONENT(true, false)
 | 
			
		||||
}
 | 
			
		||||
MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor *binary_sensor)
 | 
			
		||||
    : MQTTComponent(), binary_sensor_(binary_sensor) {}
 | 
			
		||||
    : MQTTComponent(), binary_sensor_(binary_sensor) {
 | 
			
		||||
  if (this->binary_sensor_->is_status_binary_sensor()) {
 | 
			
		||||
    this->set_custom_state_topic(mqtt::global_mqtt_client->get_availability().topic);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
std::string MQTTBinarySensorComponent::friendly_name() const { return this->binary_sensor_->get_name(); }
 | 
			
		||||
 | 
			
		||||
void MQTTBinarySensorComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config) {
 | 
			
		||||
  if (!this->binary_sensor_->get_device_class().empty())
 | 
			
		||||
    root["device_class"] = this->binary_sensor_->get_device_class();
 | 
			
		||||
  if (this->is_status_)
 | 
			
		||||
  if (this->binary_sensor_->is_status_binary_sensor())
 | 
			
		||||
    root["payload_on"] = mqtt::global_mqtt_client->get_availability().payload_available;
 | 
			
		||||
  if (this->is_status_)
 | 
			
		||||
  if (this->binary_sensor_->is_status_binary_sensor())
 | 
			
		||||
    root["payload_off"] = mqtt::global_mqtt_client->get_availability().payload_not_available;
 | 
			
		||||
  config.command_topic = false;
 | 
			
		||||
}
 | 
			
		||||
@@ -40,13 +44,12 @@ bool MQTTBinarySensorComponent::send_initial_state() {
 | 
			
		||||
}
 | 
			
		||||
bool MQTTBinarySensorComponent::is_internal() { return this->binary_sensor_->is_internal(); }
 | 
			
		||||
bool MQTTBinarySensorComponent::publish_state(bool state) {
 | 
			
		||||
  if (this->is_status_)
 | 
			
		||||
  if (this->binary_sensor_->is_status_binary_sensor())
 | 
			
		||||
    return true;
 | 
			
		||||
 | 
			
		||||
  const char *state_s = state ? "ON" : "OFF";
 | 
			
		||||
  return this->publish(this->get_state_topic_(), state_s);
 | 
			
		||||
}
 | 
			
		||||
void MQTTBinarySensorComponent::set_is_status(bool status) { this->is_status_ = status; }
 | 
			
		||||
 | 
			
		||||
}  // namespace mqtt
 | 
			
		||||
}  // namespace esphome
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,6 @@ class MQTTBinarySensorComponent : public mqtt::MQTTComponent {
 | 
			
		||||
  std::string component_type() const override;
 | 
			
		||||
 | 
			
		||||
  binary_sensor::BinarySensor *binary_sensor_;
 | 
			
		||||
  bool is_status_{false};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace mqtt
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,10 @@ namespace mqtt {
 | 
			
		||||
 | 
			
		||||
static const char *TAG = "mqtt";
 | 
			
		||||
 | 
			
		||||
MQTTClientComponent::MQTTClientComponent() { global_mqtt_client = this; }
 | 
			
		||||
MQTTClientComponent::MQTTClientComponent() {
 | 
			
		||||
  global_mqtt_client = this;
 | 
			
		||||
  this->credentials_.client_id = App.get_name() + "-" + get_mac_address();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Connection
 | 
			
		||||
void MQTTClientComponent::setup() {
 | 
			
		||||
@@ -357,18 +360,19 @@ bool MQTTClientComponent::publish(const std::string &topic, const char *payload,
 | 
			
		||||
  }
 | 
			
		||||
  bool logging_topic = topic == this->log_message_.topic;
 | 
			
		||||
  uint16_t ret = this->mqtt_client_.publish(topic.c_str(), qos, retain, payload, payload_length);
 | 
			
		||||
  yield();
 | 
			
		||||
  delay(0);
 | 
			
		||||
  if (ret == 0 && !logging_topic && this->is_connected()) {
 | 
			
		||||
    delay(5);
 | 
			
		||||
    delay(0);
 | 
			
		||||
    ret = this->mqtt_client_.publish(topic.c_str(), qos, retain, payload, payload_length);
 | 
			
		||||
    yield();
 | 
			
		||||
    delay(0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!logging_topic) {
 | 
			
		||||
    if (ret != 0) {
 | 
			
		||||
      ESP_LOGV(TAG, "Publish(topic='%s' payload='%s' retain=%d)", topic.c_str(), payload, retain);
 | 
			
		||||
    } else {
 | 
			
		||||
      ESP_LOGW(TAG, "Publish failed for topic='%s' will retry later..", topic.c_str());
 | 
			
		||||
      ESP_LOGV(TAG, "Publish failed for topic='%s' (len=%u). will retry later..", topic.c_str(),
 | 
			
		||||
               payload_length);  // NOLINT
 | 
			
		||||
      this->status_momentary_warning("publish", 1000);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
#include "esphome/core/helpers.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace mqtt {
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_METHOD, CONF_NUM_L
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
 | 
			
		||||
neopixelbus_ns = cg.esphome_ns.namespace('neopixelbus')
 | 
			
		||||
NeoPixelBusLightOutputBase = neopixelbus_ns.class_('NeoPixelBusLightOutputBase', cg.Component,
 | 
			
		||||
NeoPixelBusLightOutputBase = neopixelbus_ns.class_('NeoPixelBusLightOutputBase',
 | 
			
		||||
                                                   light.AddressableLight)
 | 
			
		||||
NeoPixelRGBLightOutput = neopixelbus_ns.class_('NeoPixelRGBLightOutput', NeoPixelBusLightOutputBase)
 | 
			
		||||
NeoPixelRGBWLightOutput = neopixelbus_ns.class_('NeoPixelRGBWLightOutput',
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,7 @@ enum class ESPNeoPixelOrder {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template<typename T_METHOD, typename T_COLOR_FEATURE>
 | 
			
		||||
class NeoPixelBusLightOutputBase : public Component, public light::AddressableLight {
 | 
			
		||||
class NeoPixelBusLightOutputBase : public light::AddressableLight {
 | 
			
		||||
 public:
 | 
			
		||||
  NeoPixelBus<T_COLOR_FEATURE, T_METHOD> *get_controller() const { return this->controller_; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -33,4 +33,5 @@ def to_code(config):
 | 
			
		||||
                                           conf[CONF_TO] - conf[CONF_FROM] + 1))
 | 
			
		||||
 | 
			
		||||
    var = cg.new_Pvariable(config[CONF_OUTPUT_ID], segments)
 | 
			
		||||
    yield cg.register_component(var, config)
 | 
			
		||||
    yield light.register_light(var, config)
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ class AddressableSegment {
 | 
			
		||||
  int32_t dst_offset_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class PartitionLightOutput : public light::AddressableLight, public Component {
 | 
			
		||||
class PartitionLightOutput : public light::AddressableLight {
 | 
			
		||||
 public:
 | 
			
		||||
  explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(segments) {
 | 
			
		||||
    int32_t off = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -83,14 +83,20 @@ def register_dumper(name, type):
 | 
			
		||||
    return decorator
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def register_action(name, type_, schema):
 | 
			
		||||
    validator = templatize(schema).extend({
 | 
			
		||||
        cv.GenerateID(CONF_TRANSMITTER_ID): cv.use_id(RemoteTransmitterBase),
 | 
			
		||||
        cv.Optional(CONF_REPEAT): cv.Schema({
 | 
			
		||||
def validate_repeat(value):
 | 
			
		||||
    if isinstance(value, dict):
 | 
			
		||||
        return cv.Schema({
 | 
			
		||||
            cv.Required(CONF_TIMES): cv.templatable(cv.positive_int),
 | 
			
		||||
            cv.Optional(CONF_WAIT_TIME, default='10ms'):
 | 
			
		||||
                cv.templatable(cv.positive_time_period_milliseconds),
 | 
			
		||||
        }),
 | 
			
		||||
        })(value)
 | 
			
		||||
    return validate_repeat({CONF_TIMES: value})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def register_action(name, type_, schema):
 | 
			
		||||
    validator = templatize(schema).extend({
 | 
			
		||||
        cv.GenerateID(CONF_TRANSMITTER_ID): cv.use_id(RemoteTransmitterBase),
 | 
			
		||||
        cv.Optional(CONF_REPEAT): validate_repeat,
 | 
			
		||||
    })
 | 
			
		||||
    registerer = automation.register_action('remote_transmitter.transmit_{}'.format(name),
 | 
			
		||||
                                            type_, validator)
 | 
			
		||||
 
 | 
			
		||||
@@ -293,7 +293,7 @@ template<typename T, typename D> class RemoteReceiverBinarySensor : public Remot
 | 
			
		||||
  bool matches(RemoteReceiveData src) override {
 | 
			
		||||
    auto proto = T();
 | 
			
		||||
    auto res = proto.decode(src);
 | 
			
		||||
    return res.has_value();
 | 
			
		||||
    return res.has_value() && *res == this->data_;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 public:
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ optional<SonyData> SonyProtocol::decode(RemoteReceiveData src) {
 | 
			
		||||
      .nbits = 0,
 | 
			
		||||
  };
 | 
			
		||||
  if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
 | 
			
		||||
    return out;
 | 
			
		||||
    return {};
 | 
			
		||||
 | 
			
		||||
  for (; out.nbits < 20; out.nbits++) {
 | 
			
		||||
    uint32_t bit;
 | 
			
		||||
 
 | 
			
		||||
@@ -101,15 +101,15 @@ void RotaryEncoderSensor::setup() {
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "Setting up Rotary Encoder '%s'...", this->name_.c_str());
 | 
			
		||||
  this->pin_a_->setup();
 | 
			
		||||
  this->store_.pin_a = this->pin_a_->to_isr();
 | 
			
		||||
  this->pin_a_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
 | 
			
		||||
 | 
			
		||||
  this->pin_b_->setup();
 | 
			
		||||
  this->store_.pin_b = this->pin_b_->to_isr();
 | 
			
		||||
  this->pin_b_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
 | 
			
		||||
 | 
			
		||||
  if (this->pin_i_ != nullptr) {
 | 
			
		||||
    this->pin_i_->setup();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  this->pin_a_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
 | 
			
		||||
  this->pin_b_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
 | 
			
		||||
}
 | 
			
		||||
void RotaryEncoderSensor::dump_config() {
 | 
			
		||||
  LOG_SENSOR("", "Rotary Encoder", this);
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@ CONFIG_SCHEMA = cv.All(sensor.sensor_schema(UNIT_STEPS, ICON_ROTATE_RIGHT, 0).ex
 | 
			
		||||
                                    pins.validate_has_interrupt),
 | 
			
		||||
    cv.Required(CONF_PIN_B): cv.All(pins.internal_gpio_input_pin_schema,
 | 
			
		||||
                                    pins.validate_has_interrupt),
 | 
			
		||||
    cv.Optional(CONF_PIN_RESET): pins.internal_gpio_input_pin_schema,
 | 
			
		||||
    cv.Optional(CONF_PIN_RESET): pins.internal_gpio_output_pin_schema,
 | 
			
		||||
    cv.Optional(CONF_RESOLUTION, default=1): cv.enum(RESOLUTIONS, int=True),
 | 
			
		||||
    cv.Optional(CONF_MIN_VALUE): cv.int_,
 | 
			
		||||
    cv.Optional(CONF_MAX_VALUE): cv.int_,
 | 
			
		||||
@@ -50,7 +50,7 @@ def to_code(config):
 | 
			
		||||
    pin_a = yield cg.gpio_pin_expression(config[CONF_PIN_A])
 | 
			
		||||
    cg.add(var.set_pin_a(pin_a))
 | 
			
		||||
    pin_b = yield cg.gpio_pin_expression(config[CONF_PIN_B])
 | 
			
		||||
    cg.add(var.set_pin_a(pin_b))
 | 
			
		||||
    cg.add(var.set_pin_b(pin_b))
 | 
			
		||||
 | 
			
		||||
    if CONF_PIN_RESET in config:
 | 
			
		||||
        pin_i = yield cg.gpio_pin_expression(config[CONF_PIN_RESET])
 | 
			
		||||
 
 | 
			
		||||
@@ -16,8 +16,13 @@ CONFIG_SCHEMA = automation.validate_automation({
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    # Register all variables first, so that scripts can use other scripts
 | 
			
		||||
    triggers = []
 | 
			
		||||
    for conf in config:
 | 
			
		||||
        trigger = cg.new_Pvariable(conf[CONF_ID])
 | 
			
		||||
        triggers.append((trigger, conf))
 | 
			
		||||
 | 
			
		||||
    for trigger, conf in triggers:
 | 
			
		||||
        yield automation.build_automation(trigger, [], conf)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,10 @@ CONF_ELEVATION = 'elevation'
 | 
			
		||||
CONF_ON_SUNRISE = 'on_sunrise'
 | 
			
		||||
CONF_ON_SUNSET = 'on_sunset'
 | 
			
		||||
 | 
			
		||||
# Default sun elevation is a bit below horizon because sunset
 | 
			
		||||
# means time when the entire sun disk is below the horizon
 | 
			
		||||
DEFAULT_ELEVATION = -0.883
 | 
			
		||||
 | 
			
		||||
ELEVATION_MAP = {
 | 
			
		||||
    'sunrise': 0.0,
 | 
			
		||||
    'sunset': 0.0,
 | 
			
		||||
@@ -44,11 +48,11 @@ CONFIG_SCHEMA = cv.Schema({
 | 
			
		||||
 | 
			
		||||
    cv.Optional(CONF_ON_SUNRISE): automation.validate_automation({
 | 
			
		||||
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SunTrigger),
 | 
			
		||||
        cv.Optional(CONF_ELEVATION, default=0.0): elevation,
 | 
			
		||||
        cv.Optional(CONF_ELEVATION, default=DEFAULT_ELEVATION): elevation,
 | 
			
		||||
    }),
 | 
			
		||||
    cv.Optional(CONF_ON_SUNSET): automation.validate_automation({
 | 
			
		||||
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SunTrigger),
 | 
			
		||||
        cv.Optional(CONF_ELEVATION, default=0.0): elevation,
 | 
			
		||||
        cv.Optional(CONF_ELEVATION, default=DEFAULT_ELEVATION): elevation,
 | 
			
		||||
    }),
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
@@ -79,7 +83,7 @@ def to_code(config):
 | 
			
		||||
 | 
			
		||||
@automation.register_condition('sun.is_above_horizon', SunCondition, cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.use_id(Sun),
 | 
			
		||||
    cv.Optional(CONF_ELEVATION, default=0): cv.templatable(elevation),
 | 
			
		||||
    cv.Optional(CONF_ELEVATION, default=DEFAULT_ELEVATION): cv.templatable(elevation),
 | 
			
		||||
}))
 | 
			
		||||
def sun_above_horizon_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    var = cg.new_Pvariable(condition_id, template_arg)
 | 
			
		||||
@@ -92,7 +96,7 @@ def sun_above_horizon_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
 | 
			
		||||
@automation.register_condition('sun.is_below_horizon', SunCondition, cv.Schema({
 | 
			
		||||
    cv.GenerateID(): cv.use_id(Sun),
 | 
			
		||||
    cv.Optional(CONF_ELEVATION, default=0): cv.templatable(elevation),
 | 
			
		||||
    cv.Optional(CONF_ELEVATION, default=DEFAULT_ELEVATION): cv.templatable(elevation),
 | 
			
		||||
}))
 | 
			
		||||
def sun_below_horizon_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    var = cg.new_Pvariable(condition_id, template_arg)
 | 
			
		||||
 
 | 
			
		||||
@@ -103,7 +103,7 @@ class SunTrigger : public Trigger<>, public PollingComponent, public Parented<Su
 | 
			
		||||
      crossed = this->last_elevation_ >= this->elevation_ && this->elevation_ > current;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (crossed) {
 | 
			
		||||
    if (crossed && !isnan(this->last_elevation_)) {
 | 
			
		||||
      this->trigger();
 | 
			
		||||
    }
 | 
			
		||||
    this->last_elevation_ = current;
 | 
			
		||||
@@ -111,7 +111,7 @@ class SunTrigger : public Trigger<>, public PollingComponent, public Parented<Su
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  bool sunrise_;
 | 
			
		||||
  double last_elevation_;
 | 
			
		||||
  double last_elevation_{NAN};
 | 
			
		||||
  double elevation_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@ import esphome.config_validation as cv
 | 
			
		||||
import esphome.codegen as cg
 | 
			
		||||
from esphome.const import CONF_ICON, ICON_WEATHER_SUNSET_DOWN, ICON_WEATHER_SUNSET_UP, CONF_TYPE, \
 | 
			
		||||
    CONF_ID, CONF_FORMAT
 | 
			
		||||
from .. import sun_ns, CONF_SUN_ID, Sun, CONF_ELEVATION, elevation
 | 
			
		||||
from .. import sun_ns, CONF_SUN_ID, Sun, CONF_ELEVATION, elevation, DEFAULT_ELEVATION
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ['sun']
 | 
			
		||||
 | 
			
		||||
@@ -28,7 +28,7 @@ CONFIG_SCHEMA = cv.All(text_sensor.TEXT_SENSOR_SCHEMA.extend({
 | 
			
		||||
    cv.GenerateID(): cv.declare_id(SunTextSensor),
 | 
			
		||||
    cv.GenerateID(CONF_SUN_ID): cv.use_id(Sun),
 | 
			
		||||
    cv.Required(CONF_TYPE): cv.one_of(*SUN_TYPES, lower=True),
 | 
			
		||||
    cv.Optional(CONF_ELEVATION, default=0): elevation,
 | 
			
		||||
    cv.Optional(CONF_ELEVATION, default=DEFAULT_ELEVATION): elevation,
 | 
			
		||||
    cv.Optional(CONF_FORMAT, default='%X'): cv.string_strict,
 | 
			
		||||
}).extend(cv.polling_component_schema('60s')), validate_optional_icon)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -74,19 +74,12 @@ void TemplateCover::control(const CoverCall &call) {
 | 
			
		||||
    this->stop_prev_trigger_();
 | 
			
		||||
    this->stop_trigger_->trigger();
 | 
			
		||||
    this->prev_command_trigger_ = this->stop_trigger_;
 | 
			
		||||
    this->current_operation = COVER_OPERATION_IDLE;
 | 
			
		||||
    this->publish_state();
 | 
			
		||||
  }
 | 
			
		||||
  if (call.get_position().has_value()) {
 | 
			
		||||
    auto pos = *call.get_position();
 | 
			
		||||
    this->stop_prev_trigger_();
 | 
			
		||||
 | 
			
		||||
    if (pos < this->position) {
 | 
			
		||||
      this->current_operation = COVER_OPERATION_CLOSING;
 | 
			
		||||
    } else if (pos > this->position) {
 | 
			
		||||
      this->current_operation = COVER_OPERATION_OPENING;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (pos == COVER_OPEN) {
 | 
			
		||||
      this->open_trigger_->trigger();
 | 
			
		||||
      this->prev_command_trigger_ = this->open_trigger_;
 | 
			
		||||
 
 | 
			
		||||
@@ -70,6 +70,14 @@ def convert_tz(pytz_obj):
 | 
			
		||||
    transition_times = tz._utc_transition_times
 | 
			
		||||
    transition_info = tz._transition_info
 | 
			
		||||
    idx = max(0, bisect.bisect_right(transition_times, now))
 | 
			
		||||
    if idx >= len(transition_times):
 | 
			
		||||
        tzname = tz.tzname(now)
 | 
			
		||||
        utcoffset = tz.utcoffset(now)
 | 
			
		||||
        _LOGGER.info("Detected timezone '%s' with UTC offset %s",
 | 
			
		||||
                     tzname, _tz_timedelta(utcoffset))
 | 
			
		||||
        tzbase = '{}{}'.format(tzname, _tz_timedelta(-1 * utcoffset))
 | 
			
		||||
        return tzbase
 | 
			
		||||
 | 
			
		||||
    idx1, idx2 = idx, idx + 1
 | 
			
		||||
    dstoffset1 = transition_info[idx1][1]
 | 
			
		||||
    if dstoffset1 == datetime.timedelta(seconds=0):
 | 
			
		||||
@@ -244,10 +252,12 @@ def validate_tz(value):
 | 
			
		||||
    value = cv.string_strict(value)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        return convert_tz(pytz.timezone(value))
 | 
			
		||||
    except Exception:  # pylint: disable=broad-except
 | 
			
		||||
        pytz_obj = pytz.timezone(value)
 | 
			
		||||
    except pytz.UnknownTimeZoneError:  # pylint: disable=broad-except
 | 
			
		||||
        return value
 | 
			
		||||
 | 
			
		||||
    return convert_tz(pytz_obj)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TIME_SCHEMA = cv.Schema({
 | 
			
		||||
    cv.Optional(CONF_TIMEZONE, default=detect_tz): validate_tz,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
#include "version_text_sensor.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace version {
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ MODELS = {
 | 
			
		||||
    '2.90in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN),
 | 
			
		||||
    '2.70in': ('b', WaveshareEPaper2P7In),
 | 
			
		||||
    '4.20in': ('b', WaveshareEPaper4P2In),
 | 
			
		||||
    '7.50in': ('b', WaveshareEPaperTypeBModel),
 | 
			
		||||
    '7.50in': ('b', WaveshareEPaper7P5In),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -246,7 +246,11 @@ void print_signal_bars(int8_t rssi, char *buf) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WiFiComponent::print_connect_params_() {
 | 
			
		||||
  uint8_t *bssid = WiFi.BSSID();
 | 
			
		||||
  uint8_t bssid[6] = {};
 | 
			
		||||
  uint8_t *raw_bssid = WiFi.BSSID();
 | 
			
		||||
  if (raw_bssid != nullptr)
 | 
			
		||||
    memcpy(bssid, raw_bssid, sizeof(bssid));
 | 
			
		||||
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  SSID: " LOG_SECRET("'%s'"), WiFi.SSID().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  IP Address: %s", WiFi.localIP().toString().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  BSSID: " LOG_SECRET("%02X:%02X:%02X:%02X:%02X:%02X"), bssid[0], bssid[1], bssid[2], bssid[3],
 | 
			
		||||
@@ -421,6 +425,7 @@ void WiFiComponent::check_connecting_finished() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WiFiComponent::retry_connect() {
 | 
			
		||||
  delay(10);
 | 
			
		||||
  if (this->num_retried_ > 5 || this->error_from_callback_) {
 | 
			
		||||
    // If retry failed for more than 5 times, let's restart STA
 | 
			
		||||
    ESP_LOGW(TAG, "Restarting WiFi adapter...");
 | 
			
		||||
 
 | 
			
		||||
@@ -330,7 +330,6 @@ const char *get_disconnect_reason_str(uint8_t reason) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WiFiComponent::wifi_event_callback(System_Event_t *event) {
 | 
			
		||||
#ifdef ESPHOME_LOG_HAS_VERBOSE
 | 
			
		||||
  // TODO: this callback is called while in cont context, so delay will fail
 | 
			
		||||
  // We need to defer the log messages until we're out of this context
 | 
			
		||||
  // only affects verbose log level
 | 
			
		||||
@@ -351,7 +350,7 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
 | 
			
		||||
      char buf[33];
 | 
			
		||||
      memcpy(buf, it.ssid, it.ssid_len);
 | 
			
		||||
      buf[it.ssid_len] = '\0';
 | 
			
		||||
      ESP_LOGV(TAG, "Event: Disconnected ssid='%s' bssid=%s reason='%s'", buf, format_mac_addr(it.bssid).c_str(),
 | 
			
		||||
      ESP_LOGW(TAG, "Event: Disconnected ssid='%s' bssid=%s reason='%s'", buf, format_mac_addr(it.bssid).c_str(),
 | 
			
		||||
               get_disconnect_reason_str(it.reason));
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
@@ -403,7 +402,6 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
 | 
			
		||||
    default:
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  if (event->event == EVENT_STAMODE_DISCONNECTED) {
 | 
			
		||||
    global_wifi_component->error_from_callback_ = true;
 | 
			
		||||
@@ -476,6 +474,7 @@ void WiFiComponent::wifi_scan_done_callback_(void *arg, STATUS status) {
 | 
			
		||||
 | 
			
		||||
  if (status != OK) {
 | 
			
		||||
    ESP_LOGV(TAG, "Scan failed! %d", status);
 | 
			
		||||
    this->retry_connect();
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  auto *head = reinterpret_cast<bss_info *>(arg);
 | 
			
		||||
 
 | 
			
		||||
@@ -115,7 +115,7 @@ bool XiaomiListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
 | 
			
		||||
 | 
			
		||||
  const char *name = res->type == XiaomiParseResult::TYPE_MIFLORA ? "Mi Flora" : "Mi Jia";
 | 
			
		||||
 | 
			
		||||
  ESP_LOGD(TAG, "Got Xiaomi %s:", name);
 | 
			
		||||
  ESP_LOGD(TAG, "Got Xiaomi %s (%s):", name, device.address_str().c_str());
 | 
			
		||||
 | 
			
		||||
  if (res->temperature.has_value()) {
 | 
			
		||||
    ESP_LOGD(TAG, "  Temperature: %.1f°C", *res->temperature);
 | 
			
		||||
 
 | 
			
		||||
@@ -393,6 +393,16 @@ def validate_config(config):
 | 
			
		||||
            result.add_error(err)
 | 
			
		||||
            return result
 | 
			
		||||
 | 
			
		||||
    if 'esphomeyaml' in config:
 | 
			
		||||
        _LOGGER.warning("The esphomeyaml section has been renamed to esphome in 1.11.0. "
 | 
			
		||||
                        "Please replace 'esphomeyaml:' in your configuration with 'esphome:'.")
 | 
			
		||||
        config[CONF_ESPHOME] = config.pop('esphomeyaml')
 | 
			
		||||
 | 
			
		||||
    if CONF_ESPHOME not in config:
 | 
			
		||||
        result.add_str_error("'esphome' section missing from configuration. Please make sure "
 | 
			
		||||
                             "your configuration has an 'esphome:' line in it.", [])
 | 
			
		||||
        return result
 | 
			
		||||
 | 
			
		||||
    # 2. Load partial core config
 | 
			
		||||
    result[CONF_ESPHOME] = config[CONF_ESPHOME]
 | 
			
		||||
    result.add_output_path([CONF_ESPHOME], CONF_ESPHOME)
 | 
			
		||||
 
 | 
			
		||||
@@ -1175,7 +1175,6 @@ def validate_registry_entry(name, registry):
 | 
			
		||||
        if not isinstance(value, dict):
 | 
			
		||||
            raise Invalid(u"{} must consist of key-value mapping! Got {}"
 | 
			
		||||
                          u"".format(name.title(), value))
 | 
			
		||||
        value = base_schema(value)
 | 
			
		||||
        key = next((x for x in value if x not in ignore_keys), None)
 | 
			
		||||
        if key is None:
 | 
			
		||||
            raise Invalid(u"Key missing from {}! Got {}".format(name, value))
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
 | 
			
		||||
MAJOR_VERSION = 1
 | 
			
		||||
MINOR_VERSION = 13
 | 
			
		||||
PATCH_VERSION = '0b7'
 | 
			
		||||
PATCH_VERSION = '5'
 | 
			
		||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
 | 
			
		||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
 | 
			
		||||
#ifdef USE_STATUS_LED
 | 
			
		||||
#include "esphome/components/status_led/status_led.h"
 | 
			
		||||
@@ -57,14 +58,7 @@ void Application::setup() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ESP_LOGI(TAG, "setup() finished successfully!");
 | 
			
		||||
  this->dump_config();
 | 
			
		||||
}
 | 
			
		||||
void Application::dump_config() {
 | 
			
		||||
  ESP_LOGI(TAG, "esphome version " ESPHOME_VERSION " compiled on %s", this->compilation_time_.c_str());
 | 
			
		||||
 | 
			
		||||
  for (auto component : this->components_) {
 | 
			
		||||
    component->dump_config();
 | 
			
		||||
  }
 | 
			
		||||
  this->schedule_dump_config();
 | 
			
		||||
}
 | 
			
		||||
void Application::loop() {
 | 
			
		||||
  uint32_t new_app_state = 0;
 | 
			
		||||
@@ -97,9 +91,13 @@ void Application::loop() {
 | 
			
		||||
  }
 | 
			
		||||
  this->last_loop_ = now;
 | 
			
		||||
 | 
			
		||||
  if (this->dump_config_scheduled_) {
 | 
			
		||||
    this->dump_config();
 | 
			
		||||
    this->dump_config_scheduled_ = false;
 | 
			
		||||
  if (this->dump_config_at_ >= 0 && this->dump_config_at_ < this->components_.size()) {
 | 
			
		||||
    if (this->dump_config_at_ == 0) {
 | 
			
		||||
      ESP_LOGI(TAG, "esphome version " ESPHOME_VERSION " compiled on %s", this->compilation_time_.c_str());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this->components_[this->dump_config_at_]->dump_config();
 | 
			
		||||
    this->dump_config_at_++;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -109,8 +109,7 @@ class Application {
 | 
			
		||||
   */
 | 
			
		||||
  void set_loop_interval(uint32_t loop_interval) { this->loop_interval_ = loop_interval; }
 | 
			
		||||
 | 
			
		||||
  void dump_config();
 | 
			
		||||
  void schedule_dump_config() { this->dump_config_scheduled_ = true; }
 | 
			
		||||
  void schedule_dump_config() { this->dump_config_at_ = 0; }
 | 
			
		||||
 | 
			
		||||
  void feed_wdt();
 | 
			
		||||
 | 
			
		||||
@@ -234,7 +233,7 @@ class Application {
 | 
			
		||||
  std::string compilation_time_;
 | 
			
		||||
  uint32_t last_loop_{0};
 | 
			
		||||
  uint32_t loop_interval_{16};
 | 
			
		||||
  bool dump_config_scheduled_{false};
 | 
			
		||||
  int dump_config_at_{-1};
 | 
			
		||||
  uint32_t app_state_{0};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ template<typename... Ts> class ForCondition : public Condition<Ts...>, public Co
 | 
			
		||||
  bool check(Ts... x) override {
 | 
			
		||||
    if (!this->check_internal())
 | 
			
		||||
      return false;
 | 
			
		||||
    return millis() - this->last_inactive_ < this->time_.value(x...);
 | 
			
		||||
    return millis() - this->last_inactive_ >= this->time_.value(x...);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,6 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
// This file is auto-generated! Do not edit!
 | 
			
		||||
 | 
			
		||||
#define ESPHOME_VERSION "dev"
 | 
			
		||||
 | 
			
		||||
#define USE_API
 | 
			
		||||
#define USE_LOGGER
 | 
			
		||||
#define USE_BINARY_SENSOR
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
#include "esphome/core/util.h"
 | 
			
		||||
#include "esphome/core/defines.h"
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
 | 
			
		||||
#ifdef USE_WIFI
 | 
			
		||||
#include "esphome/components/wifi/wifi_component.h"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								esphome/core/version.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								esphome/core/version.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
// This file is auto-generated! Do not edit!
 | 
			
		||||
#define ESPHOME_VERSION "dev"
 | 
			
		||||
@@ -10,7 +10,7 @@ from esphome.const import ARDUINO_VERSION_ESP32_DEV, ARDUINO_VERSION_ESP8266_DEV
 | 
			
		||||
    CONF_ESPHOME, CONF_INCLUDES, CONF_LIBRARIES, \
 | 
			
		||||
    CONF_NAME, CONF_ON_BOOT, CONF_ON_LOOP, CONF_ON_SHUTDOWN, CONF_PLATFORM, \
 | 
			
		||||
    CONF_PLATFORMIO_OPTIONS, CONF_PRIORITY, CONF_TRIGGER_ID, \
 | 
			
		||||
    CONF_ESP8266_RESTORE_FROM_FLASH, __version__, ARDUINO_VERSION_ESP8266_2_3_0, \
 | 
			
		||||
    CONF_ESP8266_RESTORE_FROM_FLASH, ARDUINO_VERSION_ESP8266_2_3_0, \
 | 
			
		||||
    ARDUINO_VERSION_ESP8266_2_5_0, ARDUINO_VERSION_ESP8266_2_5_1, ARDUINO_VERSION_ESP8266_2_5_2
 | 
			
		||||
from esphome.core import CORE, coroutine_with_priority
 | 
			
		||||
from esphome.helpers import copy_file_if_changed, walk_files
 | 
			
		||||
@@ -38,7 +38,7 @@ def validate_board(value):
 | 
			
		||||
 | 
			
		||||
    if value not in board_pins:
 | 
			
		||||
        raise cv.Invalid(u"Could not find board '{}'. Valid boards are {}".format(
 | 
			
		||||
            value, u', '.join(pins.ESP8266_BOARD_PINS.keys())))
 | 
			
		||||
            value, u', '.join(sorted(board_pins.keys()))))
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -201,7 +201,6 @@ def add_includes(includes):
 | 
			
		||||
@coroutine_with_priority(100.0)
 | 
			
		||||
def to_code(config):
 | 
			
		||||
    cg.add_global(cg.global_ns.namespace('esphome').using)
 | 
			
		||||
    cg.add_define('ESPHOME_VERSION', __version__)
 | 
			
		||||
    cg.add(cg.App.pre_setup(config[CONF_NAME], cg.RawExpression('__DATE__ ", " __TIME__')))
 | 
			
		||||
 | 
			
		||||
    for conf in config.get(CONF_ON_BOOT, []):
 | 
			
		||||
 
 | 
			
		||||
@@ -169,7 +169,7 @@ def websocket_class(cls):
 | 
			
		||||
    if not hasattr(cls, '_message_handlers'):
 | 
			
		||||
        cls._message_handlers = {}
 | 
			
		||||
 | 
			
		||||
    for _, method in cls.__dict__.iteritems():
 | 
			
		||||
    for _, method in cls.__dict__.items():
 | 
			
		||||
        if hasattr(method, "_message_handler"):
 | 
			
		||||
            cls._message_handlers[method._message_handler] = method
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,12 +5,13 @@
 | 
			
		||||
document.addEventListener('DOMContentLoaded', () => {
 | 
			
		||||
  M.AutoInit(document.body);
 | 
			
		||||
});
 | 
			
		||||
let wsProtocol = "ws:";
 | 
			
		||||
if (window.location.protocol === "https:") {
 | 
			
		||||
  wsProtocol = 'wss:';
 | 
			
		||||
const loc = window.location;
 | 
			
		||||
const wsLoc = new URL("./",`${loc.protocol}//${loc.host}${loc.pathname}`);
 | 
			
		||||
wsLoc.protocol = 'ws:';
 | 
			
		||||
if (loc.protocol === "https:") {
 | 
			
		||||
  wsLoc.protocol = 'wss:';
 | 
			
		||||
}
 | 
			
		||||
const wsUrl = `${wsProtocol}//${window.location.host}${window.location.pathname}`;
 | 
			
		||||
 | 
			
		||||
const wsUrl = wsLoc.href;
 | 
			
		||||
 | 
			
		||||
// ============================= Color Log Parsing =============================
 | 
			
		||||
const initializeColorState = () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -469,7 +469,7 @@
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="footer-copyright">
 | 
			
		||||
    <div class="container">
 | 
			
		||||
      © 2019 Copyright Otto Winter, Made with <a class="grey-text text-lighten-4" href="https://materializecss.com/" target="_blank">Materialize</a>
 | 
			
		||||
      © 2019 Copyright ESPHome, Made with <a class="grey-text text-lighten-4" href="https://materializecss.com/" target="_blank">Materialize</a>
 | 
			
		||||
      <a class="grey-text text-lighten-4 right" href="{{ docs_link }}" target="_blank" rel="noreferrer">ESPHome {{ version }} Documentation</a>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -65,7 +65,7 @@
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="footer-copyright">
 | 
			
		||||
    <div class="container">
 | 
			
		||||
      © 2019 Copyright Otto Winter, Made with <a class="grey-text text-lighten-4" href="https://materializecss.com/" target="_blank">Materialize</a>
 | 
			
		||||
      © 2019 Copyright ESPHome, Made with <a class="grey-text text-lighten-4" href="https://materializecss.com/" target="_blank">Materialize</a>
 | 
			
		||||
        <a class="grey-text text-lighten-4 right" href="{{ docs_link }}"
 | 
			
		||||
           target="_blank">ESPHome {{ version }} Documentation</a>
 | 
			
		||||
    </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -127,15 +127,20 @@ def resolve_ip_address(host):
 | 
			
		||||
    from esphome.core import EsphomeError
 | 
			
		||||
    import socket
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        ip = socket.gethostbyname(host)
 | 
			
		||||
    except socket.error as err:
 | 
			
		||||
        if host.endswith('.local'):
 | 
			
		||||
            ip = _resolve_with_zeroconf(host)
 | 
			
		||||
        else:
 | 
			
		||||
            raise EsphomeError("Error resolving IP address: {}".format(err))
 | 
			
		||||
    errs = []
 | 
			
		||||
 | 
			
		||||
    return ip
 | 
			
		||||
    if host.endswith('.local'):
 | 
			
		||||
        try:
 | 
			
		||||
            return _resolve_with_zeroconf(host)
 | 
			
		||||
        except EsphomeError as err:
 | 
			
		||||
            errs.append(str(err))
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        return socket.gethostbyname(host)
 | 
			
		||||
    except socket.error as err:
 | 
			
		||||
        errs.append(str(err))
 | 
			
		||||
        raise EsphomeError("Error resolving IP address: {}"
 | 
			
		||||
                           "".format(', '.join(errs)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_bool_env(var, default=False):
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ import re
 | 
			
		||||
import subprocess
 | 
			
		||||
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
from esphome.py_compat import IS_PY2
 | 
			
		||||
from esphome.util import run_external_command, run_external_process
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
@@ -17,12 +18,10 @@ def patch_structhash():
 | 
			
		||||
    # removed/added. This might have unintended consequences, but this improves compile
 | 
			
		||||
    # times greatly when adding/removing components and a simple clean build solves
 | 
			
		||||
    # all issues
 | 
			
		||||
    # pylint: disable=no-member,no-name-in-module
 | 
			
		||||
    from platformio.commands import run
 | 
			
		||||
    from platformio import util
 | 
			
		||||
    try:
 | 
			
		||||
        from platformio.util import get_project_dir
 | 
			
		||||
    except ImportError:
 | 
			
		||||
        from platformio.project.helpers import get_project_dir
 | 
			
		||||
    from platformio.util import get_project_dir
 | 
			
		||||
    from os.path import join, isdir, getmtime, isfile
 | 
			
		||||
    from os import makedirs
 | 
			
		||||
 | 
			
		||||
@@ -69,7 +68,8 @@ def run_platformio_cli(*args, **kwargs):
 | 
			
		||||
    if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
 | 
			
		||||
        import platformio.__main__
 | 
			
		||||
        try:
 | 
			
		||||
            patch_structhash()
 | 
			
		||||
            if IS_PY2:
 | 
			
		||||
                patch_structhash()
 | 
			
		||||
        except Exception:  # pylint: disable=broad-except
 | 
			
		||||
            # Ignore when patch fails
 | 
			
		||||
            pass
 | 
			
		||||
 
 | 
			
		||||
@@ -78,8 +78,12 @@ def indexbytes(buf, i):
 | 
			
		||||
if IS_PY2:
 | 
			
		||||
    def decode_text(data, encoding='utf-8', errors='strict'):
 | 
			
		||||
        # type: (str, str, str) -> unicode
 | 
			
		||||
        if isinstance(data, unicode):
 | 
			
		||||
            return data
 | 
			
		||||
        return unicode(data, encoding=encoding, errors=errors)
 | 
			
		||||
else:
 | 
			
		||||
    def decode_text(data, encoding='utf-8', errors='strict'):
 | 
			
		||||
        # type: (bytes, str, str) -> str
 | 
			
		||||
        if isinstance(data, str):
 | 
			
		||||
            return data
 | 
			
		||||
        return data.decode(encoding=encoding, errors=errors)
 | 
			
		||||
 
 | 
			
		||||
@@ -187,6 +187,8 @@ class OrderedDict(collections.OrderedDict):
 | 
			
		||||
 | 
			
		||||
    def move_to_end(self, key, last=True):
 | 
			
		||||
        if IS_PY2:
 | 
			
		||||
            if len(self) == 1:
 | 
			
		||||
                return
 | 
			
		||||
            if last:
 | 
			
		||||
                # When moving to end, just pop and re-add
 | 
			
		||||
                val = self.pop(key)
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ import re
 | 
			
		||||
 | 
			
		||||
from esphome.config import iter_components
 | 
			
		||||
from esphome.const import CONF_BOARD_FLASH_MODE, CONF_ESPHOME, CONF_PLATFORMIO_OPTIONS, \
 | 
			
		||||
    HEADER_FILE_EXTENSIONS, SOURCE_FILE_EXTENSIONS
 | 
			
		||||
    HEADER_FILE_EXTENSIONS, SOURCE_FILE_EXTENSIONS, __version__
 | 
			
		||||
from esphome.core import CORE, EsphomeError
 | 
			
		||||
from esphome.helpers import mkdir_p, read_file, write_file_if_changed, walk_files
 | 
			
		||||
from esphome.storage_json import StorageJSON, storage_path
 | 
			
		||||
@@ -268,7 +268,12 @@ DEFINES_H_FORMAT = ESPHOME_H_FORMAT = u"""\
 | 
			
		||||
#pragma once
 | 
			
		||||
{}
 | 
			
		||||
"""
 | 
			
		||||
VERSION_H_FORMAT = u"""\
 | 
			
		||||
#pragma once
 | 
			
		||||
#define ESPHOME_VERSION "{}"
 | 
			
		||||
"""
 | 
			
		||||
DEFINES_H_TARGET = 'esphome/core/defines.h'
 | 
			
		||||
VERSION_H_TARGET = 'esphome/core/version.h'
 | 
			
		||||
ESPHOME_README_TXT = u"""
 | 
			
		||||
THIS DIRECTORY IS AUTO-GENERATED, DO NOT MODIFY
 | 
			
		||||
 | 
			
		||||
@@ -335,6 +340,8 @@ def copy_src_tree():
 | 
			
		||||
                          CORE.relative_src_path('esphome', 'README.txt'))
 | 
			
		||||
    write_file_if_changed(ESPHOME_H_FORMAT.format(include_s),
 | 
			
		||||
                          CORE.relative_src_path('esphome.h'))
 | 
			
		||||
    write_file_if_changed(VERSION_H_FORMAT.format(__version__),
 | 
			
		||||
                          CORE.relative_src_path('esphome' 'core', 'version.h'))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def generate_defines_h():
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,7 @@ def main():
 | 
			
		||||
    print("Running flake8...")
 | 
			
		||||
    log = get_output(*cmd)
 | 
			
		||||
    for line in log.splitlines():
 | 
			
		||||
        line = line.split(':')
 | 
			
		||||
        line = line.split(':', 4)
 | 
			
		||||
        if len(line) < 4:
 | 
			
		||||
            continue
 | 
			
		||||
        file_ = line[0]
 | 
			
		||||
@@ -69,12 +69,12 @@ def main():
 | 
			
		||||
    print("Running pylint...")
 | 
			
		||||
    log = get_output(*cmd)
 | 
			
		||||
    for line in log.splitlines():
 | 
			
		||||
        line = line.split(':')
 | 
			
		||||
        line = line.split(':', 3)
 | 
			
		||||
        if len(line) < 3:
 | 
			
		||||
            continue
 | 
			
		||||
        file_ = line[0]
 | 
			
		||||
        linno = line[1]
 | 
			
		||||
        msg = (u':'.join(line[3:])).strip()
 | 
			
		||||
        msg = (u':'.join(line[2:])).strip()
 | 
			
		||||
        print_error(file_, linno, msg)
 | 
			
		||||
        errors += 1
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -105,6 +105,9 @@ mqtt:
 | 
			
		||||
        - light.control:
 | 
			
		||||
            id: living_room_lights
 | 
			
		||||
            brightness: !lambda 'return id(living_room_lights).current_values.get_brightness() + 0.5;'
 | 
			
		||||
        - light.dim_relative:
 | 
			
		||||
            id: living_room_lights
 | 
			
		||||
            relative_brightness: 5%
 | 
			
		||||
        - uart.write:
 | 
			
		||||
            id: uart0
 | 
			
		||||
            data: Hello World
 | 
			
		||||
@@ -347,6 +350,10 @@ sensor:
 | 
			
		||||
  - platform: total_daily_energy
 | 
			
		||||
    power_id: hlw8012_power
 | 
			
		||||
    name: "HLW8012 Total Daily Energy"
 | 
			
		||||
  - platform: integration
 | 
			
		||||
    sensor: hlw8012_power
 | 
			
		||||
    name: "Integration Sensor"
 | 
			
		||||
    time_unit: s
 | 
			
		||||
  - platform: hmc5883l
 | 
			
		||||
    address: 0x68
 | 
			
		||||
    field_strength_x:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user