1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-01 15:41:52 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Otto Winter
caa5b20791 Bump version to v1.13.4 2019-06-03 15:24:10 +02:00
Otto Winter
e2ad9ed746 ESP8266 connect fixes (#605)
* ESP8266 Connection Fixes

* Update client.py

* Update mqtt_client.cpp

* Update mqtt_client.cpp

* Fix ping

* Async dump config

* Update base image to 1.7.0

* Update helpers.py

* Updates

* Update Dockerfile.lint
2019-06-03 15:23:57 +02:00
Otto Winter
32c0e7c2ae Fix ADS1115 calculation (#606)
Fixes https://github.com/esphome/issues/issues/393
2019-06-03 15:23:56 +02:00
Otto Winter
6c564c7b7f Fix validation infinite loop with empty platform block (#598)
* Fix validation infinite loop with empty platform block

* Update util.py
2019-06-03 15:23:56 +02:00
Otto Winter
c81e3a3be4 Fix hx711 (#602)
* Fix HX711

* Use signed value

* Update hx711.cpp
2019-06-03 15:23:56 +02:00
Otto Winter
6b1b9ef7ec Fix color wipe effect (#599) 2019-06-03 15:23:56 +02:00
Otto Winter
c26a8b8718 Allow old remote_transmitter repeat schema (#601)
Fixes https://github.com/esphome/issues/issues/389
2019-06-03 15:23:56 +02:00
Otto Winter
4a89a475bd Add better esphomeyaml migration path (#600)
Fixes https://github.com/esphome/issues/issues/387
2019-06-03 15:23:55 +02:00
23 changed files with 138 additions and 105 deletions

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
FROM esphome/esphome-base-amd64:1.5.1
FROM esphome/esphome-base-amd64:1.7.0
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

View File

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

View File

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

View File

@@ -712,12 +712,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;
}
}

View File

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

View File

@@ -82,7 +82,7 @@ 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_}; }
@@ -123,6 +123,35 @@ 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;
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_); }

View File

@@ -399,33 +399,7 @@ 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;
}
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;

View File

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

View File

@@ -360,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);
}
}

View File

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

View File

@@ -421,6 +421,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...");

View File

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

View File

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

View File

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

View File

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

View File

@@ -57,14 +57,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 +90,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_++;
}
}

View File

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

View File

@@ -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.6.0',
'RECOMMENDED': 'espressif32@1.8.0',
'LATEST': 'espressif32',
'DEV': ARDUINO_VERSION_ESP32_DEV,
}

View File

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

View File

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

View File

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