1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-02 08:01:50 +00:00

Compare commits

...

27 Commits

Author SHA1 Message Date
Jesse Hills
b8c27bc17d Merge pull request #4905 from esphome/bump-2023.5.5
2023.5.5
2023-05-29 10:25:22 +12:00
Jesse Hills
1057ac4db7 Bump version to 2023.5.5 2023-05-29 09:42:12 +12:00
Jesse Hills
69f5674d9e Fix version printing not breaking yaml parsing (#4904) 2023-05-29 09:42:12 +12:00
Keith Burzinski
b723728177 Merge pull request #4889 from esphome/bump-2023.5.4
2023.5.4
2023-05-24 17:21:24 -05:00
Keith Burzinski
316171491f Bump version to 2023.5.4 2023-05-24 15:58:54 -05:00
Jesse Hills
91ff502872 Fix esp32_rmt_led_strip color modes (#4886) 2023-05-24 15:58:53 -05:00
Samuel Sieb
6e414180e0 fix modbus sending FP32_R values (#4882) 2023-05-24 15:58:53 -05:00
Jesse Hills
7d2ae4e252 Print ESPHome version when running commands (#4883) 2023-05-24 15:58:53 -05:00
Davrosx
fb4cb07c6f Update cover.h for compile errors with stop() (#4879) 2023-05-24 15:58:53 -05:00
Fabian
19f91a7deb [internal_temperature] ESP32-S3 needs ESP IDF V4.4.3 or higher (#4873)
Co-authored-by: Your Name <you@example.com>
2023-05-24 15:58:53 -05:00
Keith Burzinski
3807350c61 Merge pull request #4877 from esphome/bump-2023.5.3
2023.5.3
2023-05-22 17:25:56 -05:00
Keith Burzinski
9d2467cf62 Bump version to 2023.5.3 2023-05-22 16:53:10 -05:00
Fabian
d2480d3194 [PSRam] Change log unit to KB to minimize rounding error. (#4872)
Co-authored-by: Your Name <you@example.com>
2023-05-22 16:53:10 -05:00
Jesse Hills
148eb03d13 Allow microphone channel to be specified in config (#4871) 2023-05-22 16:53:10 -05:00
Jesse Hills
70aa5d0f6c Merge pull request #4870 from esphome/bump-2023.5.2
2023.5.2
2023-05-22 12:15:07 +12:00
Jesse Hills
8fcec8e2cb Bump version to 2023.5.2 2023-05-22 11:31:30 +12:00
Stefan Rado
2d3b48f86f Fix i2s_audio media_player mutex acquisition (#4867)
Co-authored-by: Rajan Patel <rpatel3001@gmail.com>
2023-05-22 11:31:30 +12:00
Jesse Hills
99c10bc6de Merge pull request #4852 from esphome/bump-2023.5.1
2023.5.1
2023-05-18 14:27:55 +12:00
Jesse Hills
f30f20db86 Bump version to 2023.5.1 2023-05-18 13:00:37 +12:00
Keith Burzinski
9bf946e196 Sprinkler fixes (#4816) 2023-05-18 13:00:36 +12:00
Jesse Hills
bfaad1f28d Remove i2c dependency from ttp229_bsf (#4851) 2023-05-18 13:00:36 +12:00
Jesse Hills
f90e9ba871 Merge pull request #4846 from esphome/bump-2023.5.0
2023.5.0
2023-05-17 13:17:10 +12:00
Jesse Hills
726bdd7be2 Bump version to 2023.5.0 2023-05-17 12:45:42 +12:00
Jesse Hills
52db40eb41 Merge pull request #4845 from esphome/bump-2023.5.0b5
2023.5.0b5
2023-05-17 12:04:22 +12:00
Jesse Hills
3c371a0c59 Bump version to 2023.5.0b5 2023-05-17 09:57:36 +12:00
Samuel Sieb
c941bc4109 handle Wiegand 8-bit keys (#4837)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
2023-05-17 09:57:35 +12:00
Samuel Sieb
cc76e5353c support sending keys to the collector (#4838)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
2023-05-17 09:57:35 +12:00
20 changed files with 241 additions and 128 deletions

View File

@@ -932,6 +932,8 @@ def run_esphome(argv):
_LOGGER.error(e, exc_info=args.verbose)
return 1
_LOGGER.info("ESPHome %s", const.__version__)
for conf_path in args.configuration:
if any(os.path.basename(conf_path) == x for x in SECRETS_FILES):
_LOGGER.warning("Skipping secrets file %s", conf_path)

View File

@@ -140,8 +140,9 @@ class Cover : public EntityBase, public EntityBase_DeviceClass {
/** Stop the cover.
*
* This is a legacy method and may be removed later, please use `.make_call()` instead.
* As per solution from issue #2885 the call should include perform()
*/
ESPDEPRECATED("stop() is deprecated, use make_call().set_command_stop() instead.", "2021.9")
ESPDEPRECATED("stop() is deprecated, use make_call().set_command_stop().perform() instead.", "2021.9")
void stop();
void add_on_state_callback(std::function<void()> &&f);

View File

@@ -34,7 +34,7 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight {
light::LightTraits get_traits() override {
auto traits = light::LightTraits();
if (this->is_rgbw_) {
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::RGB_WHITE});
traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
} else {
traits.set_supported_color_modes({light::ColorMode::RGB});
}

View File

@@ -133,7 +133,7 @@ void I2SAudioMediaPlayer::play_() {
void I2SAudioMediaPlayer::start() { this->i2s_state_ = I2S_STATE_STARTING; }
void I2SAudioMediaPlayer::start_() {
if (this->parent_->try_lock()) {
if (!this->parent_->try_lock()) {
return; // Waiting for another i2s to return lock
}
@@ -156,6 +156,7 @@ void I2SAudioMediaPlayer::start_() {
#if SOC_I2S_SUPPORTS_DAC
}
#endif
this->i2s_state_ = I2S_STATE_RUNNING;
this->high_freq_.start();
this->audio_->setVolume(remap<uint8_t, float>(this->volume, 0.0f, 1.0f, 0, 21));
@@ -218,6 +219,12 @@ void I2SAudioMediaPlayer::dump_config() {
default:
break;
}
} else {
#endif
ESP_LOGCONFIG(TAG, " External DAC channels: %d", this->external_dac_channels_);
ESP_LOGCONFIG(TAG, " I2S DOUT Pin: %d", this->dout_pin_);
LOG_PIN(" Mute Pin: ", this->mute_pin_);
#if SOC_I2S_SUPPORTS_DAC
}
#endif
}

View File

@@ -2,7 +2,7 @@ import esphome.config_validation as cv
import esphome.codegen as cg
from esphome import pins
from esphome.const import CONF_ID, CONF_NUMBER
from esphome.const import CONF_CHANNEL, CONF_ID, CONF_NUMBER
from esphome.components import microphone, esp32
from esphome.components.adc import ESP32_VARIANT_ADC1_PIN_TO_CHANNEL, validate_adc_pin
@@ -25,6 +25,12 @@ I2SAudioMicrophone = i2s_audio_ns.class_(
"I2SAudioMicrophone", I2SAudioIn, microphone.Microphone, cg.Component
)
i2s_channel_fmt_t = cg.global_ns.enum("i2s_channel_fmt_t")
CHANNELS = {
"left": i2s_channel_fmt_t.I2S_CHANNEL_FMT_ONLY_LEFT,
"right": i2s_channel_fmt_t.I2S_CHANNEL_FMT_ONLY_RIGHT,
}
INTERNAL_ADC_VARIANTS = [esp32.const.VARIANT_ESP32]
PDM_VARIANTS = [esp32.const.VARIANT_ESP32, esp32.const.VARIANT_ESP32S3]
@@ -47,6 +53,7 @@ BASE_SCHEMA = microphone.MICROPHONE_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(I2SAudioMicrophone),
cv.GenerateID(CONF_I2S_AUDIO_ID): cv.use_id(I2SAudioComponent),
cv.Optional(CONF_CHANNEL, default="right"): cv.enum(CHANNELS),
}
).extend(cv.COMPONENT_SCHEMA)
@@ -86,4 +93,6 @@ async def to_code(config):
cg.add(var.set_din_pin(config[CONF_I2S_DIN_PIN]))
cg.add(var.set_pdm(config[CONF_PDM]))
cg.add(var.set_channel(CHANNELS[config[CONF_CHANNEL]]))
await microphone.register_microphone(var, config)

View File

@@ -49,7 +49,7 @@ void I2SAudioMicrophone::start_() {
.mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 16000,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
.channel_format = this->channel_,
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 4,

View File

@@ -28,6 +28,8 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub
}
#endif
void set_channel(i2s_channel_fmt_t channel) { this->channel_ = channel; }
protected:
void start_();
void stop_();
@@ -40,6 +42,7 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub
#endif
bool pdm_{false};
std::vector<uint8_t> buffer_;
i2s_channel_fmt_t channel_;
HighFrequencyLoopRequester high_freq_;
};

View File

@@ -33,6 +33,10 @@ void InternalTemperatureSensor::update() {
temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
temp_sensor_set_config(tsens);
temp_sensor_start();
#if defined(USE_ESP32_VARIANT_ESP32S3) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 3))
#error \
"ESP32-S3 internal temperature sensor requires ESP IDF V4.4.3 or higher. See https://github.com/esphome/issues/issues/4271"
#endif
esp_err_t result = temp_sensor_read_celsius(&temperature);
temp_sensor_stop();
success = (result == ESP_OK);

View File

@@ -1,18 +1,45 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.components.esp32 import get_esp32_variant
from esphome.components.esp32.const import (
VARIANT_ESP32S3,
)
from esphome.const import (
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
DEVICE_CLASS_TEMPERATURE,
ENTITY_CATEGORY_DIAGNOSTIC,
KEY_CORE,
KEY_FRAMEWORK_VERSION,
)
from esphome.core import CORE
internal_temperature_ns = cg.esphome_ns.namespace("internal_temperature")
InternalTemperatureSensor = internal_temperature_ns.class_(
"InternalTemperatureSensor", sensor.Sensor, cg.PollingComponent
)
def validate_config(config):
if CORE.is_esp32:
variant = get_esp32_variant()
if variant == VARIANT_ESP32S3:
if CORE.using_arduino and CORE.data[KEY_CORE][
KEY_FRAMEWORK_VERSION
] < cv.Version(2, 0, 6):
raise cv.Invalid(
"ESP32-S3 Internal Temperature Sensor requires framework version 2.0.6 or higher. See <https://github.com/esphome/issues/issues/4271>."
)
if CORE.using_esp_idf and CORE.data[KEY_CORE][
KEY_FRAMEWORK_VERSION
] < cv.Version(4, 4, 3):
raise cv.Invalid(
"ESP32-S3 Internal Temperature Sensor requires framework version 4.4.3 or higher. See <https://github.com/esphome/issues/issues/4271>."
)
return config
CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(
InternalTemperatureSensor,
@@ -23,6 +50,7 @@ CONFIG_SCHEMA = cv.All(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
).extend(cv.polling_component_schema("60s")),
cv.only_on(["esp32", "rp2040"]),
validate_config,
)

View File

@@ -33,7 +33,7 @@ CONFIG_SCHEMA = cv.All(
cv.COMPONENT_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(KeyCollector),
cv.GenerateID(CONF_SOURCE_ID): cv.use_id(key_provider.KeyProvider),
cv.Optional(CONF_SOURCE_ID): cv.use_id(key_provider.KeyProvider),
cv.Optional(CONF_MIN_LENGTH): cv.int_,
cv.Optional(CONF_MAX_LENGTH): cv.int_,
cv.Optional(CONF_START_KEYS): cv.string,
@@ -55,8 +55,9 @@ CONFIG_SCHEMA = cv.All(
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_provider(source))
if CONF_SOURCE_ID in config:
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_provider(source))
if CONF_MIN_LENGTH in config:
cg.add(var.set_min_length(config[CONF_MIN_LENGTH]))
if CONF_MAX_LENGTH in config:

View File

@@ -52,6 +52,8 @@ void KeyCollector::clear(bool progress_update) {
this->progress_trigger_->trigger(this->result_, 0);
}
void KeyCollector::send_key(uint8_t key) { this->key_pressed_(key); }
void KeyCollector::key_pressed_(uint8_t key) {
this->last_key_time_ = millis();
if (!this->start_keys_.empty() && !this->start_key_) {

View File

@@ -27,6 +27,7 @@ class KeyCollector : public Component {
void set_timeout(int timeout) { this->timeout_ = timeout; };
void clear(bool progress_update = true);
void send_key(uint8_t key);
protected:
void key_pressed_(uint8_t key);

View File

@@ -506,12 +506,12 @@ void number_to_payload(std::vector<uint16_t> &data, int64_t value, SensorValueTy
case SensorValueType::U_DWORD:
case SensorValueType::S_DWORD:
case SensorValueType::FP32:
case SensorValueType::FP32_R:
data.push_back((value & 0xFFFF0000) >> 16);
data.push_back(value & 0xFFFF);
break;
case SensorValueType::U_DWORD_R:
case SensorValueType::S_DWORD_R:
case SensorValueType::FP32_R:
data.push_back(value & 0xFFFF);
data.push_back((value & 0xFFFF0000) >> 16);
break;

View File

@@ -21,7 +21,7 @@ void PsramComponent::dump_config() {
ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available));
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
if (available) {
ESP_LOGCONFIG(TAG, " Size: %d MB", heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024 / 1024);
ESP_LOGCONFIG(TAG, " Size: %d KB", heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024);
}
#endif
}

View File

@@ -599,15 +599,6 @@ async def to_code(config):
)
cg.add(var.set_controller_auto_adv_switch(sw_aa_var))
if CONF_QUEUE_ENABLE_SWITCH in sprinkler_controller:
sw_qen_var = await switch.new_switch(
sprinkler_controller[CONF_QUEUE_ENABLE_SWITCH]
)
await cg.register_component(
sw_qen_var, sprinkler_controller[CONF_QUEUE_ENABLE_SWITCH]
)
cg.add(var.set_controller_queue_enable_switch(sw_qen_var))
if CONF_REVERSE_SWITCH in sprinkler_controller:
sw_rev_var = await switch.new_switch(
sprinkler_controller[CONF_REVERSE_SWITCH]
@@ -617,78 +608,83 @@ async def to_code(config):
)
cg.add(var.set_controller_reverse_switch(sw_rev_var))
if CONF_STANDBY_SWITCH in sprinkler_controller:
sw_stb_var = await switch.new_switch(
sprinkler_controller[CONF_STANDBY_SWITCH]
)
await cg.register_component(
sw_stb_var, sprinkler_controller[CONF_STANDBY_SWITCH]
)
cg.add(var.set_controller_standby_switch(sw_stb_var))
if CONF_STANDBY_SWITCH in sprinkler_controller:
sw_stb_var = await switch.new_switch(
sprinkler_controller[CONF_STANDBY_SWITCH]
)
await cg.register_component(
sw_stb_var, sprinkler_controller[CONF_STANDBY_SWITCH]
)
cg.add(var.set_controller_standby_switch(sw_stb_var))
if CONF_MULTIPLIER_NUMBER in sprinkler_controller:
num_mult_var = await number.new_number(
sprinkler_controller[CONF_MULTIPLIER_NUMBER],
min_value=sprinkler_controller[CONF_MULTIPLIER_NUMBER][
CONF_MIN_VALUE
],
max_value=sprinkler_controller[CONF_MULTIPLIER_NUMBER][
CONF_MAX_VALUE
],
step=sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_STEP],
if CONF_QUEUE_ENABLE_SWITCH in sprinkler_controller:
sw_qen_var = await switch.new_switch(
sprinkler_controller[CONF_QUEUE_ENABLE_SWITCH]
)
await cg.register_component(
sw_qen_var, sprinkler_controller[CONF_QUEUE_ENABLE_SWITCH]
)
cg.add(var.set_controller_queue_enable_switch(sw_qen_var))
if CONF_MULTIPLIER_NUMBER in sprinkler_controller:
num_mult_var = await number.new_number(
sprinkler_controller[CONF_MULTIPLIER_NUMBER],
min_value=sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_MIN_VALUE],
max_value=sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_MAX_VALUE],
step=sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_STEP],
)
await cg.register_component(
num_mult_var, sprinkler_controller[CONF_MULTIPLIER_NUMBER]
)
cg.add(
num_mult_var.set_initial_value(
sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_INITIAL_VALUE]
)
await cg.register_component(
num_mult_var, sprinkler_controller[CONF_MULTIPLIER_NUMBER]
)
cg.add(
num_mult_var.set_restore_value(
sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_RESTORE_VALUE]
)
cg.add(
num_mult_var.set_initial_value(
sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_INITIAL_VALUE]
)
)
cg.add(
num_mult_var.set_restore_value(
sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_RESTORE_VALUE]
)
)
if CONF_SET_ACTION in sprinkler_controller[CONF_MULTIPLIER_NUMBER]:
await automation.build_automation(
num_mult_var.get_set_trigger(),
[(float, "x")],
sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_SET_ACTION],
)
if CONF_SET_ACTION in sprinkler_controller[CONF_MULTIPLIER_NUMBER]:
await automation.build_automation(
num_mult_var.get_set_trigger(),
[(float, "x")],
sprinkler_controller[CONF_MULTIPLIER_NUMBER][CONF_SET_ACTION],
)
cg.add(var.set_controller_multiplier_number(num_mult_var))
cg.add(var.set_controller_multiplier_number(num_mult_var))
if CONF_REPEAT_NUMBER in sprinkler_controller:
num_repeat_var = await number.new_number(
sprinkler_controller[CONF_REPEAT_NUMBER],
min_value=sprinkler_controller[CONF_REPEAT_NUMBER][CONF_MIN_VALUE],
max_value=sprinkler_controller[CONF_REPEAT_NUMBER][CONF_MAX_VALUE],
step=sprinkler_controller[CONF_REPEAT_NUMBER][CONF_STEP],
)
await cg.register_component(
num_repeat_var, sprinkler_controller[CONF_REPEAT_NUMBER]
)
cg.add(
num_repeat_var.set_initial_value(
sprinkler_controller[CONF_REPEAT_NUMBER][CONF_INITIAL_VALUE]
)
)
cg.add(
num_repeat_var.set_restore_value(
sprinkler_controller[CONF_REPEAT_NUMBER][CONF_RESTORE_VALUE]
)
)
if CONF_REPEAT_NUMBER in sprinkler_controller:
num_repeat_var = await number.new_number(
sprinkler_controller[CONF_REPEAT_NUMBER],
min_value=sprinkler_controller[CONF_REPEAT_NUMBER][CONF_MIN_VALUE],
max_value=sprinkler_controller[CONF_REPEAT_NUMBER][CONF_MAX_VALUE],
step=sprinkler_controller[CONF_REPEAT_NUMBER][CONF_STEP],
)
await cg.register_component(
num_repeat_var, sprinkler_controller[CONF_REPEAT_NUMBER]
)
cg.add(
num_repeat_var.set_initial_value(
sprinkler_controller[CONF_REPEAT_NUMBER][CONF_INITIAL_VALUE]
)
)
cg.add(
num_repeat_var.set_restore_value(
sprinkler_controller[CONF_REPEAT_NUMBER][CONF_RESTORE_VALUE]
)
if CONF_SET_ACTION in sprinkler_controller[CONF_REPEAT_NUMBER]:
await automation.build_automation(
num_repeat_var.get_set_trigger(),
[(float, "x")],
sprinkler_controller[CONF_REPEAT_NUMBER][CONF_SET_ACTION],
)
if CONF_SET_ACTION in sprinkler_controller[CONF_REPEAT_NUMBER]:
await automation.build_automation(
num_repeat_var.get_set_trigger(),
[(float, "x")],
sprinkler_controller[CONF_REPEAT_NUMBER][CONF_SET_ACTION],
)
cg.add(var.set_controller_repeat_number(num_repeat_var))
cg.add(var.set_controller_repeat_number(num_repeat_var))
for valve in sprinkler_controller[CONF_VALVES]:
sw_valve_var = await switch.new_switch(valve[CONF_VALVE_SWITCH])

View File

@@ -147,22 +147,22 @@ SprinklerValveOperator::SprinklerValveOperator(SprinklerValve *valve, Sprinkler
: controller_(controller), valve_(valve) {}
void SprinklerValveOperator::loop() {
if (millis() >= this->pinned_millis_) { // dummy check
if (millis() >= this->start_millis_) { // dummy check
switch (this->state_) {
case STARTING:
if (millis() > (this->pinned_millis_ + this->start_delay_)) {
if (millis() > (this->start_millis_ + this->start_delay_)) {
this->run_(); // start_delay_ has been exceeded, so ensure both valves are on and update the state
}
break;
case ACTIVE:
if (millis() > (this->pinned_millis_ + this->start_delay_ + this->run_duration_)) {
if (millis() > (this->start_millis_ + this->start_delay_ + this->run_duration_)) {
this->stop(); // start_delay_ + run_duration_ has been exceeded, start shutting down
}
break;
case STOPPING:
if (millis() > (this->pinned_millis_ + this->stop_delay_)) {
if (millis() > (this->stop_millis_ + this->stop_delay_)) {
this->kill_(); // stop_delay_has been exceeded, ensure all valves are off
}
break;
@@ -183,11 +183,12 @@ void SprinklerValveOperator::set_controller(Sprinkler *controller) {
void SprinklerValveOperator::set_valve(SprinklerValve *valve) {
if (valve != nullptr) {
this->state_ = IDLE; // reset state
this->run_duration_ = 0; // reset to ensure the valve isn't started without updating it
this->pinned_millis_ = 0; // reset because (new) valve has not been started yet
this->kill_(); // ensure everything is off before we let go!
this->valve_ = valve; // finally, set the pointer to the new valve
this->state_ = IDLE; // reset state
this->run_duration_ = 0; // reset to ensure the valve isn't started without updating it
this->start_millis_ = 0; // reset because (new) valve has not been started yet
this->stop_millis_ = 0; // reset because (new) valve has not been started yet
this->kill_(); // ensure everything is off before we let go!
this->valve_ = valve; // finally, set the pointer to the new valve
}
}
@@ -221,7 +222,8 @@ void SprinklerValveOperator::start() {
} else {
this->run_(); // there is no start_delay_, so just start the pump and valve
}
this->pinned_millis_ = millis(); // save the time the start request was made
this->stop_millis_ = 0;
this->start_millis_ = millis(); // save the time the start request was made
}
void SprinklerValveOperator::stop() {
@@ -238,19 +240,33 @@ void SprinklerValveOperator::stop() {
if (this->pump_switch()->state()) { // if the pump is still on at this point, it may be in use...
this->valve_off_(); // ...so just switch the valve off now to ensure consistent run time
}
this->pinned_millis_ = millis(); // save the time the stop request was made
} else {
this->kill_(); // there is no stop_delay_, so just stop the pump and valve
}
this->stop_millis_ = millis(); // save the time the stop request was made
}
uint32_t SprinklerValveOperator::run_duration() { return this->run_duration_; }
uint32_t SprinklerValveOperator::run_duration() { return this->run_duration_ / 1000; }
uint32_t SprinklerValveOperator::time_remaining() {
if ((this->state_ == STARTING) || (this->state_ == ACTIVE)) {
return (this->pinned_millis_ + this->start_delay_ + this->run_duration_ - millis()) / 1000;
if (this->start_millis_ == 0) {
return this->run_duration(); // hasn't been started yet
}
return 0;
if (this->stop_millis_) {
if (this->stop_millis_ - this->start_millis_ >= this->start_delay_ + this->run_duration_) {
return 0; // valve was active for more than its configured duration, so we are done
} else {
// we're stopped; return time remaining
return (this->run_duration_ - (this->stop_millis_ - this->start_millis_)) / 1000;
}
}
auto completed_millis = this->start_millis_ + this->start_delay_ + this->run_duration_;
if (completed_millis > millis()) {
return (completed_millis - millis()) / 1000; // running now
}
return 0; // run completed
}
SprinklerState SprinklerValveOperator::state() { return this->state_; }
@@ -386,6 +402,9 @@ void Sprinkler::loop() {
for (auto &vo : this->valve_op_) {
vo.loop();
}
if (this->prev_req_.has_request() && this->prev_req_.valve_operator()->state() == IDLE) {
this->prev_req_.reset();
}
}
void Sprinkler::add_valve(SprinklerControllerSwitch *valve_sw, SprinklerControllerSwitch *enable_sw) {
@@ -732,7 +751,7 @@ bool Sprinkler::auto_advance() {
if (this->auto_adv_sw_ != nullptr) {
return this->auto_adv_sw_->state;
}
return false;
return true;
}
float Sprinkler::multiplier() {
@@ -972,7 +991,14 @@ optional<SprinklerValveRunRequestOrigin> Sprinkler::active_valve_request_is_from
return nullopt;
}
optional<size_t> Sprinkler::active_valve() { return this->active_req_.valve_as_opt(); }
optional<size_t> Sprinkler::active_valve() {
if (!this->valve_overlap_ && this->prev_req_.has_request() &&
(this->prev_req_.valve_operator()->state() == STARTING || this->prev_req_.valve_operator()->state() == ACTIVE)) {
return this->prev_req_.valve_as_opt();
}
return this->active_req_.valve_as_opt();
}
optional<size_t> Sprinkler::paused_valve() { return this->paused_valve_; }
optional<size_t> Sprinkler::queued_valve() {
@@ -1097,22 +1123,35 @@ uint32_t Sprinkler::total_cycle_time_enabled_valves() {
uint32_t Sprinkler::total_cycle_time_enabled_incomplete_valves() {
uint32_t total_time_remaining = 0;
uint32_t valve_count = 0;
uint32_t enabled_valve_count = 0;
uint32_t incomplete_valve_count = 0;
for (size_t valve = 0; valve < this->number_of_valves(); valve++) {
if (this->valve_is_enabled_(valve) && !this->valve_cycle_complete_(valve)) {
if (!this->active_valve().has_value() || (valve != this->active_valve().value())) {
total_time_remaining += this->valve_run_duration_adjusted(valve);
valve_count++;
if (this->valve_is_enabled_(valve)) {
enabled_valve_count++;
if (!this->valve_cycle_complete_(valve)) {
if (!this->active_valve().has_value() || (valve != this->active_valve().value())) {
total_time_remaining += this->valve_run_duration_adjusted(valve);
incomplete_valve_count++;
} else {
// to get here, there must be an active valve and this valve must be equal to 'valve'
if (this->active_req_.valve_operator() == nullptr) { // no SVO has been assigned yet so it hasn't started
total_time_remaining += this->valve_run_duration_adjusted(valve);
incomplete_valve_count++;
}
}
}
}
}
if (valve_count) {
if (incomplete_valve_count >= enabled_valve_count) {
incomplete_valve_count--;
}
if (incomplete_valve_count) {
if (this->valve_overlap_) {
total_time_remaining -= this->switching_delay_.value_or(0) * (valve_count - 1);
total_time_remaining -= this->switching_delay_.value_or(0) * incomplete_valve_count;
} else {
total_time_remaining += this->switching_delay_.value_or(0) * (valve_count - 1);
total_time_remaining += this->switching_delay_.value_or(0) * incomplete_valve_count;
}
}
@@ -1149,31 +1188,32 @@ optional<uint32_t> Sprinkler::time_remaining_active_valve() {
return this->active_req_.valve_operator()->time_remaining();
}
}
for (auto &vo : this->valve_op_) { // ...else return the value from the first non-IDLE SprinklerValveOperator
if (vo.state() != IDLE) {
return vo.time_remaining();
if (this->prev_req_.has_request()) { // try to return the value based on prev_req_...
if (this->prev_req_.valve_operator() != nullptr) {
return this->prev_req_.valve_operator()->time_remaining();
}
}
return nullopt;
}
optional<uint32_t> Sprinkler::time_remaining_current_operation() {
auto total_time_remaining = this->time_remaining_active_valve();
if (!this->time_remaining_active_valve().has_value() && this->state_ == IDLE) {
return nullopt;
}
if (total_time_remaining.has_value()) {
if (this->auto_advance()) {
total_time_remaining = total_time_remaining.value() + this->total_cycle_time_enabled_incomplete_valves();
total_time_remaining =
total_time_remaining.value() +
auto total_time_remaining = this->time_remaining_active_valve().value_or(0);
if (this->auto_advance()) {
total_time_remaining += this->total_cycle_time_enabled_incomplete_valves();
if (this->repeat().value_or(0) > 0) {
total_time_remaining +=
(this->total_cycle_time_enabled_valves() * (this->repeat().value_or(0) - this->repeat_count().value_or(0)));
}
if (this->queue_enabled()) {
total_time_remaining = total_time_remaining.value() + this->total_queue_time();
}
return total_time_remaining;
}
return nullopt;
if (this->queue_enabled()) {
total_time_remaining += this->total_queue_time();
}
return total_time_remaining;
}
bool Sprinkler::any_controller_is_active() {
@@ -1305,6 +1345,12 @@ optional<size_t> Sprinkler::next_valve_number_in_cycle_(const optional<size_t> f
}
void Sprinkler::load_next_valve_run_request_(const optional<size_t> first_valve) {
if (this->active_req_.has_request()) {
this->prev_req_ = this->active_req_;
} else {
this->prev_req_.reset();
}
if (this->next_req_.has_request()) {
if (!this->next_req_.run_duration()) { // ensure the run duration is set correctly for consumption later on
this->next_req_.set_run_duration(this->valve_run_duration_adjusted(this->next_req_.valve()));

View File

@@ -170,7 +170,8 @@ class SprinklerValveOperator {
uint32_t start_delay_{0};
uint32_t stop_delay_{0};
uint32_t run_duration_{0};
uint64_t pinned_millis_{0};
uint64_t start_millis_{0};
uint64_t stop_millis_{0};
Sprinkler *controller_{nullptr};
SprinklerValve *valve_{nullptr};
SprinklerState state_{IDLE};
@@ -538,15 +539,18 @@ class Sprinkler : public Component {
/// The valve run request that is currently active
SprinklerValveRunRequest active_req_;
/// The next run request for the controller to consume after active_req_ is complete
SprinklerValveRunRequest next_req_;
/// The previous run request the controller processed
SprinklerValveRunRequest prev_req_;
/// The number of the manually selected valve currently selected
optional<size_t> manual_valve_;
/// The number of the valve to resume from (if paused)
optional<size_t> paused_valve_;
/// The next run request for the controller to consume after active_req_ is complete
SprinklerValveRunRequest next_req_;
/// Set the number of times to repeat a full cycle
optional<uint32_t> target_repeats_;

View File

@@ -3,7 +3,6 @@ import esphome.config_validation as cv
from esphome import pins
from esphome.const import CONF_ID, CONF_SDO_PIN, CONF_SCL_PIN
DEPENDENCIES = ["i2c"]
AUTO_LOAD = ["binary_sensor"]
CONF_TTP229_ID = "ttp229_id"

View File

@@ -102,6 +102,16 @@ void Wiegand::loop() {
uint8_t key = KEYS[value];
this->send_key_(key);
}
} else if (count == 8) {
if ((value ^ 0xf0) >> 4 == (value & 0xf)) {
value &= 0xf;
for (auto *trigger : this->key_triggers_)
trigger->trigger(value);
if (value < 12) {
uint8_t key = KEYS[value];
this->send_key_(key);
}
}
} else {
ESP_LOGD(TAG, "received unknown %d-bit value: %llx", count, value);
}

View File

@@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2023.5.0b4"
__version__ = "2023.5.5"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"