1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-04 00:51:49 +00:00

Compare commits

..

24 Commits

Author SHA1 Message Date
Otto Winter
1ca241615d Bump version to v1.13.6 2019-06-14 12:55:23 +02:00
Otto Winter
b8aa84002a Re-add CustomMQTTDevice class (#640)
* Re-add CustomMQTTDevice class

Fixes https://github.com/esphome/issues/issues/427

* Fix
2019-06-14 12:55:20 +02:00
Otto Winter
10cc0b1d5b Fix remote_receiver raw binary sensor (#639)
* Fix remote_receiver raw binary sensor

Fixes https://github.com/esphome/issues/issues/439

* Lint
2019-06-14 12:55:19 +02:00
Otto Winter
11d9c203c1 Fix version.h file (#630)
* Fix version.h file

* Lint
2019-06-14 12:55:19 +02:00
Otto Winter
c9ab454c3c Fix globals.set (#635)
* Fix globals.set

* Update __init__.py
2019-06-14 12:55:19 +02:00
Otto Winter
4a55692885 Fix russia timezone detection (#637)
Fixes https://github.com/esphome/issues/issues/378#issuecomment-500219634
2019-06-14 12:55:19 +02:00
Otto Winter
88c129e705 Fix ESP32 RCSwitch Dump Stack Smash Protection (#636)
Fixes https://github.com/esphome/issues/issues/366
2019-06-14 12:55:19 +02:00
Otto Winter
80b48f01fb Fix esp8266_restore_from_flash (#638)
Fixes https://github.com/esphome/issues/issues/424
2019-06-14 12:36:30 +02:00
Otto Winter
642bc91a76 Update esp32_ble_tracker.cpp 2019-06-08 17:06:29 +02:00
Otto Winter
d69926ee56 Bump version to v1.13.5 2019-06-08 16:49:04 +02:00
Otto Winter
4758403d44 Work around ESP32 core WiFi Bug (#627)
* Work around ESP32 WiFi Bug

* Lint
2019-06-08 16:49:00 +02:00
Otto Winter
4b0ec5c28a Work around ESP32 BLE issue (#626) 2019-06-08 16:49:00 +02:00
Otto Winter
4b2a9e5e49 Fix status binary sensor for MQTT (#628)
Fixes https://github.com/esphome/issues/issues/417
2019-06-08 16:48:59 +02:00
Otto Winter
1449c51d49 Update base image to 1.8.3 (#625) 2019-06-08 16:48:59 +02:00
Otto Winter
a451705e0b Fix sun default elevation (#620) 2019-06-08 16:48:58 +02:00
Otto Winter
2e6db39173 Fix integration sensor, add test (#619)
* Fix integration sensor, add test

* Fix

* Fix
2019-06-08 16:48:58 +02:00
Otto Winter
373f75253c Update docker base image to 1.8.0 (#618) 2019-06-08 16:48:58 +02:00
Otto Winter
724842084e Make ForCondition a component (#616)
Fixes https://github.com/esphome/issues/issues/396
2019-06-08 16:48:57 +02:00
Otto Winter
8f3635b167 Fix remote_receiver always shows sony (#617)
Fixes https://github.com/esphome/issues/issues/383#issuecomment-498370572
2019-06-08 16:48:57 +02:00
Otto Winter
11605a36f7 Fix Hass.io addon SSL (#613)
Fixes https://github.com/esphome/issues/issues/404
2019-06-08 16:48:56 +02:00
Otto Winter
533f81d625 Template Cover don't auto-set current_operation (#612)
Fixes https://github.com/esphome/issues/issues/408
2019-06-08 16:48:56 +02:00
Otto Winter
aacb9e44e8 DHT22 ignore invalid values (#614)
Fixes https://github.com/esphome/issues/issues/397
2019-06-08 16:48:55 +02:00
Peter Tatrai
c6e3f1bca6 Fix ForCondition time duration check (#610)
According documentation ForCondition should evaluate to true if a nested condition is true for at least the specified time duration and not the less.
2019-06-08 16:48:55 +02:00
Otto Winter
a933d4aeb6 Move ESPHome version define (#607)
* Move ESPHome version define

* Lint
2019-06-08 16:48:55 +02:00
37 changed files with 358 additions and 88 deletions

View File

@@ -3,7 +3,7 @@
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375/
BASE_VERSION: '1.7.0'
BASE_VERSION: '1.8.3'
TZ: UTC
stages:

View File

@@ -1,4 +1,4 @@
ARG BUILD_FROM=esphome/esphome-base-amd64:1.7.0
ARG BUILD_FROM=esphome/esphome-base-amd64:1.8.3
FROM ${BUILD_FROM}
COPY . .

View File

@@ -1,4 +1,4 @@
FROM esphome/esphome-base-amd64:1.7.0
FROM esphome/esphome-base-amd64:1.8.3
RUN \
apt-get update \

View File

@@ -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

View File

@@ -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

View File

@@ -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 "";

View File

@@ -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):

View File

@@ -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"

View File

@@ -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_);

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -50,6 +50,7 @@ def globals_set_to_code(config, action_id, template_arg, args):
full_id, paren = yield cg.get_variable_with_full_id(config[CONF_ID])
template_arg = cg.TemplateArguments(full_id.type, *template_arg)
var = cg.new_Pvariable(action_id, template_arg, paren)
templ = yield cg.templatable(config[CONF_VALUE], args, None)
templ = yield cg.templatable(config[CONF_VALUE], args, None,
to_exp=cg.RawExpression)
cg.add(var.set_value(templ))
yield var

View File

@@ -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]))

View File

@@ -0,0 +1,30 @@
#include "custom_mqtt_device.h"
#include "esphome/core/log.h"
namespace esphome {
namespace mqtt {
static const char *TAG = "mqtt.custom";
bool CustomMQTTDevice::publish(const std::string &topic, const std::string &payload, uint8_t qos, bool retain) {
return global_mqtt_client->publish(topic, payload, qos, retain);
}
bool CustomMQTTDevice::publish(const std::string &topic, float value, int8_t number_decimals) {
auto str = value_accuracy_to_string(value, number_decimals);
return this->publish(topic, str);
}
bool CustomMQTTDevice::publish(const std::string &topic, int value) {
char buffer[24];
sprintf(buffer, "%d", value);
return this->publish(topic, buffer);
}
bool CustomMQTTDevice::publish_json(const std::string &topic, const json::json_build_t &f, uint8_t qos, bool retain) {
return global_mqtt_client->publish_json(topic, f, qos, retain);
}
bool CustomMQTTDevice::publish_json(const std::string &topic, const json::json_build_t &f) {
return this->publish_json(topic, f, 0, false);
}
bool CustomMQTTDevice::is_connected() { return global_mqtt_client != nullptr && global_mqtt_client->is_connected(); }
} // namespace mqtt
} // namespace esphome

View File

@@ -0,0 +1,217 @@
#pragma once
#include "esphome/core/component.h"
#include "mqtt_client.h"
namespace esphome {
namespace mqtt {
/** This class is a helper class for custom components that communicate using
* MQTT. It has 5 helper functions that you can use (square brackets indicate optional):
*
* - `subscribe(topic, function_pointer, [qos])`
* - `subscribe_json(topic, function_pointer, [qos])`
* - `publish(topic, payload, [qos], [retain])`
* - `publish_json(topic, payload_builder, [qos], [retain])`
* - `is_connected()`
*/
class CustomMQTTDevice {
public:
/** Subscribe to an MQTT topic with the given Quality of Service.
*
* Example:
*
* ```cpp
* class MyCustomMQTTDevice : public Component, public mqtt:CustomMQTTDevice {
* public:
* void setup() override {
* subscribe("the/topic", &MyCustomMQTTDevice::on_message);
* pinMode(5, OUTPUT);
* }
*
* // topic and payload parameters can be removed if not needed
* // e.g: void on_message() {
*
* void on_message(const std::string &topic, const std::string &payload) {
* // do something with topic and payload
* if (payload == "ON") {
* digitalWrite(5, HIGH);
* } else {
* digitalWrite(5, LOW);
* }
* }
* };
* ```
*
* @tparam T A C++ template argument for determining the type of the callback.
* @param topic The topic to subscribe to. Re-subscription on re-connects is automatically handled.
* @param callback The callback (must be a class member) to subscribe with.
* @param qos The Quality of Service to subscribe with. Defaults to 0.
*/
template<typename T>
void subscribe(const std::string &topic, void (T::*callback)(const std::string &, const std::string &),
uint8_t qos = 0);
template<typename T>
void subscribe(const std::string &topic, void (T::*callback)(const std::string &), uint8_t qos = 0);
template<typename T> void subscribe(const std::string &topic, void (T::*callback)(), uint8_t qos = 0);
/** Subscribe to an MQTT topic and call the callback if the payload can be decoded
* as JSON with the given Quality of Service.
*
* Example:
*
* ```cpp
* class MyCustomMQTTDevice : public Component, public mqtt:CustomMQTTDevice {
* public:
* void setup() override {
* subscribe_json("the/topic", &MyCustomMQTTDevice::on_json_message);
* pinMode(5, OUTPUT);
* }
*
* // topic parameter can be remove if not needed:
* // e.g.: void on_json_message(JsonObject &payload) {
*
* void on_json_message(const std::string &topic, JsonObject &payload) {
* // do something with topic and payload
* if (payload["number"] == 1) {
* digitalWrite(5, HIGH);
* } else {
* digitalWrite(5, LOW);
* }
* }
* };
* ```
*
* @tparam T A C++ template argument for determining the type of the callback.
* @param topic The topic to subscribe to. Re-subscription on re-connects is automatically handled.
* @param callback The callback (must be a class member) to subscribe with.
* @param qos The Quality of Service to subscribe with. Defaults to 0.
*/
template<typename T>
void subscribe_json(const std::string &topic, void (T::*callback)(const std::string &, JsonObject &),
uint8_t qos = 0);
template<typename T>
void subscribe_json(const std::string &topic, void (T::*callback)(JsonObject &), uint8_t qos = 0);
/** Publish an MQTT message with the given payload and QoS and retain settings.
*
* Example:
*
* ```cpp
* void in_some_method() {
* publish("the/topic", "The Payload", 0, true);
* }
* ```
*
* @param topic The topic to publish to.
* @param payload The payload to publish.
* @param qos The Quality of Service to publish with. Defaults to 0
* @param retain Whether to retain the message. Defaults to false.
*/
bool publish(const std::string &topic, const std::string &payload, uint8_t qos = 0, bool retain = false);
/** Publish an MQTT message with the given floating point number and number of decimals.
*
* Example:
*
* ```cpp
* void in_some_method() {
* publish("the/topic", 1.0);
* // with two digits after the decimal point
* publish("the/topic", 1.0, 2);
* }
* ```
*
* @param topic The topic to publish to.
* @param payload The payload to publish.
* @param number_decimals The number of digits after the decimal point to round to, defaults to 3 digits.
*/
bool publish(const std::string &topic, float value, int8_t number_decimals = 3);
/** Publish an MQTT message with the given integer as payload.
*
* Example:
*
* ```cpp
* void in_some_method() {
* publish("the/topic", 42);
* }
* ```
*
* @param topic The topic to publish to.
* @param payload The payload to publish.
*/
bool publish(const std::string &topic, int value);
/** Publish a JSON-encoded MQTT message with the given Quality of Service and retain settings.
*
* Example:
*
* ```cpp
* void in_some_method() {
* publish("the/topic", [=](JsonObject &root) {
* root["the_key"] = "Hello World!";
* }, 0, false);
* }
* ```
*
* @param topic The topic to publish to.
* @param payload The payload to publish.
* @param qos The Quality of Service to publish with.
* @param retain Whether to retain the message.
*/
bool publish_json(const std::string &topic, const json::json_build_t &f, uint8_t qos, bool retain);
/** Publish a JSON-encoded MQTT message.
*
* Example:
*
* ```cpp
* void in_some_method() {
* publish("the/topic", [=](JsonObject &root) {
* root["the_key"] = "Hello World!";
* });
* }
* ```
*
* @param topic The topic to publish to.
* @param payload The payload to publish.
*/
bool publish_json(const std::string &topic, const json::json_build_t &f);
/// Check whether the MQTT client is currently connected and messages can be published.
bool is_connected();
};
template<typename T>
void CustomMQTTDevice::subscribe(const std::string &topic,
void (T::*callback)(const std::string &, const std::string &), uint8_t qos) {
auto f = std::bind(callback, (T *) this, std::placeholders::_1, std::placeholders::_2);
global_mqtt_client->subscribe(topic, f, qos);
}
template<typename T>
void CustomMQTTDevice::subscribe(const std::string &topic, void (T::*callback)(const std::string &), uint8_t qos) {
auto f = std::bind(callback, (T *) this, std::placeholders::_2);
global_mqtt_client->subscribe(topic, f, qos);
}
template<typename T> void CustomMQTTDevice::subscribe(const std::string &topic, void (T::*callback)(), uint8_t qos) {
auto f = std::bind(callback, (T *) this);
global_mqtt_client->subscribe(topic, f, qos);
}
template<typename T>
void CustomMQTTDevice::subscribe_json(const std::string &topic, void (T::*callback)(const std::string &, JsonObject &),
uint8_t qos) {
auto f = std::bind(callback, (T *) this, std::placeholders::_1, std::placeholders::_2);
global_mqtt_client->subscribe_json(topic, f, qos);
}
template<typename T>
void CustomMQTTDevice::subscribe_json(const std::string &topic, void (T::*callback)(JsonObject &), uint8_t qos) {
auto f = std::bind(callback, (T *) this, std::placeholders::_2);
global_mqtt_client->subscribe_json(topic, f, qos);
}
} // namespace mqtt
} // namespace esphome

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -2,7 +2,7 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components import binary_sensor
from esphome.const import CONF_DATA, CONF_ID, CONF_TRIGGER_ID, CONF_NBITS, CONF_ADDRESS, \
from esphome.const import CONF_DATA, CONF_TRIGGER_ID, CONF_NBITS, CONF_ADDRESS, \
CONF_COMMAND, CONF_CODE, CONF_PULSE_LENGTH, CONF_SYNC, CONF_ZERO, CONF_ONE, CONF_INVERTED, \
CONF_PROTOCOL, CONF_GROUP, CONF_DEVICE, CONF_STATE, CONF_CHANNEL, CONF_FAMILY, CONF_REPEAT, \
CONF_WAIT_TIME, CONF_TIMES, CONF_TYPE_ID, CONF_CARRIER_FREQUENCY
@@ -350,7 +350,7 @@ RAW_SCHEMA = cv.Schema({
@register_binary_sensor('raw', RawBinarySensor, RAW_SCHEMA)
def raw_binary_sensor(var, config):
code_ = config[CONF_CODE]
arr = cg.progmem_array(config[CONF_ID], code_)
arr = cg.progmem_array(config[CONF_CODE_STORAGE_ID], code_)
cg.add(var.set_data(arr))
cg.add(var.set_len(len(code_)))

View File

@@ -232,7 +232,7 @@ bool RCSwitchDumper::dump(RemoteReceiveData src) {
uint8_t out_nbits;
RCSwitchBase *protocol = &rc_switch_protocols[i];
if (protocol->decode(src, &out_data, &out_nbits) && out_nbits >= 3) {
char buffer[32];
char buffer[33];
for (uint8_t j = 0; j < out_nbits; j++)
buffer[j] = (out_data & (1 << (out_nbits - j - 1))) ? '1' : '0';

View File

@@ -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;

View File

@@ -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)

View File

@@ -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)

View File

@@ -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_;

View File

@@ -52,6 +52,15 @@ def _tz_dst_str(dt):
_tz_timedelta(td))
def _non_dst_tz(tz, dt):
tzname = tz.tzname(dt)
utcoffset = tz.utcoffset(dt)
_LOGGER.info("Detected timezone '%s' with UTC offset %s",
tzname, _tz_timedelta(utcoffset))
tzbase = '{}{}'.format(tzname, _tz_timedelta(-1 * utcoffset))
return tzbase
def convert_tz(pytz_obj):
tz = pytz_obj
@@ -59,24 +68,14 @@ def convert_tz(pytz_obj):
first_january = datetime.datetime(year=now.year, month=1, day=1)
if not isinstance(tz, pytz.tzinfo.DstTzInfo):
tzname = tz.tzname(first_january)
utcoffset = tz.utcoffset(first_january)
_LOGGER.info("Detected timezone '%s' with UTC offset %s",
tzname, _tz_timedelta(utcoffset))
tzbase = '{}{}'.format(tzname, _tz_timedelta(-1 * utcoffset))
return tzbase
return _non_dst_tz(tz, first_january)
# pylint: disable=protected-access
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
return _non_dst_tz(tz, now)
idx1, idx2 = idx, idx + 1
dstoffset1 = transition_info[idx1][1]
@@ -84,6 +83,14 @@ def convert_tz(pytz_obj):
# Normalize to 1 being DST on
idx1, idx2 = idx + 1, idx + 2
if idx2 >= len(transition_times):
return _non_dst_tz(tz, now)
if transition_times[idx2].year > now.year + 1:
# Next transition is scheduled after this year
# Probably a scheduler timezone change.
return _non_dst_tz(tz, now)
utcoffset_on, _, tzname_on = transition_info[idx1]
utcoffset_off, _, tzname_off = transition_info[idx2]
dst_begins_utc = transition_times[idx1]

View File

@@ -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 {

View File

@@ -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],

View File

@@ -3,7 +3,7 @@
MAJOR_VERSION = 1
MINOR_VERSION = 13
PATCH_VERSION = '4'
PATCH_VERSION = '6'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)

View File

@@ -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"

View File

@@ -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:

View File

@@ -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

View File

@@ -7,6 +7,7 @@
#endif
#include "esphome/core/esphal.h"
#include "esphome/core/defines.h"
namespace esphome {

View File

@@ -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
View File

@@ -0,0 +1,3 @@
#pragma once
// This file is auto-generated! Do not edit!
#define ESPHOME_VERSION "dev"

View File

@@ -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
@@ -61,7 +61,7 @@ PLATFORMIO_ESP32_LUT = {
'1.0.0': 'espressif32@1.4.0',
'1.0.1': 'espressif32@1.6.0',
'1.0.2': 'espressif32@1.8.0',
'RECOMMENDED': 'espressif32@1.8.0',
'RECOMMENDED': 'espressif32@1.6.0',
'LATEST': 'espressif32',
'DEV': ARDUINO_VERSION_ESP32_DEV,
}
@@ -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, []):

View File

@@ -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
@@ -310,7 +315,7 @@ def copy_src_tree():
continue
# Transform path to target path name
target = os.path.relpath(path, CORE.relative_src_path()).replace(os.path.sep, '/')
if target == DEFINES_H_TARGET:
if target in (DEFINES_H_TARGET, VERSION_H_TARGET):
# Ignore defines.h, will be dealt with later
continue
if target not in source_files_copy:
@@ -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():

View File

@@ -350,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:
@@ -657,6 +661,13 @@ binary_sensor:
number: 1
mode: INPUT
inverted: True
- platform: remote_receiver
name: "Raw Remote Receiver Test"
raw:
code: [5685, -4252, 1711, -2265, 1712, -2265, 1711, -2264, 1712, -2266,
3700, -2263, 1712, -4254, 1711, -4249, 1715, -2266, 1710, -2267,
1709, -2265, 3704, -4250, 1712, -4254, 3700, -2260, 1714, -2265,
1712, -2262, 1714, -2267, 1709]
pca9685:
frequency: 500
@@ -1272,6 +1283,9 @@ text_sensor:
id: template_text
state: |-
return "Hello World2";
- globals.set:
id: glob_int
value: '0'
- platform: template
name: Template Text Sensor
id: template_text