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

Compare commits

...

39 Commits

Author SHA1 Message Date
Otto Winter
8cf15c7f5c Bump version to v1.13.3 2019-06-01 22:02:10 +02:00
Otto Winter
adc76ca1b8 Fix dashboard for Py3 installs (#596)
Fixes https://github.com/esphome/issues/issues/368
2019-06-01 22:02:05 +02:00
Otto Winter
8f8892440c Fix medium fan speed (#595) 2019-06-01 22:02:04 +02:00
Otto Winter
570843150d Fix flicker light effect turning itself off (#594)
Fixes https://github.com/esphome/issues/issues/382
2019-06-01 22:02:04 +02:00
Otto Winter
f3fc9e4142 Fix remote_receiver binary_sensor (#592)
Fixes https://github.com/esphome/issues/issues/369
2019-06-01 22:02:04 +02:00
Otto Winter
075fcb77a8 Fix timezone detection (#586)
* Fix timezone detection

* Update __init__.py
2019-06-01 22:02:04 +02:00
Otto Winter
e5899ff717 Fix scripts circular dependency (#591)
Fixes https://github.com/esphome/issues/issues/370
2019-06-01 22:02:04 +02:00
Otto Winter
2fb3970027 Fix addressable effects (#590) 2019-06-01 22:02:03 +02:00
Marc-Antoine Courteau
1a4efa1b8c List the correct boards when building for ESP32 (#589)
* List the ESP32 boards for ESP32 builds.

* Sort the list of valid boards.
2019-06-01 22:02:03 +02:00
Otto Winter
72f656ffef Bump version to v1.13.2 2019-05-31 16:37:56 +02:00
Otto Winter
b60239d5e5 Fix i2c setup priority (#585)
Fixes https://github.com/esphome/issues/issues/314
2019-05-31 16:37:49 +02:00
Otto Winter
d02e280c3c Fix light partition (#584)
* Fix light partition

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

* Lint
2019-05-31 16:37:48 +02:00
Otto Winter
6535b0966e Fix MQTT on_message trigger (#583)
Fixes https://github.com/esphome/issues/issues/363
Fixes https://github.com/esphome/issues/issues/364
2019-05-31 16:37:48 +02:00
Otto Winter
82dbacbee5 Fix travis build (#582) 2019-05-31 16:37:48 +02:00
Otto Winter
2432901974 Fix Rotary Encoder (#580)
Fixes https://github.com/esphome/issues/issues/360
2019-05-31 16:37:48 +02:00
Otto Winter
ebb5d58c14 Fix MQTT client_id changed (#579)
Fixes https://github.com/esphome/issues/issues/323
2019-05-31 16:37:48 +02:00
Otto Winter
605e365405 Fix remote_receiver binary_sensor schema (#578)
Fixes https://github.com/esphome/issues/issues/353#issuecomment-497491863
2019-05-31 16:37:47 +02:00
Otto Winter
5ab995d8ca Bump version to v1.13.1 2019-05-30 22:31:56 +02:00
Otto Winter
4248741b11 Fix waveshare 7.5in model (#576)
* Fix waveshare 7.5in model

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

* Fix platformio travis errors
2019-05-30 22:31:54 +02:00
Otto Winter
4b8ecc7634 Dashboard work around Hass.io bug (#575)
* Dashboard work around Hass.io bug

Ref https://github.com/home-assistant/hassio/issues/1103

* Lint
2019-05-30 22:31:53 +02:00
Otto Winter
25d04c759c Fix Sun Trigger (#572)
* Fix Sun Trigger

* Fix cwww lights
2019-05-30 22:31:53 +02:00
Otto Winter
b4ec84030e Fix validation TypeError (#574) 2019-05-30 22:31:53 +02:00
Otto Winter
29e8761373 Fix merge 2019-05-30 14:20:06 +02:00
Otto Winter
a04299c59e Bump version to v1.13.0 2019-05-30 14:15:41 +02:00
Otto Winter
d7bf3c51d9 Merge branch 'beta' 2019-05-30 14:15:28 +02:00
Otto Winter
3ddf5a4ec7 Bump version to v1.13.0b7 2019-05-30 13:13:40 +02:00
Otto Winter
f2d6817d8a Register light conditions (#570) 2019-05-30 13:13:37 +02:00
Jesse Hills
31821e6309 Correctly set warm white variables (#569) 2019-05-30 13:13:36 +02:00
Otto Winter
7f507935b1 Bump version to v1.13.0b6 2019-05-29 19:38:32 +02:00
Otto Winter
3b1ba27043 Add uart.write action (#567)
* Add uart.write action

* Lint
2019-05-29 19:38:29 +02:00
Otto Winter
4b7c5aa05c Use copy for custom includes (#568) 2019-05-29 19:38:29 +02:00
Otto Winter
5fca02c712 Fix TSL2561 invalid default (#566)
Ref https://github.com/esphome/issues/issues/352#issuecomment-496883794
2019-05-29 19:38:28 +02:00
Otto Winter
ac0b095941 Bump version to v1.12.2 2019-03-31 13:13:12 +02:00
Otto Winter
cda9bad233 Upgrade docker base image to 1.4.3 (#499) 2019-03-31 13:13:09 +02:00
Otto Winter
41db8a1264 Fix text sensor MQTT settings (#495)
Fixes https://github.com/esphome/issues/issues/170
2019-03-31 13:13:09 +02:00
Otto Winter
e7e785fd60 Fix dashboard wizard unicode (#494)
* Fix dashboard wizard unicode

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

* Fix password md5
2019-03-31 13:13:08 +02:00
Otto Winter
300d3a1f46 Upgrade ESPAsyncTCP to 1.2.0 (#497) 2019-03-31 13:13:08 +02:00
Otto Winter
356554c08d ESP8266 SDK 2.3.0 compat (#490) 2019-03-31 13:13:08 +02:00
Guillermo Ruffino
ced28ad006 Better symlink support under Windows (#487)
* Better symlink support under Windows

* Conditional loading of ctypes wintypes module

* Shortening comment line for pylint

* Adding plint bypass for Python 3
2019-03-31 13:13:08 +02:00
49 changed files with 345 additions and 143 deletions

View File

@@ -1,5 +1,6 @@
sudo: false
language: python
python: '2.7'
install: script/setup
cache:
directories:

View File

@@ -20,7 +20,7 @@ class CWWWLightOutput : public light::LightOutput {
traits.set_supports_rgb_white_value(false);
traits.set_supports_color_temperature(true);
traits.set_min_mireds(this->cold_white_temperature_);
traits.set_min_mireds(this->warm_white_temperature_);
traits.set_max_mireds(this->warm_white_temperature_);
return traits;
}
void write_state(light::LightState *state) override {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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);
@@ -83,8 +85,46 @@ ESPColorView ESPRangeView::operator[](int32_t index) const {
index = interpret_index(index, this->size());
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);
}
ESPColorView ESPRangeView::Iterator::operator*() const { return (*this->range_->parent_)[this->i_]; }
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 +132,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

View File

@@ -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) {
@@ -431,51 +426,41 @@ class ESPRangeView : public ESPColorSettable {
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);
}
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 +472,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 +515,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 +549,7 @@ class AddressableLight : public LightOutput {
#ifdef USE_POWER_SUPPLY
power_supply::PowerSupplyRequester power_;
#endif
LightState *state_parent_{nullptr};
};
} // namespace light

View File

@@ -308,14 +308,15 @@ class AddressableFlickerEffect : public AddressableLightEffect {
explicit AddressableFlickerEffect(const std::string &name) : AddressableLightEffect(name) {}
void apply(AddressableLight &it, const ESPColor &current_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; }

View File

@@ -89,7 +89,7 @@ template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> {
protected:
LightState *state_;
};
template<typename... Ts> class LightIsOffCondition : public Condition<LightState, Ts...> {
template<typename... Ts> class LightIsOffCondition : public Condition<Ts...> {
public:
explicit LightIsOffCondition(LightState *state) : state_(state) {}
bool check(Ts... x) override { return !this->state_->current_values.is_on(); }

View File

@@ -5,7 +5,7 @@ from esphome.const import CONF_ID, CONF_TRANSITION_LENGTH, CONF_STATE, CONF_FLAS
CONF_EFFECT, CONF_BRIGHTNESS, CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, \
CONF_COLOR_TEMPERATURE, CONF_RANGE_FROM, CONF_RANGE_TO
from .types import DimRelativeAction, ToggleAction, LightState, LightControlAction, \
AddressableLightState, AddressableSet
AddressableLightState, AddressableSet, LightIsOnCondition, LightIsOffCondition
@automation.register_action('light.toggle', ToggleAction, automation.maybe_simple_id({
@@ -145,3 +145,16 @@ def light_addressable_set_to_code(config, action_id, template_arg, args):
templ = yield cg.templatable(config[CONF_WHITE], args, cg.uint8, to_exp=rgbw_to_exp)
cg.add(var.set_white(templ))
yield var
@automation.register_condition('light.is_on', LightIsOnCondition,
automation.maybe_simple_id({
cv.Required(CONF_ID): cv.use_id(LightState),
}))
@automation.register_condition('light.is_off', LightIsOffCondition,
automation.maybe_simple_id({
cv.Required(CONF_ID): cv.use_id(LightState),
}))
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)

View File

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

View File

@@ -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')
@@ -16,6 +16,8 @@ ToggleAction = light_ns.class_('ToggleAction', automation.Action)
LightControlAction = light_ns.class_('LightControlAction', automation.Action)
DimRelativeAction = light_ns.class_('DimRelativeAction', automation.Action)
AddressableSet = light_ns.class_('AddressableSet', automation.Action)
LightIsOnCondition = light_ns.class_('LightIsOnCondition', automation.Condition)
LightIsOffCondition = light_ns.class_('LightIsOffCondition', automation.Condition)
# Effects
LightEffect = light_ns.class_('LightEffect')

View File

@@ -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, []):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -37,4 +37,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]))

View File

@@ -23,7 +23,7 @@ class RGBWWLightOutput : public light::LightOutput {
traits.set_supports_rgb_white_value(true);
traits.set_supports_color_temperature(true);
traits.set_min_mireds(this->cold_white_temperature_);
traits.set_min_mireds(this->warm_white_temperature_);
traits.set_max_mireds(this->warm_white_temperature_);
return traits;
}
void write_state(light::LightState *state) override {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -32,7 +32,7 @@ TSL2561Sensor = tsl2561_ns.class_('TSL2561Sensor', sensor.Sensor, cg.PollingComp
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_LUX, ICON_BRIGHTNESS_5, 1).extend({
cv.GenerateID(): cv.declare_id(TSL2561Sensor),
cv.Optional(CONF_INTEGRATION_TIME, default=402): validate_integration_time,
cv.Optional(CONF_INTEGRATION_TIME, default='402ms'): validate_integration_time,
cv.Optional(CONF_GAIN, default='1X'): cv.enum(GAINS, upper=True),
cv.Optional(CONF_IS_CS_PACKAGE, default=False): cv.boolean,
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x39))

View File

@@ -1,15 +1,27 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN, CONF_UART_ID
from esphome import pins, automation
from esphome.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN, CONF_UART_ID, CONF_DATA
from esphome.core import CORE, coroutine
from esphome.py_compat import text_type, binary_type, char_to_byte
uart_ns = cg.esphome_ns.namespace('uart')
UARTComponent = uart_ns.class_('UARTComponent', cg.Component)
UARTDevice = uart_ns.class_('UARTDevice')
UARTWriteAction = uart_ns.class_('UARTWriteAction', automation.Action)
MULTI_CONF = True
def validate_raw_data(value):
if isinstance(value, text_type):
return value.encode('utf-8')
if isinstance(value, str):
return value
if isinstance(value, list):
return cv.Schema([cv.hex_uint8_t])(value)
raise cv.Invalid("data must either be a string wrapped in quotes or a list of bytes")
def validate_rx_pin(value):
value = pins.input_pin(value)
if CORE.is_esp8266 and value >= 16:
@@ -51,3 +63,22 @@ def register_uart_device(var, config):
"""
parent = yield cg.get_variable(config[CONF_UART_ID])
cg.add(var.set_uart_parent(parent))
@automation.register_action('uart.write', UARTWriteAction, cv.maybe_simple_value({
cv.GenerateID(): cv.use_id(UARTComponent),
cv.Required(CONF_DATA): cv.templatable(validate_raw_data),
}, key=CONF_DATA))
def uart_write_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
yield cg.register_parented(var, config[CONF_ID])
data = config[CONF_DATA]
if isinstance(data, binary_type):
data = [char_to_byte(x) for x in data]
if cg.is_template(data):
templ = yield cg.templatable(data, args, cg.std_vector.template(cg.uint8))
cg.add(var.set_data_template(templ))
else:
cg.add(var.set_data_static(data))
yield var

View File

@@ -0,0 +1,36 @@
#pragma once
#include "uart.h"
#include "esphome/core/automation.h"
namespace esphome {
namespace uart {
template<typename... Ts> class UARTWriteAction : public Action<Ts...>, public Parented<UARTComponent> {
public:
void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
this->data_func_ = func;
this->static_ = false;
}
void set_data_static(const std::vector<uint8_t> &data) {
this->data_static_ = data;
this->static_ = true;
}
void play(Ts... x) override {
if (this->static_) {
this->parent_->write_array(this->data_static_);
} else {
auto val = this->data_func_(x...);
this->parent_->write_array(val);
}
}
protected:
bool static_{false};
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
std::vector<uint8_t> data_static_{};
};
} // namespace uart
} // namespace esphome

View File

@@ -3,27 +3,17 @@ import esphome.config_validation as cv
from esphome.components import switch, uart
from esphome.const import CONF_DATA, CONF_ID, CONF_INVERTED
from esphome.core import HexInt
from esphome.py_compat import text_type, binary_type, char_to_byte
from .. import uart_ns
from esphome.py_compat import binary_type, char_to_byte
from .. import uart_ns, validate_raw_data
DEPENDENCIES = ['uart']
UARTSwitch = uart_ns.class_('UARTSwitch', switch.Switch, uart.UARTDevice, cg.Component)
def validate_data(value):
if isinstance(value, text_type):
return value.encode('utf-8')
if isinstance(value, str):
return value
if isinstance(value, list):
return cv.Schema([cv.hex_uint8_t])(value)
raise cv.Invalid("data must either be a string wrapped in quotes or a list of bytes")
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(UARTSwitch),
cv.Required(CONF_DATA): validate_data,
cv.Required(CONF_DATA): validate_raw_data,
cv.Optional(CONF_INVERTED): cv.invalid("UART switches do not support inverted mode!"),
}).extend(uart.UART_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)

View File

@@ -49,6 +49,7 @@ class UARTComponent : public Component, public Stream {
void write_byte(uint8_t data);
void write_array(const uint8_t *data, size_t len);
void write_array(const std::vector<uint8_t> &data) { this->write_array(&data[0], data.size()); }
void write_str(const char *str);
@@ -97,6 +98,7 @@ class UARTDevice : public Stream {
void write_byte(uint8_t data) { this->parent_->write_byte(data); }
void write_array(const uint8_t *data, size_t len) { this->parent_->write_array(data, len); }
void write_array(const std::vector<uint8_t> &data) { this->parent_->write_array(data); }
void write_str(const char *str) { this->parent_->write_str(str); }

View File

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

View File

@@ -476,6 +476,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);

View File

@@ -612,9 +612,9 @@ def _format_vol_invalid(ex, config):
else:
message += u'[{}] is an invalid option for [{}]. Please check the indentation.'.format(
ex.path[-1], paren)
elif u'extra keys not allowed' in ex.error_message:
elif u'extra keys not allowed' in text_type(ex):
message += u'[{}] is an invalid option for [{}].'.format(ex.path[-1], paren)
elif u'required key not provided' in ex.error_message:
elif u'required key not provided' in text_type(ex):
message += u"'{}' is a required option for [{}].".format(ex.path[-1], paren)
else:
message += humanize_error(config, ex)

View File

@@ -20,7 +20,7 @@ from esphome.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY,
from esphome.core import CORE, HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes
from esphome.helpers import list_starts_with
from esphome.py_compat import integer_types, string_types, text_type, IS_PY2
from esphome.py_compat import integer_types, string_types, text_type, IS_PY2, decode_text
from esphome.voluptuous_schema import _Schema
_LOGGER = logging.getLogger(__name__)
@@ -617,9 +617,9 @@ if IS_PY2:
# Override voluptuous invalid to unicode for py2
def _vol_invalid_unicode(self):
path = u' @ data[%s]' % u']['.join(map(repr, self.path)) \
if self.path else ''
if self.path else u''
# pylint: disable=no-member
output = self.message
output = decode_text(self.message)
if self.error_type:
output += u' for ' + self.error_type
return output + path
@@ -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))
@@ -1210,13 +1209,14 @@ def validate_registry(name, registry):
return ensure_list(validate_registry_entry(name, registry))
def maybe_simple_value(*validators):
def maybe_simple_value(*validators, **kwargs):
key = kwargs.pop('key', CONF_VALUE)
validator = All(*validators)
def validate(value):
if isinstance(value, dict) and CONF_VALUE in value:
if isinstance(value, dict) and key in value:
return validator(value)
return validator({CONF_VALUE: value})
return validator({key: value})
return validate

View File

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

View File

@@ -13,6 +13,7 @@ from esphome.const import ARDUINO_VERSION_ESP32_DEV, ARDUINO_VERSION_ESP8266_DEV
CONF_ESP8266_RESTORE_FROM_FLASH, __version__, 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
from esphome.pins import ESP8266_FLASH_SIZES, ESP8266_LD_SCRIPTS
_LOGGER = logging.getLogger(__name__)
@@ -37,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
@@ -59,6 +60,7 @@ PLATFORMIO_ESP8266_LUT = {
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',
'LATEST': 'espressif32',
'DEV': ARDUINO_VERSION_ESP32_DEV,
@@ -91,6 +93,22 @@ def default_build_path():
return CORE.name
VALID_INCLUDE_EXTS = {'.h', '.hpp', '.tcc', '.ino', '.cpp', '.c'}
def valid_include(value):
try:
return cv.directory(value)
except cv.Invalid:
pass
value = cv.file_(value)
_, ext = os.path.splitext(value)
if ext not in VALID_INCLUDE_EXTS:
raise cv.Invalid(u"Include has invalid file extension {} - valid extensions are {}"
u"".format(ext, ', '.join(VALID_INCLUDE_EXTS)))
return value
CONFIG_SCHEMA = cv.Schema({
cv.Required(CONF_NAME): cv.valid_name,
cv.Required(CONF_PLATFORM): cv.one_of('ESP8266', 'ESP32', upper=True),
@@ -115,7 +133,7 @@ CONFIG_SCHEMA = cv.Schema({
cv.Optional(CONF_ON_LOOP): automation.validate_automation({
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoopTrigger),
}),
cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(cv.file_),
cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(valid_include),
cv.Optional(CONF_LIBRARIES, default=[]): cv.ensure_list(cv.string_strict),
cv.Optional('esphome_core_version'): cv.invalid("The esphome_core_version option has been "
@@ -153,13 +171,31 @@ def preload_core_config(config):
CORE.build_path = CORE.relative_config_path(out2[CONF_BUILD_PATH])
def include_file(path, basename):
parts = basename.split(os.path.sep)
dst = CORE.relative_src_path(*parts)
copy_file_if_changed(path, dst)
_, ext = os.path.splitext(path)
if ext in ['.h', '.hpp', '.tcc']:
# Header, add include statement
cg.add_global(cg.RawStatement(u'#include "{}"'.format(basename)))
@coroutine_with_priority(-1000.0)
def add_includes(includes):
# Add includes at the very end, so that the included files can access global variables
for include in includes:
path = CORE.relative_config_path(include)
res = os.path.relpath(path, CORE.relative_build_path('src')).replace(os.path.sep, '/')
cg.add_global(cg.RawStatement(u'#include "{}"'.format(res)))
if os.path.isdir(path):
# Directory, copy tree
for p in walk_files(path):
basename = os.path.relpath(p, os.path.dirname(path))
include_file(p, basename)
else:
# Copy file
basename = os.path.basename(path)
include_file(path, basename)
@coroutine_with_priority(100.0)

View File

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

View File

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

View File

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

View File

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

View File

@@ -157,6 +157,12 @@ def copy_file_if_changed(src, dst):
write_file(dst, src_text)
def walk_files(path):
for root, _, files in os.walk(path):
for name in files:
yield os.path.join(root, name)
def read_file(path):
try:
with codecs.open(path, 'r', encoding='utf-8') as f_handle:

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ 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
from esphome.core import CORE, EsphomeError
from esphome.helpers import mkdir_p, read_file, write_file_if_changed
from esphome.helpers import mkdir_p, read_file, write_file_if_changed, walk_files
from esphome.storage_json import StorageJSON, storage_path
_LOGGER = logging.getLogger(__name__)
@@ -281,12 +281,6 @@ or use the custom_components folder.
"""
def walk_files(path):
for root, _, files in os.walk(path):
for name in files:
yield os.path.join(root, name)
def copy_src_tree():
import filecmp
import shutil

View File

@@ -84,6 +84,8 @@ mqtt:
condition:
- wifi.connected:
- mqtt.connected:
- light.is_on: kitchen
- light.is_off: kitchen
then:
- lambda: |-
int data = x["my_data"];
@@ -103,6 +105,15 @@ 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
- uart.write: [0x00, 0x20, 0x30]
- uart.write: !lambda |-
return {};
i2c:
sda: 21
@@ -120,6 +131,7 @@ uart:
tx_pin: GPIO22
rx_pin: GPIO23
baud_rate: 115200
id: uart0
ota:
safe_mode: True