mirror of
https://github.com/esphome/esphome.git
synced 2025-11-13 05:15:45 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ab995d8ca | ||
|
|
4248741b11 | ||
|
|
4b8ecc7634 | ||
|
|
25d04c759c | ||
|
|
b4ec84030e | ||
|
|
29e8761373 | ||
|
|
a04299c59e | ||
|
|
d7bf3c51d9 | ||
|
|
3ddf5a4ec7 | ||
|
|
f2d6817d8a | ||
|
|
31821e6309 | ||
|
|
7f507935b1 | ||
|
|
3b1ba27043 | ||
|
|
4b7c5aa05c | ||
|
|
5fca02c712 | ||
|
|
ac0b095941 | ||
|
|
cda9bad233 | ||
|
|
41db8a1264 | ||
|
|
e7e785fd60 | ||
|
|
300d3a1f46 | ||
|
|
356554c08d | ||
|
|
ced28ad006 |
@@ -20,7 +20,7 @@ class CWWWLightOutput : public light::LightOutput {
|
|||||||
traits.set_supports_rgb_white_value(false);
|
traits.set_supports_rgb_white_value(false);
|
||||||
traits.set_supports_color_temperature(true);
|
traits.set_supports_color_temperature(true);
|
||||||
traits.set_min_mireds(this->cold_white_temperature_);
|
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;
|
return traits;
|
||||||
}
|
}
|
||||||
void write_state(light::LightState *state) override {
|
void write_state(light::LightState *state) override {
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ def to_code(config):
|
|||||||
|
|
||||||
wwhite = yield cg.get_variable(config[CONF_WARM_WHITE])
|
wwhite = yield cg.get_variable(config[CONF_WARM_WHITE])
|
||||||
cg.add(var.set_warm_white(wwhite))
|
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]))
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ template<typename... Ts> class LightIsOnCondition : public Condition<Ts...> {
|
|||||||
protected:
|
protected:
|
||||||
LightState *state_;
|
LightState *state_;
|
||||||
};
|
};
|
||||||
template<typename... Ts> class LightIsOffCondition : public Condition<LightState, Ts...> {
|
template<typename... Ts> class LightIsOffCondition : public Condition<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit LightIsOffCondition(LightState *state) : state_(state) {}
|
explicit LightIsOffCondition(LightState *state) : state_(state) {}
|
||||||
bool check(Ts... x) override { return !this->state_->current_values.is_on(); }
|
bool check(Ts... x) override { return !this->state_->current_values.is_on(); }
|
||||||
|
|||||||
@@ -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_EFFECT, CONF_BRIGHTNESS, CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, \
|
||||||
CONF_COLOR_TEMPERATURE, CONF_RANGE_FROM, CONF_RANGE_TO
|
CONF_COLOR_TEMPERATURE, CONF_RANGE_FROM, CONF_RANGE_TO
|
||||||
from .types import DimRelativeAction, ToggleAction, LightState, LightControlAction, \
|
from .types import DimRelativeAction, ToggleAction, LightState, LightControlAction, \
|
||||||
AddressableLightState, AddressableSet
|
AddressableLightState, AddressableSet, LightIsOnCondition, LightIsOffCondition
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action('light.toggle', ToggleAction, automation.maybe_simple_id({
|
@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)
|
templ = yield cg.templatable(config[CONF_WHITE], args, cg.uint8, to_exp=rgbw_to_exp)
|
||||||
cg.add(var.set_white(templ))
|
cg.add(var.set_white(templ))
|
||||||
yield var
|
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 binary_sensor_is_on_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)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ ToggleAction = light_ns.class_('ToggleAction', automation.Action)
|
|||||||
LightControlAction = light_ns.class_('LightControlAction', automation.Action)
|
LightControlAction = light_ns.class_('LightControlAction', automation.Action)
|
||||||
DimRelativeAction = light_ns.class_('DimRelativeAction', automation.Action)
|
DimRelativeAction = light_ns.class_('DimRelativeAction', automation.Action)
|
||||||
AddressableSet = light_ns.class_('AddressableSet', automation.Action)
|
AddressableSet = light_ns.class_('AddressableSet', automation.Action)
|
||||||
|
LightIsOnCondition = light_ns.class_('LightIsOnCondition', automation.Condition)
|
||||||
|
LightIsOffCondition = light_ns.class_('LightIsOffCondition', automation.Condition)
|
||||||
|
|
||||||
# Effects
|
# Effects
|
||||||
LightEffect = light_ns.class_('LightEffect')
|
LightEffect = light_ns.class_('LightEffect')
|
||||||
|
|||||||
@@ -37,4 +37,4 @@ def to_code(config):
|
|||||||
|
|
||||||
wwhite = yield cg.get_variable(config[CONF_WARM_WHITE])
|
wwhite = yield cg.get_variable(config[CONF_WARM_WHITE])
|
||||||
cg.add(var.set_warm_white(wwhite))
|
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]))
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class RGBWWLightOutput : public light::LightOutput {
|
|||||||
traits.set_supports_rgb_white_value(true);
|
traits.set_supports_rgb_white_value(true);
|
||||||
traits.set_supports_color_temperature(true);
|
traits.set_supports_color_temperature(true);
|
||||||
traits.set_min_mireds(this->cold_white_temperature_);
|
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;
|
return traits;
|
||||||
}
|
}
|
||||||
void write_state(light::LightState *state) override {
|
void write_state(light::LightState *state) override {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class SunTrigger : public Trigger<>, public PollingComponent, public Parented<Su
|
|||||||
crossed = this->last_elevation_ >= this->elevation_ && this->elevation_ > current;
|
crossed = this->last_elevation_ >= this->elevation_ && this->elevation_ > current;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crossed) {
|
if (crossed && !isnan(this->last_elevation_)) {
|
||||||
this->trigger();
|
this->trigger();
|
||||||
}
|
}
|
||||||
this->last_elevation_ = current;
|
this->last_elevation_ = current;
|
||||||
@@ -111,7 +111,7 @@ class SunTrigger : public Trigger<>, public PollingComponent, public Parented<Su
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool sunrise_;
|
bool sunrise_;
|
||||||
double last_elevation_;
|
double last_elevation_{NAN};
|
||||||
double elevation_;
|
double elevation_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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({
|
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_LUX, ICON_BRIGHTNESS_5, 1).extend({
|
||||||
cv.GenerateID(): cv.declare_id(TSL2561Sensor),
|
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_GAIN, default='1X'): cv.enum(GAINS, upper=True),
|
||||||
cv.Optional(CONF_IS_CS_PACKAGE, default=False): cv.boolean,
|
cv.Optional(CONF_IS_CS_PACKAGE, default=False): cv.boolean,
|
||||||
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x39))
|
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x39))
|
||||||
|
|||||||
@@ -1,15 +1,27 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome import pins
|
from esphome import pins, automation
|
||||||
from esphome.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN, CONF_UART_ID
|
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.core import CORE, coroutine
|
||||||
|
from esphome.py_compat import text_type, binary_type, char_to_byte
|
||||||
|
|
||||||
uart_ns = cg.esphome_ns.namespace('uart')
|
uart_ns = cg.esphome_ns.namespace('uart')
|
||||||
UARTComponent = uart_ns.class_('UARTComponent', cg.Component)
|
UARTComponent = uart_ns.class_('UARTComponent', cg.Component)
|
||||||
UARTDevice = uart_ns.class_('UARTDevice')
|
UARTDevice = uart_ns.class_('UARTDevice')
|
||||||
|
UARTWriteAction = uart_ns.class_('UARTWriteAction', automation.Action)
|
||||||
MULTI_CONF = True
|
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):
|
def validate_rx_pin(value):
|
||||||
value = pins.input_pin(value)
|
value = pins.input_pin(value)
|
||||||
if CORE.is_esp8266 and value >= 16:
|
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])
|
parent = yield cg.get_variable(config[CONF_UART_ID])
|
||||||
cg.add(var.set_uart_parent(parent))
|
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
|
||||||
|
|||||||
36
esphome/components/uart/automation.h
Normal file
36
esphome/components/uart/automation.h
Normal 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
|
||||||
@@ -3,27 +3,17 @@ import esphome.config_validation as cv
|
|||||||
from esphome.components import switch, uart
|
from esphome.components import switch, uart
|
||||||
from esphome.const import CONF_DATA, CONF_ID, CONF_INVERTED
|
from esphome.const import CONF_DATA, CONF_ID, CONF_INVERTED
|
||||||
from esphome.core import HexInt
|
from esphome.core import HexInt
|
||||||
from esphome.py_compat import text_type, binary_type, char_to_byte
|
from esphome.py_compat import binary_type, char_to_byte
|
||||||
from .. import uart_ns
|
from .. import uart_ns, validate_raw_data
|
||||||
|
|
||||||
DEPENDENCIES = ['uart']
|
DEPENDENCIES = ['uart']
|
||||||
|
|
||||||
UARTSwitch = uart_ns.class_('UARTSwitch', switch.Switch, uart.UARTDevice, cg.Component)
|
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({
|
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
|
||||||
cv.GenerateID(): cv.declare_id(UARTSwitch),
|
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!"),
|
cv.Optional(CONF_INVERTED): cv.invalid("UART switches do not support inverted mode!"),
|
||||||
}).extend(uart.UART_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)
|
}).extend(uart.UART_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class UARTComponent : public Component, public Stream {
|
|||||||
void write_byte(uint8_t data);
|
void write_byte(uint8_t data);
|
||||||
|
|
||||||
void write_array(const uint8_t *data, size_t len);
|
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);
|
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_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 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); }
|
void write_str(const char *str) { this->parent_->write_str(str); }
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ MODELS = {
|
|||||||
'2.90in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN),
|
'2.90in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN),
|
||||||
'2.70in': ('b', WaveshareEPaper2P7In),
|
'2.70in': ('b', WaveshareEPaper2P7In),
|
||||||
'4.20in': ('b', WaveshareEPaper4P2In),
|
'4.20in': ('b', WaveshareEPaper4P2In),
|
||||||
'7.50in': ('b', WaveshareEPaperTypeBModel),
|
'7.50in': ('b', WaveshareEPaper7P5In),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -612,9 +612,9 @@ def _format_vol_invalid(ex, config):
|
|||||||
else:
|
else:
|
||||||
message += u'[{}] is an invalid option for [{}]. Please check the indentation.'.format(
|
message += u'[{}] is an invalid option for [{}]. Please check the indentation.'.format(
|
||||||
ex.path[-1], paren)
|
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)
|
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)
|
message += u"'{}' is a required option for [{}].".format(ex.path[-1], paren)
|
||||||
else:
|
else:
|
||||||
message += humanize_error(config, ex)
|
message += humanize_error(config, ex)
|
||||||
|
|||||||
@@ -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, \
|
from esphome.core import CORE, HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \
|
||||||
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes
|
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes
|
||||||
from esphome.helpers import list_starts_with
|
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
|
from esphome.voluptuous_schema import _Schema
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -617,9 +617,9 @@ if IS_PY2:
|
|||||||
# Override voluptuous invalid to unicode for py2
|
# Override voluptuous invalid to unicode for py2
|
||||||
def _vol_invalid_unicode(self):
|
def _vol_invalid_unicode(self):
|
||||||
path = u' @ data[%s]' % u']['.join(map(repr, self.path)) \
|
path = u' @ data[%s]' % u']['.join(map(repr, self.path)) \
|
||||||
if self.path else ''
|
if self.path else u''
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
output = self.message
|
output = decode_text(self.message)
|
||||||
if self.error_type:
|
if self.error_type:
|
||||||
output += u' for ' + self.error_type
|
output += u' for ' + self.error_type
|
||||||
return output + path
|
return output + path
|
||||||
@@ -1210,13 +1210,14 @@ def validate_registry(name, registry):
|
|||||||
return ensure_list(validate_registry_entry(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)
|
validator = All(*validators)
|
||||||
|
|
||||||
def validate(value):
|
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(value)
|
||||||
return validator({CONF_VALUE: value})
|
return validator({key: value})
|
||||||
|
|
||||||
return validate
|
return validate
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
MAJOR_VERSION = 1
|
MAJOR_VERSION = 1
|
||||||
MINOR_VERSION = 13
|
MINOR_VERSION = 13
|
||||||
PATCH_VERSION = '0b5'
|
PATCH_VERSION = '1'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
|
|
||||||
|
|||||||
@@ -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, \
|
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
|
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.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
|
from esphome.pins import ESP8266_FLASH_SIZES, ESP8266_LD_SCRIPTS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -59,6 +60,7 @@ PLATFORMIO_ESP8266_LUT = {
|
|||||||
PLATFORMIO_ESP32_LUT = {
|
PLATFORMIO_ESP32_LUT = {
|
||||||
'1.0.0': 'espressif32@1.4.0',
|
'1.0.0': 'espressif32@1.4.0',
|
||||||
'1.0.1': 'espressif32@1.6.0',
|
'1.0.1': 'espressif32@1.6.0',
|
||||||
|
'1.0.2': 'espressif32@1.8.0',
|
||||||
'RECOMMENDED': 'espressif32@1.6.0',
|
'RECOMMENDED': 'espressif32@1.6.0',
|
||||||
'LATEST': 'espressif32',
|
'LATEST': 'espressif32',
|
||||||
'DEV': ARDUINO_VERSION_ESP32_DEV,
|
'DEV': ARDUINO_VERSION_ESP32_DEV,
|
||||||
@@ -91,6 +93,22 @@ def default_build_path():
|
|||||||
return CORE.name
|
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({
|
CONFIG_SCHEMA = cv.Schema({
|
||||||
cv.Required(CONF_NAME): cv.valid_name,
|
cv.Required(CONF_NAME): cv.valid_name,
|
||||||
cv.Required(CONF_PLATFORM): cv.one_of('ESP8266', 'ESP32', upper=True),
|
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.Optional(CONF_ON_LOOP): automation.validate_automation({
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoopTrigger),
|
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(CONF_LIBRARIES, default=[]): cv.ensure_list(cv.string_strict),
|
||||||
|
|
||||||
cv.Optional('esphome_core_version'): cv.invalid("The esphome_core_version option has been "
|
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])
|
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)
|
@coroutine_with_priority(-1000.0)
|
||||||
def add_includes(includes):
|
def add_includes(includes):
|
||||||
# Add includes at the very end, so that the included files can access global variables
|
# Add includes at the very end, so that the included files can access global variables
|
||||||
for include in includes:
|
for include in includes:
|
||||||
path = CORE.relative_config_path(include)
|
path = CORE.relative_config_path(include)
|
||||||
res = os.path.relpath(path, CORE.relative_build_path('src')).replace(os.path.sep, '/')
|
if os.path.isdir(path):
|
||||||
cg.add_global(cg.RawStatement(u'#include "{}"'.format(res)))
|
# 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)
|
@coroutine_with_priority(100.0)
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
M.AutoInit(document.body);
|
M.AutoInit(document.body);
|
||||||
});
|
});
|
||||||
let wsProtocol = "ws:";
|
const loc = window.location;
|
||||||
if (window.location.protocol === "https:") {
|
const wsLoc = new URL("./",`${loc.protocol}//${loc.host}${loc.pathname}`);
|
||||||
wsProtocol = 'wss:';
|
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 =============================
|
// ============================= Color Log Parsing =============================
|
||||||
const initializeColorState = () => {
|
const initializeColorState = () => {
|
||||||
|
|||||||
@@ -469,7 +469,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="footer-copyright">
|
<div class="footer-copyright">
|
||||||
<div class="container">
|
<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>
|
<a class="grey-text text-lighten-4 right" href="{{ docs_link }}" target="_blank" rel="noreferrer">ESPHome {{ version }} Documentation</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="footer-copyright">
|
<div class="footer-copyright">
|
||||||
<div class="container">
|
<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 }}"
|
<a class="grey-text text-lighten-4 right" href="{{ docs_link }}"
|
||||||
target="_blank">ESPHome {{ version }} Documentation</a>
|
target="_blank">ESPHome {{ version }} Documentation</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -157,6 +157,12 @@ def copy_file_if_changed(src, dst):
|
|||||||
write_file(dst, src_text)
|
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):
|
def read_file(path):
|
||||||
try:
|
try:
|
||||||
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
|
from esphome.py_compat import IS_PY2
|
||||||
from esphome.util import run_external_command, run_external_process
|
from esphome.util import run_external_command, run_external_process
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -17,12 +18,10 @@ def patch_structhash():
|
|||||||
# removed/added. This might have unintended consequences, but this improves compile
|
# removed/added. This might have unintended consequences, but this improves compile
|
||||||
# times greatly when adding/removing components and a simple clean build solves
|
# times greatly when adding/removing components and a simple clean build solves
|
||||||
# all issues
|
# all issues
|
||||||
|
# pylint: disable=no-member,no-name-in-module
|
||||||
from platformio.commands import run
|
from platformio.commands import run
|
||||||
from platformio import util
|
from platformio import util
|
||||||
try:
|
|
||||||
from platformio.util import get_project_dir
|
from platformio.util import get_project_dir
|
||||||
except ImportError:
|
|
||||||
from platformio.project.helpers import get_project_dir
|
|
||||||
from os.path import join, isdir, getmtime, isfile
|
from os.path import join, isdir, getmtime, isfile
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
|
|
||||||
@@ -69,6 +68,7 @@ def run_platformio_cli(*args, **kwargs):
|
|||||||
if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
|
if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
|
||||||
import platformio.__main__
|
import platformio.__main__
|
||||||
try:
|
try:
|
||||||
|
if IS_PY2:
|
||||||
patch_structhash()
|
patch_structhash()
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
# Ignore when patch fails
|
# Ignore when patch fails
|
||||||
|
|||||||
@@ -78,8 +78,12 @@ def indexbytes(buf, i):
|
|||||||
if IS_PY2:
|
if IS_PY2:
|
||||||
def decode_text(data, encoding='utf-8', errors='strict'):
|
def decode_text(data, encoding='utf-8', errors='strict'):
|
||||||
# type: (str, str, str) -> unicode
|
# type: (str, str, str) -> unicode
|
||||||
|
if isinstance(data, unicode):
|
||||||
|
return data
|
||||||
return unicode(data, encoding=encoding, errors=errors)
|
return unicode(data, encoding=encoding, errors=errors)
|
||||||
else:
|
else:
|
||||||
def decode_text(data, encoding='utf-8', errors='strict'):
|
def decode_text(data, encoding='utf-8', errors='strict'):
|
||||||
# type: (bytes, str, str) -> str
|
# type: (bytes, str, str) -> str
|
||||||
|
if isinstance(data, str):
|
||||||
|
return data
|
||||||
return data.decode(encoding=encoding, errors=errors)
|
return data.decode(encoding=encoding, errors=errors)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from esphome.config import iter_components
|
|||||||
from esphome.const import CONF_BOARD_FLASH_MODE, CONF_ESPHOME, CONF_PLATFORMIO_OPTIONS, \
|
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
|
||||||
from esphome.core import CORE, EsphomeError
|
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
|
from esphome.storage_json import StorageJSON, storage_path
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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():
|
def copy_src_tree():
|
||||||
import filecmp
|
import filecmp
|
||||||
import shutil
|
import shutil
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ mqtt:
|
|||||||
condition:
|
condition:
|
||||||
- wifi.connected:
|
- wifi.connected:
|
||||||
- mqtt.connected:
|
- mqtt.connected:
|
||||||
|
- light.is_on: kitchen
|
||||||
|
- light.is_off: kitchen
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
int data = x["my_data"];
|
int data = x["my_data"];
|
||||||
@@ -103,6 +105,12 @@ mqtt:
|
|||||||
- light.control:
|
- light.control:
|
||||||
id: living_room_lights
|
id: living_room_lights
|
||||||
brightness: !lambda 'return id(living_room_lights).current_values.get_brightness() + 0.5;'
|
brightness: !lambda 'return id(living_room_lights).current_values.get_brightness() + 0.5;'
|
||||||
|
- uart.write:
|
||||||
|
id: uart0
|
||||||
|
data: Hello World
|
||||||
|
- uart.write: [0x00, 0x20, 0x30]
|
||||||
|
- uart.write: !lambda |-
|
||||||
|
return {};
|
||||||
|
|
||||||
i2c:
|
i2c:
|
||||||
sda: 21
|
sda: 21
|
||||||
@@ -120,6 +128,7 @@ uart:
|
|||||||
tx_pin: GPIO22
|
tx_pin: GPIO22
|
||||||
rx_pin: GPIO23
|
rx_pin: GPIO23
|
||||||
baud_rate: 115200
|
baud_rate: 115200
|
||||||
|
id: uart0
|
||||||
|
|
||||||
ota:
|
ota:
|
||||||
safe_mode: True
|
safe_mode: True
|
||||||
|
|||||||
Reference in New Issue
Block a user