mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 12:37:45 +01:00
Merge branch 'dev' into platform
This commit is contained in:
commit
36171bccb3
@ -63,15 +63,16 @@ Checks: >-
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-no-recursion,
|
||||
-misc-unused-parameters,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-avoid-bind,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-concat-nested-namespaces,
|
||||
-modernize-return-braced-init-list,
|
||||
-modernize-use-auto,
|
||||
-modernize-use-default-member-init,
|
||||
-modernize-use-equals-default,
|
||||
-modernize-use-trailing-return-type,
|
||||
-modernize-use-nodiscard,
|
||||
-modernize-use-nullptr,
|
||||
-modernize-use-trailing-return-type,
|
||||
-mpi-*,
|
||||
-objc-*,
|
||||
-readability-container-data-pointer,
|
||||
@ -82,6 +83,7 @@ Checks: >-
|
||||
-readability-isolate-declaration,
|
||||
-readability-magic-numbers,
|
||||
-readability-make-member-function-const,
|
||||
-readability-named-parameter,
|
||||
-readability-redundant-string-init,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-use-anyofallof,
|
||||
|
@ -354,6 +354,7 @@ esphome/components/sdl/* @clydebarrow
|
||||
esphome/components/sdm_meter/* @jesserockz @polyfaces
|
||||
esphome/components/sdp3x/* @Azimath
|
||||
esphome/components/seeed_mr24hpc1/* @limengdu
|
||||
esphome/components/seeed_mr60fda2/* @limengdu
|
||||
esphome/components/selec_meter/* @sourabhjaiswal
|
||||
esphome/components/select/* @esphome/core
|
||||
esphome/components/sen0321/* @notjj
|
||||
@ -408,6 +409,7 @@ esphome/components/substitutions/* @esphome/core
|
||||
esphome/components/sun/* @OttoWinter
|
||||
esphome/components/sun_gtil2/* @Mat931
|
||||
esphome/components/switch/* @esphome/core
|
||||
esphome/components/switch/binary_sensor/* @ssieb
|
||||
esphome/components/t6615/* @tylermenezes
|
||||
esphome/components/tc74/* @sethgirvan
|
||||
esphome/components/tca9548a/* @andreashergert1984
|
||||
|
@ -99,15 +99,17 @@ BUILD_DEPS="
|
||||
libfreetype-dev=2.12.1+dfsg-5+deb12u3
|
||||
libssl-dev=3.0.15-1~deb12u1
|
||||
libffi-dev=3.4.4-1
|
||||
libopenjp2-7=2.5.0-2
|
||||
libtiff6=4.5.0-6+deb12u1
|
||||
cargo=0.66.0+ds1-1
|
||||
pkg-config=1.8.1-1
|
||||
"
|
||||
LIB_DEPS="
|
||||
libtiff6=4.5.0-6+deb12u1
|
||||
libopenjp2-7=2.5.0-2
|
||||
"
|
||||
if [ "$TARGETARCH$TARGETVARIANT" = "arm64" ] || [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]
|
||||
then
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends $BUILD_DEPS
|
||||
apt-get install -y --no-install-recommends $BUILD_DEPS $LIB_DEPS
|
||||
fi
|
||||
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse CARGO_HOME=/root/.cargo
|
||||
|
@ -72,10 +72,9 @@ void AlarmControlPanelCall::validate_() {
|
||||
this->state_.reset();
|
||||
return;
|
||||
}
|
||||
if (state == ACP_STATE_DISARMED &&
|
||||
!(this->parent_->is_state_armed(this->parent_->get_state()) ||
|
||||
this->parent_->get_state() == ACP_STATE_PENDING || this->parent_->get_state() == ACP_STATE_ARMING ||
|
||||
this->parent_->get_state() == ACP_STATE_TRIGGERED)) {
|
||||
if (state == ACP_STATE_DISARMED && !this->parent_->is_state_armed(this->parent_->get_state()) &&
|
||||
this->parent_->get_state() != ACP_STATE_PENDING && this->parent_->get_state() != ACP_STATE_ARMING &&
|
||||
this->parent_->get_state() != ACP_STATE_TRIGGERED) {
|
||||
ESP_LOGW(TAG, "Cannot disarm when not armed");
|
||||
this->state_.reset();
|
||||
return;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace audio {
|
||||
|
@ -58,7 +58,7 @@ class BinarySensor : public EntityBase, public EntityBase_DeviceClass {
|
||||
void publish_initial_state(bool state);
|
||||
|
||||
/// The current reported state of the binary sensor.
|
||||
bool state;
|
||||
bool state{false};
|
||||
|
||||
void add_filter(Filter *filter);
|
||||
void add_filters(const std::vector<Filter *> &filters);
|
||||
|
@ -43,7 +43,7 @@ bool CSE7766Component::check_byte_() {
|
||||
uint8_t index = this->raw_data_index_;
|
||||
uint8_t byte = this->raw_data_[index];
|
||||
if (index == 0) {
|
||||
return !((byte != 0x55) && ((byte & 0xF0) != 0xF0) && (byte != 0xAA));
|
||||
return (byte == 0x55) || ((byte & 0xF0) == 0xF0) || (byte == 0xAA);
|
||||
}
|
||||
|
||||
if (index == 1) {
|
||||
|
@ -60,9 +60,7 @@ ESPTime DateTimeEntity::state_as_esptime() const {
|
||||
obj.hour = this->hour_;
|
||||
obj.minute = this->minute_;
|
||||
obj.second = this->second_;
|
||||
obj.day_of_week = 1; // Required to be valid for recalc_timestamp_local but not used.
|
||||
obj.day_of_year = 1; // Required to be valid for recalc_timestamp_local but not used.
|
||||
obj.recalc_timestamp_local(false);
|
||||
obj.recalc_timestamp_local();
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,6 @@ IsActiveCondition = display_menu_base_ns.class_(
|
||||
"IsActiveCondition", automation.Condition
|
||||
)
|
||||
|
||||
MULTI_CONF = True
|
||||
|
||||
MenuItemType = display_menu_base_ns.enum("MenuItemType")
|
||||
|
||||
MENU_ITEM_TYPES = {
|
||||
|
@ -280,7 +280,7 @@ bool DisplayMenuComponent::cursor_down_() {
|
||||
bool DisplayMenuComponent::enter_menu_() {
|
||||
this->displayed_item_->on_leave();
|
||||
this->displayed_item_ = static_cast<MenuItemMenu *>(this->get_selected_item_());
|
||||
this->selection_stack_.push_front({this->top_index_, this->cursor_index_});
|
||||
this->selection_stack_.emplace_front(this->top_index_, this->cursor_index_);
|
||||
this->cursor_index_ = this->top_index_ = 0;
|
||||
this->displayed_item_->on_enter();
|
||||
|
||||
|
@ -296,7 +296,7 @@ void Dsmr::dump_config() {
|
||||
}
|
||||
|
||||
void Dsmr::set_decryption_key(const std::string &decryption_key) {
|
||||
if (decryption_key.length() == 0) {
|
||||
if (decryption_key.empty()) {
|
||||
ESP_LOGI(TAG, "Disabling decryption");
|
||||
this->decryption_key_.clear();
|
||||
if (this->crypt_telegram_ != nullptr) {
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
|
||||
struct httpd_req;
|
||||
struct httpd_req; // NOLINT(readability-identifier-naming)
|
||||
|
||||
namespace esphome {
|
||||
namespace esp32_camera_web_server {
|
||||
|
@ -1,10 +1,9 @@
|
||||
import logging
|
||||
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
import esphome.final_validate as fv
|
||||
from esphome.components.ota import BASE_OTA_SCHEMA, ota_to_code, OTAComponent
|
||||
from esphome.components.ota import BASE_OTA_SCHEMA, OTAComponent, ota_to_code
|
||||
from esphome.config_helpers import merge_config
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_ESPHOME,
|
||||
CONF_ID,
|
||||
@ -18,6 +17,7 @@ from esphome.const import (
|
||||
CONF_VERSION,
|
||||
)
|
||||
from esphome.core import coroutine_with_priority
|
||||
import esphome.final_validate as fv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -124,7 +124,6 @@ FINAL_VALIDATE_SCHEMA = ota_esphome_final_validate
|
||||
@coroutine_with_priority(52.0)
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await ota_to_code(var, config)
|
||||
cg.add(var.set_port(config[CONF_PORT]))
|
||||
if CONF_PASSWORD in config:
|
||||
cg.add(var.set_auth_password(config[CONF_PASSWORD]))
|
||||
@ -132,3 +131,4 @@ async def to_code(config):
|
||||
cg.add_define("USE_OTA_VERSION", config[CONF_VERSION])
|
||||
|
||||
await cg.register_component(var, config)
|
||||
await ota_to_code(var, config)
|
||||
|
@ -36,6 +36,8 @@ CODEOWNERS = ["@MrMDavidson"]
|
||||
|
||||
AUTO_LOAD = ["display_menu_base"]
|
||||
|
||||
MULTI_CONF = True
|
||||
|
||||
CONFIG_SCHEMA = DISPLAY_MENU_BASE_SCHEMA.extend(
|
||||
cv.Schema(
|
||||
{
|
||||
|
@ -1069,19 +1069,17 @@ void HonClimate::fill_control_messages_queue_() {
|
||||
climate_control = this->current_hvac_settings_;
|
||||
// Beeper command
|
||||
{
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::BEEPER_STATUS,
|
||||
this->get_beeper_state() ? ZERO_BUF : ONE_BUF, 2));
|
||||
this->get_beeper_state() ? ZERO_BUF : ONE_BUF, 2);
|
||||
}
|
||||
// Health mode
|
||||
{
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::HEALTH_MODE,
|
||||
this->get_health_mode() ? ONE_BUF : ZERO_BUF, 2));
|
||||
this->get_health_mode() ? ONE_BUF : ZERO_BUF, 2);
|
||||
this->health_mode_ = (SwitchState) ((uint8_t) this->health_mode_ & 0b01);
|
||||
}
|
||||
// Climate mode
|
||||
@ -1099,51 +1097,46 @@ void HonClimate::fill_control_messages_queue_() {
|
||||
case CLIMATE_MODE_HEAT_COOL:
|
||||
new_power = true;
|
||||
buffer[1] = (uint8_t) hon_protocol::ConditioningMode::AUTO;
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::AC_MODE,
|
||||
buffer, 2));
|
||||
buffer, 2);
|
||||
fan_mode_buf[1] = this->other_modes_fan_speed_;
|
||||
break;
|
||||
case CLIMATE_MODE_HEAT:
|
||||
new_power = true;
|
||||
buffer[1] = (uint8_t) hon_protocol::ConditioningMode::HEAT;
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::AC_MODE,
|
||||
buffer, 2));
|
||||
buffer, 2);
|
||||
fan_mode_buf[1] = this->other_modes_fan_speed_;
|
||||
break;
|
||||
case CLIMATE_MODE_DRY:
|
||||
new_power = true;
|
||||
buffer[1] = (uint8_t) hon_protocol::ConditioningMode::DRY;
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::AC_MODE,
|
||||
buffer, 2));
|
||||
buffer, 2);
|
||||
fan_mode_buf[1] = this->other_modes_fan_speed_;
|
||||
break;
|
||||
case CLIMATE_MODE_FAN_ONLY:
|
||||
new_power = true;
|
||||
buffer[1] = (uint8_t) hon_protocol::ConditioningMode::FAN;
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::AC_MODE,
|
||||
buffer, 2));
|
||||
buffer, 2);
|
||||
fan_mode_buf[1] = this->other_modes_fan_speed_; // Auto doesn't work in fan only mode
|
||||
break;
|
||||
case CLIMATE_MODE_COOL:
|
||||
new_power = true;
|
||||
buffer[1] = (uint8_t) hon_protocol::ConditioningMode::COOL;
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::AC_MODE,
|
||||
buffer, 2));
|
||||
buffer, 2);
|
||||
fan_mode_buf[1] = this->other_modes_fan_speed_;
|
||||
break;
|
||||
default:
|
||||
@ -1153,11 +1146,10 @@ void HonClimate::fill_control_messages_queue_() {
|
||||
}
|
||||
// Climate power
|
||||
{
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::AC_POWER,
|
||||
new_power ? ONE_BUF : ZERO_BUF, 2));
|
||||
new_power ? ONE_BUF : ZERO_BUF, 2);
|
||||
}
|
||||
// CLimate preset
|
||||
{
|
||||
@ -1199,36 +1191,32 @@ void HonClimate::fill_control_messages_queue_() {
|
||||
}
|
||||
auto presets = this->traits_.get_supported_presets();
|
||||
if (quiet_mode_buf[1] != 0xFF) {
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::QUIET_MODE,
|
||||
quiet_mode_buf, 2));
|
||||
quiet_mode_buf, 2);
|
||||
}
|
||||
if ((fast_mode_buf[1] != 0xFF) && ((presets.find(climate::ClimatePreset::CLIMATE_PRESET_BOOST) != presets.end()))) {
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::FAST_MODE,
|
||||
fast_mode_buf, 2));
|
||||
fast_mode_buf, 2);
|
||||
}
|
||||
if ((away_mode_buf[1] != 0xFF) && ((presets.find(climate::ClimatePreset::CLIMATE_PRESET_AWAY) != presets.end()))) {
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::TEN_DEGREE,
|
||||
away_mode_buf, 2));
|
||||
away_mode_buf, 2);
|
||||
}
|
||||
}
|
||||
// Target temperature
|
||||
if (climate_control.target_temperature.has_value() && (this->mode != ClimateMode::CLIMATE_MODE_FAN_ONLY)) {
|
||||
uint8_t buffer[2] = {0x00, 0x00};
|
||||
buffer[1] = ((uint8_t) climate_control.target_temperature.value()) - 16;
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::SET_POINT,
|
||||
buffer, 2));
|
||||
buffer, 2);
|
||||
}
|
||||
// Vertical swing mode
|
||||
if (climate_control.swing_mode.has_value()) {
|
||||
@ -1248,16 +1236,14 @@ void HonClimate::fill_control_messages_queue_() {
|
||||
case CLIMATE_SWING_BOTH:
|
||||
break;
|
||||
}
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::HORIZONTAL_SWING_MODE,
|
||||
horizontal_swing_buf, 2));
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
horizontal_swing_buf, 2);
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::VERTICAL_SWING_MODE,
|
||||
vertical_swing_buf, 2));
|
||||
vertical_swing_buf, 2);
|
||||
}
|
||||
// Fan mode
|
||||
if (climate_control.fan_mode.has_value()) {
|
||||
@ -1280,11 +1266,10 @@ void HonClimate::fill_control_messages_queue_() {
|
||||
break;
|
||||
}
|
||||
if (fan_mode_buf[1] != 0xFF) {
|
||||
this->control_messages_queue_.push(
|
||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||
this->control_messages_queue_.emplace(haier_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||
(uint8_t) hon_protocol::DataParameters::FAN_MODE,
|
||||
fan_mode_buf, 2));
|
||||
fan_mode_buf, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ void HomeassistantNumber::min_retrieved_(const std::string &min) {
|
||||
auto min_value = parse_number<float>(min);
|
||||
if (!min_value.has_value()) {
|
||||
ESP_LOGE(TAG, "'%s': Can't convert 'min' value '%s' to number!", this->entity_id_.c_str(), min.c_str());
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "'%s': Min retrieved: %s", get_name().c_str(), min.c_str());
|
||||
this->traits.set_min_value(min_value.value());
|
||||
@ -36,6 +37,7 @@ void HomeassistantNumber::max_retrieved_(const std::string &max) {
|
||||
auto max_value = parse_number<float>(max);
|
||||
if (!max_value.has_value()) {
|
||||
ESP_LOGE(TAG, "'%s': Can't convert 'max' value '%s' to number!", this->entity_id_.c_str(), max.c_str());
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "'%s': Max retrieved: %s", get_name().c_str(), max.c_str());
|
||||
this->traits.set_max_value(max_value.value());
|
||||
@ -45,6 +47,7 @@ void HomeassistantNumber::step_retrieved_(const std::string &step) {
|
||||
auto step_value = parse_number<float>(step);
|
||||
if (!step_value.has_value()) {
|
||||
ESP_LOGE(TAG, "'%s': Can't convert 'step' value '%s' to number!", this->entity_id_.c_str(), step.c_str());
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "'%s': Step Retrieved %s", get_name().c_str(), step.c_str());
|
||||
this->traits.set_step(step_value.value());
|
||||
|
@ -15,7 +15,7 @@ static const char *const TAG = "honeywellabp2";
|
||||
void HONEYWELLABP2Sensor::read_sensor_data() {
|
||||
if (this->read(raw_data_, 7) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Communication with ABP2 failed!");
|
||||
this->mark_failed();
|
||||
this->status_set_warning("couldn't read sensor data");
|
||||
return;
|
||||
}
|
||||
float press_counts = encode_uint24(raw_data_[1], raw_data_[2], raw_data_[3]); // calculate digital pressure counts
|
||||
@ -25,12 +25,13 @@ void HONEYWELLABP2Sensor::read_sensor_data() {
|
||||
(this->max_pressure_ - this->min_pressure_)) +
|
||||
this->min_pressure_;
|
||||
this->last_temperature_ = (temp_counts * 200 / 16777215) - 50;
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
void HONEYWELLABP2Sensor::start_measurement() {
|
||||
if (this->write(i2c_cmd_, 3) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Communication with ABP2 failed!");
|
||||
this->mark_failed();
|
||||
this->status_set_warning("couldn't start measurement");
|
||||
return;
|
||||
}
|
||||
this->measurement_running_ = true;
|
||||
@ -39,7 +40,7 @@ void HONEYWELLABP2Sensor::start_measurement() {
|
||||
bool HONEYWELLABP2Sensor::is_measurement_ready() {
|
||||
if (this->read(raw_data_, 1) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Communication with ABP2 failed!");
|
||||
this->mark_failed();
|
||||
this->status_set_warning("couldn't check measurement");
|
||||
return false;
|
||||
}
|
||||
if ((raw_data_[0] & (0x1 << STATUS_BIT_BUSY)) > 0) {
|
||||
@ -52,7 +53,7 @@ bool HONEYWELLABP2Sensor::is_measurement_ready() {
|
||||
void HONEYWELLABP2Sensor::measurement_timeout() {
|
||||
ESP_LOGE(TAG, "Timeout!");
|
||||
this->measurement_running_ = false;
|
||||
this->mark_failed();
|
||||
this->status_set_warning("measurement timed out");
|
||||
}
|
||||
|
||||
float HONEYWELLABP2Sensor::get_pressure() { return this->last_pressure_; }
|
||||
@ -79,7 +80,7 @@ void HONEYWELLABP2Sensor::update() {
|
||||
ESP_LOGV(TAG, "Update Honeywell ABP2 Sensor");
|
||||
|
||||
this->start_measurement();
|
||||
this->set_timeout("meas_timeout", 50, [this] { this->measurement_timeout(); });
|
||||
this->set_timeout("meas_timeout", 100, [this] { this->measurement_timeout(); });
|
||||
}
|
||||
|
||||
void HONEYWELLABP2Sensor::dump_config() {
|
||||
|
@ -189,7 +189,7 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||
|
||||
if (container == nullptr) {
|
||||
for (auto *trigger : this->error_triggers_)
|
||||
trigger->trigger(x...);
|
||||
trigger->trigger();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,9 @@ std::shared_ptr<HttpContainer> HttpRequestArduino::start(std::string url, std::s
|
||||
static const size_t HEADER_COUNT = sizeof(header_keys) / sizeof(header_keys[0]);
|
||||
container->client_.collectHeaders(header_keys, HEADER_COUNT);
|
||||
|
||||
App.feed_wdt();
|
||||
container->status_code = container->client_.sendRequest(method.c_str(), body.c_str());
|
||||
App.feed_wdt();
|
||||
if (container->status_code < 0) {
|
||||
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s", url.c_str(),
|
||||
HTTPClient::errorToString(container->status_code).c_str());
|
||||
|
@ -117,8 +117,11 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::start(std::string url, std::strin
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App.feed_wdt();
|
||||
container->content_length = esp_http_client_fetch_headers(client);
|
||||
App.feed_wdt();
|
||||
container->status_code = esp_http_client_get_status_code(client);
|
||||
App.feed_wdt();
|
||||
if (is_success(container->status_code)) {
|
||||
container->duration_ms = millis() - start;
|
||||
return container;
|
||||
@ -148,8 +151,11 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::start(std::string url, std::strin
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App.feed_wdt();
|
||||
container->content_length = esp_http_client_fetch_headers(client);
|
||||
App.feed_wdt();
|
||||
container->status_code = esp_http_client_get_status_code(client);
|
||||
App.feed_wdt();
|
||||
if (is_success(container->status_code)) {
|
||||
container->duration_ms = millis() - start;
|
||||
return container;
|
||||
|
@ -23,7 +23,7 @@ bool operator==(const GainTimePair &lhs, const GainTimePair &rhs) {
|
||||
}
|
||||
|
||||
bool operator!=(const GainTimePair &lhs, const GainTimePair &rhs) {
|
||||
return !(lhs.gain == rhs.gain && lhs.time == rhs.time);
|
||||
return lhs.gain != rhs.gain || lhs.time != rhs.time;
|
||||
}
|
||||
|
||||
template<typename T, size_t size> T get_next(const T (&array)[size], const T val) {
|
||||
|
@ -322,8 +322,8 @@ async def to_code(configs):
|
||||
await encoders_to_code(lv_component, config, default_group)
|
||||
await keypads_to_code(lv_component, config, default_group)
|
||||
await theme_to_code(config)
|
||||
await styles_to_code(config)
|
||||
await gradients_to_code(config)
|
||||
await styles_to_code(config)
|
||||
await set_obj_properties(lv_scr_act, config)
|
||||
await add_widgets(lv_scr_act, config)
|
||||
await add_pages(lv_component, config)
|
||||
|
@ -30,7 +30,7 @@ from .defines import (
|
||||
call_lambda,
|
||||
literal,
|
||||
)
|
||||
from .helpers import esphome_fonts_used, lv_fonts_used, requires_component
|
||||
from .helpers import add_lv_use, esphome_fonts_used, lv_fonts_used, requires_component
|
||||
from .types import lv_font_t, lv_gradient_t, lv_img_t
|
||||
|
||||
opacity_consts = LvConstant("LV_OPA_", "TRANSP", "COVER")
|
||||
@ -326,6 +326,7 @@ def image_validator(value):
|
||||
value = requires_component("image")(value)
|
||||
value = cv.use_id(Image_)(value)
|
||||
lv_images_used.add(value)
|
||||
add_lv_use("img", "label")
|
||||
return value
|
||||
|
||||
|
||||
|
@ -279,7 +279,7 @@ std::string LvSelectable::get_selected_text() {
|
||||
static std::string join_string(std::vector<std::string> options) {
|
||||
return std::accumulate(
|
||||
options.begin(), options.end(), std::string(),
|
||||
[](const std::string &a, const std::string &b) -> std::string { return a + (a.length() > 0 ? "\n" : "") + b; });
|
||||
[](const std::string &a, const std::string &b) -> std::string { return a + (!a.empty() ? "\n" : "") + b; });
|
||||
}
|
||||
|
||||
void LvSelectable::set_selected_text(const std::string &text, lv_anim_enable_t anim) {
|
||||
|
@ -341,6 +341,7 @@ FLEX_OBJ_SCHEMA = {
|
||||
cv.Optional(df.CONF_FLEX_GROW): cv.int_,
|
||||
}
|
||||
|
||||
|
||||
DISP_BG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Optional(df.CONF_DISP_BG_IMAGE): lv_image,
|
||||
|
@ -39,7 +39,10 @@ LINE_SCHEMA = {
|
||||
class LineType(WidgetType):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
CONF_LINE, LvType("lv_line_t"), (CONF_MAIN,), LINE_SCHEMA, modify_schema={}
|
||||
CONF_LINE,
|
||||
LvType("lv_line_t"),
|
||||
(CONF_MAIN,),
|
||||
LINE_SCHEMA,
|
||||
)
|
||||
|
||||
async def to_code(self, w: Widget, config):
|
||||
|
@ -1,8 +1,8 @@
|
||||
from esphome import automation, pins
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import key_provider
|
||||
from esphome.const import CONF_ID, CONF_PIN
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID, CONF_ON_KEY, CONF_PIN, CONF_TRIGGER_ID
|
||||
|
||||
CODEOWNERS = ["@ssieb"]
|
||||
|
||||
@ -14,6 +14,9 @@ matrix_keypad_ns = cg.esphome_ns.namespace("matrix_keypad")
|
||||
MatrixKeypad = matrix_keypad_ns.class_(
|
||||
"MatrixKeypad", key_provider.KeyProvider, cg.Component
|
||||
)
|
||||
MatrixKeyTrigger = matrix_keypad_ns.class_(
|
||||
"MatrixKeyTrigger", automation.Trigger.template(cg.uint8)
|
||||
)
|
||||
|
||||
CONF_KEYPAD_ID = "keypad_id"
|
||||
CONF_ROWS = "rows"
|
||||
@ -47,6 +50,11 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Optional(CONF_DEBOUNCE_TIME, default=1): cv.int_range(min=1, max=100),
|
||||
cv.Optional(CONF_HAS_DIODES): cv.boolean,
|
||||
cv.Optional(CONF_HAS_PULLDOWNS): cv.boolean,
|
||||
cv.Optional(CONF_ON_KEY): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MatrixKeyTrigger),
|
||||
}
|
||||
),
|
||||
}
|
||||
),
|
||||
check_keys,
|
||||
@ -73,3 +81,7 @@ async def to_code(config):
|
||||
cg.add(var.set_has_diodes(config[CONF_HAS_DIODES]))
|
||||
if CONF_HAS_PULLDOWNS in config:
|
||||
cg.add(var.set_has_pulldowns(config[CONF_HAS_PULLDOWNS]))
|
||||
for conf in config.get(CONF_ON_KEY, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
cg.add(var.register_key_trigger(trigger))
|
||||
await automation.build_automation(trigger, [(cg.uint8, "x")], conf)
|
||||
|
@ -6,7 +6,7 @@
|
||||
namespace esphome {
|
||||
namespace matrix_keypad {
|
||||
|
||||
class MatrixKeypadBinarySensor : public MatrixKeypadListener, public binary_sensor::BinarySensor {
|
||||
class MatrixKeypadBinarySensor : public MatrixKeypadListener, public binary_sensor::BinarySensorInitiallyOff {
|
||||
public:
|
||||
MatrixKeypadBinarySensor(uint8_t key) : has_key_(true), key_(key){};
|
||||
MatrixKeypadBinarySensor(const char *key) : has_key_(true), key_((uint8_t) key[0]){};
|
||||
|
@ -86,6 +86,8 @@ void MatrixKeypad::loop() {
|
||||
if (!this->keys_.empty()) {
|
||||
uint8_t keycode = this->keys_[key];
|
||||
ESP_LOGD(TAG, "key '%c' pressed", keycode);
|
||||
for (auto &trigger : this->key_triggers_)
|
||||
trigger->trigger(keycode);
|
||||
for (auto &listener : this->listeners_)
|
||||
listener->key_pressed(keycode);
|
||||
this->send_key_(keycode);
|
||||
@ -107,5 +109,7 @@ void MatrixKeypad::dump_config() {
|
||||
|
||||
void MatrixKeypad::register_listener(MatrixKeypadListener *listener) { this->listeners_.push_back(listener); }
|
||||
|
||||
void MatrixKeypad::register_key_trigger(MatrixKeyTrigger *trig) { this->key_triggers_.push_back(trig); }
|
||||
|
||||
} // namespace matrix_keypad
|
||||
} // namespace esphome
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/key_provider/key_provider.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
@ -18,6 +19,8 @@ class MatrixKeypadListener {
|
||||
virtual void key_released(uint8_t key){};
|
||||
};
|
||||
|
||||
class MatrixKeyTrigger : public Trigger<uint8_t> {};
|
||||
|
||||
class MatrixKeypad : public key_provider::KeyProvider, public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
@ -31,6 +34,7 @@ class MatrixKeypad : public key_provider::KeyProvider, public Component {
|
||||
void set_has_pulldowns(int has_pulldowns) { has_pulldowns_ = has_pulldowns; };
|
||||
|
||||
void register_listener(MatrixKeypadListener *listener);
|
||||
void register_key_trigger(MatrixKeyTrigger *trig);
|
||||
|
||||
protected:
|
||||
std::vector<GPIOPin *> rows_;
|
||||
@ -42,6 +46,7 @@ class MatrixKeypad : public key_provider::KeyProvider, public Component {
|
||||
int pressed_key_ = -1;
|
||||
|
||||
std::vector<MatrixKeypadListener *> listeners_{};
|
||||
std::vector<MatrixKeyTrigger *> key_triggers_;
|
||||
};
|
||||
|
||||
} // namespace matrix_keypad
|
||||
|
@ -38,8 +38,9 @@ void Modbus::loop() {
|
||||
|
||||
// stop blocking new send commands after sent_wait_time_ ms after response received
|
||||
if (now - this->last_send_ > send_wait_time_) {
|
||||
if (waiting_for_response > 0)
|
||||
if (waiting_for_response > 0) {
|
||||
ESP_LOGV(TAG, "Stop waiting for response from %d", waiting_for_response);
|
||||
}
|
||||
waiting_for_response = 0;
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
),
|
||||
cv.Optional(CONF_ON_OFFLINE): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ModbusOnlineTrigger),
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ModbusOfflineTrigger),
|
||||
}
|
||||
),
|
||||
}
|
||||
|
@ -622,51 +622,87 @@ int64_t payload_to_number(const std::vector<uint8_t> &data, SensorValueType sens
|
||||
uint32_t bitmask) {
|
||||
int64_t value = 0; // int64_t because it can hold signed and unsigned 32 bits
|
||||
|
||||
size_t size = data.size() - offset;
|
||||
bool error = false;
|
||||
switch (sensor_value_type) {
|
||||
case SensorValueType::U_WORD:
|
||||
if (size >= 2) {
|
||||
value = mask_and_shift_by_rightbit(get_data<uint16_t>(data, offset), bitmask); // default is 0xFFFF ;
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case SensorValueType::U_DWORD:
|
||||
case SensorValueType::FP32:
|
||||
if (size >= 4) {
|
||||
value = get_data<uint32_t>(data, offset);
|
||||
value = mask_and_shift_by_rightbit((uint32_t) value, bitmask);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case SensorValueType::U_DWORD_R:
|
||||
case SensorValueType::FP32_R:
|
||||
if (size >= 4) {
|
||||
value = get_data<uint32_t>(data, offset);
|
||||
value = static_cast<uint32_t>(value & 0xFFFF) << 16 | (value & 0xFFFF0000) >> 16;
|
||||
value = mask_and_shift_by_rightbit((uint32_t) value, bitmask);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case SensorValueType::S_WORD:
|
||||
if (size >= 2) {
|
||||
value = mask_and_shift_by_rightbit(get_data<int16_t>(data, offset),
|
||||
bitmask); // default is 0xFFFF ;
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case SensorValueType::S_DWORD:
|
||||
if (size >= 4) {
|
||||
value = mask_and_shift_by_rightbit(get_data<int32_t>(data, offset), bitmask);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case SensorValueType::S_DWORD_R: {
|
||||
if (size >= 4) {
|
||||
value = get_data<uint32_t>(data, offset);
|
||||
// Currently the high word is at the low position
|
||||
// the sign bit is therefore at low before the switch
|
||||
uint32_t sign_bit = (value & 0x8000) << 16;
|
||||
value = mask_and_shift_by_rightbit(
|
||||
static_cast<int32_t>(((value & 0x7FFF) << 16 | (value & 0xFFFF0000) >> 16) | sign_bit), bitmask);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
} break;
|
||||
case SensorValueType::U_QWORD:
|
||||
case SensorValueType::S_QWORD:
|
||||
// Ignore bitmask for QWORD
|
||||
if (size >= 8) {
|
||||
value = get_data<uint64_t>(data, offset);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
break;
|
||||
case SensorValueType::U_QWORD_R:
|
||||
case SensorValueType::S_QWORD_R: {
|
||||
// Ignore bitmask for QWORD
|
||||
if (size >= 8) {
|
||||
uint64_t tmp = get_data<uint64_t>(data, offset);
|
||||
value = (tmp << 48) | (tmp >> 48) | ((tmp & 0xFFFF0000) << 16) | ((tmp >> 16) & 0xFFFF0000);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
} break;
|
||||
case SensorValueType::RAW:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (error)
|
||||
ESP_LOGE(TAG, "not enough data for value");
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -151,11 +151,11 @@ void MQTTBackendESP32::mqtt_event_handler_(const Event &event) {
|
||||
break;
|
||||
case MQTT_EVENT_DATA: {
|
||||
static std::string topic;
|
||||
if (event.topic.length() > 0) {
|
||||
if (!event.topic.empty()) {
|
||||
topic = event.topic;
|
||||
}
|
||||
ESP_LOGV(TAG, "MQTT_EVENT_DATA %s", topic.c_str());
|
||||
this->on_message_.call(event.topic.length() > 0 ? topic.c_str() : nullptr, event.data.data(), event.data.size(),
|
||||
this->on_message_.call(!event.topic.empty() ? topic.c_str() : nullptr, event.data.data(), event.data.size(),
|
||||
event.current_data_offset, event.total_data_len);
|
||||
} break;
|
||||
case MQTT_EVENT_ERROR:
|
||||
@ -184,7 +184,7 @@ void MQTTBackendESP32::mqtt_event_handler(void *handler_args, esp_event_base_t b
|
||||
// queue event to decouple processing
|
||||
if (instance) {
|
||||
auto event = *static_cast<esp_mqtt_event_t *>(event_data);
|
||||
instance->mqtt_events_.push(Event(event));
|
||||
instance->mqtt_events_.emplace(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,3 +6,5 @@ Nextion = nextion_ns.class_("Nextion", cg.PollingComponent, uart.UARTDevice)
|
||||
nextion_ref = Nextion.operator("ref")
|
||||
|
||||
CONF_NEXTION_ID = "nextion_id"
|
||||
CONF_PUBLISH_STATE = "publish_state"
|
||||
CONF_SEND_TO_NEXTION = "send_to_nextion"
|
||||
|
@ -5,6 +5,13 @@
|
||||
namespace esphome {
|
||||
namespace nextion {
|
||||
|
||||
class BufferOverflowTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit BufferOverflowTrigger(Nextion *nextion) {
|
||||
nextion->add_buffer_overflow_event_callback([this]() { this->trigger(); });
|
||||
}
|
||||
};
|
||||
|
||||
class SetupTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit SetupTrigger(Nextion *nextion) {
|
||||
@ -42,5 +49,74 @@ class TouchTrigger : public Trigger<uint8_t, uint8_t, bool> {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class NextionPublishFloatAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit NextionPublishFloatAction(NextionComponent *component) : component_(component) {}
|
||||
|
||||
TEMPLATABLE_VALUE(float, state)
|
||||
TEMPLATABLE_VALUE(bool, publish_state)
|
||||
TEMPLATABLE_VALUE(bool, send_to_nextion)
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->component_->set_state(this->state_.value(x...), this->publish_state_.value(x...),
|
||||
this->send_to_nextion_.value(x...));
|
||||
}
|
||||
|
||||
void set_state(std::function<void(Ts..., float)> state) { this->state_ = state; }
|
||||
void set_publish_state(std::function<void(Ts..., bool)> publish_state) { this->publish_state_ = publish_state; }
|
||||
void set_send_to_nextion(std::function<void(Ts..., bool)> send_to_nextion) {
|
||||
this->send_to_nextion_ = send_to_nextion;
|
||||
}
|
||||
|
||||
protected:
|
||||
NextionComponent *component_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class NextionPublishTextAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit NextionPublishTextAction(NextionComponent *component) : component_(component) {}
|
||||
|
||||
TEMPLATABLE_VALUE(const char *, state)
|
||||
TEMPLATABLE_VALUE(bool, publish_state)
|
||||
TEMPLATABLE_VALUE(bool, send_to_nextion)
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->component_->set_state(this->state_.value(x...), this->publish_state_.value(x...),
|
||||
this->send_to_nextion_.value(x...));
|
||||
}
|
||||
|
||||
void set_state(std::function<void(Ts..., const char *)> state) { this->state_ = state; }
|
||||
void set_publish_state(std::function<void(Ts..., bool)> publish_state) { this->publish_state_ = publish_state; }
|
||||
void set_send_to_nextion(std::function<void(Ts..., bool)> send_to_nextion) {
|
||||
this->send_to_nextion_ = send_to_nextion;
|
||||
}
|
||||
|
||||
protected:
|
||||
NextionComponent *component_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class NextionPublishBoolAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit NextionPublishBoolAction(NextionComponent *component) : component_(component) {}
|
||||
|
||||
TEMPLATABLE_VALUE(bool, state)
|
||||
TEMPLATABLE_VALUE(bool, publish_state)
|
||||
TEMPLATABLE_VALUE(bool, send_to_nextion)
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->component_->set_state(this->state_.value(x...), this->publish_state_.value(x...),
|
||||
this->send_to_nextion_.value(x...));
|
||||
}
|
||||
|
||||
void set_state(std::function<void(Ts..., bool)> state) { this->state_ = state; }
|
||||
void set_publish_state(std::function<void(Ts..., bool)> publish_state) { this->publish_state_ = publish_state; }
|
||||
void set_send_to_nextion(std::function<void(Ts..., bool)> send_to_nextion) {
|
||||
this->send_to_nextion_ = send_to_nextion;
|
||||
}
|
||||
|
||||
protected:
|
||||
NextionComponent *component_;
|
||||
};
|
||||
|
||||
} // namespace nextion
|
||||
} // namespace esphome
|
||||
|
@ -18,6 +18,7 @@ CONF_ON_SLEEP = "on_sleep"
|
||||
CONF_ON_WAKE = "on_wake"
|
||||
CONF_ON_SETUP = "on_setup"
|
||||
CONF_ON_PAGE = "on_page"
|
||||
CONF_ON_BUFFER_OVERFLOW = "on_buffer_overflow"
|
||||
CONF_TOUCH_SLEEP_TIMEOUT = "touch_sleep_timeout"
|
||||
CONF_WAKE_UP_PAGE = "wake_up_page"
|
||||
CONF_START_UP_PAGE = "start_up_page"
|
||||
|
@ -1,9 +1,16 @@
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
|
||||
from esphome.const import CONF_COMPONENT_ID, CONF_PAGE_ID, CONF_ID
|
||||
from .. import nextion_ns, CONF_NEXTION_ID
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_STATE,
|
||||
CONF_COMPONENT_ID,
|
||||
CONF_PAGE_ID,
|
||||
)
|
||||
|
||||
from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION
|
||||
|
||||
|
||||
from ..base_component import (
|
||||
@ -19,6 +26,10 @@ NextionBinarySensor = nextion_ns.class_(
|
||||
"NextionBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent
|
||||
)
|
||||
|
||||
NextionPublishBoolAction = nextion_ns.class_(
|
||||
"NextionPublishBoolAction", automation.Action
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
binary_sensor.binary_sensor_schema(NextionBinarySensor)
|
||||
.extend(
|
||||
@ -52,3 +63,33 @@ async def to_code(config):
|
||||
if CONF_COMPONENT_NAME in config or CONF_VARIABLE_NAME in config:
|
||||
await setup_component_core_(var, config, ".val")
|
||||
cg.add(hub.register_binarysensor_component(var))
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"binary_sensor.nextion.publish",
|
||||
NextionPublishBoolAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(NextionBinarySensor),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_PUBLISH_STATE, default="true"): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_SEND_TO_NEXTION, default="true"): cv.templatable(
|
||||
cv.boolean
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def sensor_nextion_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, bool)
|
||||
cg.add(var.set_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_PUBLISH_STATE], args, bool)
|
||||
cg.add(var.set_publish_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_SEND_TO_NEXTION], args, bool)
|
||||
cg.add(var.set_send_to_nextion(template_))
|
||||
|
||||
return var
|
||||
|
@ -13,6 +13,7 @@ from esphome.const import (
|
||||
from esphome.core import CORE
|
||||
from . import Nextion, nextion_ns, nextion_ref
|
||||
from .base_component import (
|
||||
CONF_ON_BUFFER_OVERFLOW,
|
||||
CONF_ON_SLEEP,
|
||||
CONF_ON_WAKE,
|
||||
CONF_ON_SETUP,
|
||||
@ -36,6 +37,9 @@ SleepTrigger = nextion_ns.class_("SleepTrigger", automation.Trigger.template())
|
||||
WakeTrigger = nextion_ns.class_("WakeTrigger", automation.Trigger.template())
|
||||
PageTrigger = nextion_ns.class_("PageTrigger", automation.Trigger.template())
|
||||
TouchTrigger = nextion_ns.class_("TouchTrigger", automation.Trigger.template())
|
||||
BufferOverflowTrigger = nextion_ns.class_(
|
||||
"BufferOverflowTrigger", automation.Trigger.template()
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
display.BASIC_DISPLAY_SCHEMA.extend(
|
||||
@ -68,6 +72,13 @@ CONFIG_SCHEMA = (
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TouchTrigger),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_BUFFER_OVERFLOW): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
BufferOverflowTrigger
|
||||
),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_TOUCH_SLEEP_TIMEOUT): cv.int_range(min=3, max=65535),
|
||||
cv.Optional(CONF_WAKE_UP_PAGE): cv.uint8_t,
|
||||
cv.Optional(CONF_START_UP_PAGE): cv.uint8_t,
|
||||
@ -151,3 +162,7 @@ async def to_code(config):
|
||||
],
|
||||
conf,
|
||||
)
|
||||
|
||||
for conf in config.get(CONF_ON_BUFFER_OVERFLOW, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
@ -190,6 +190,10 @@ void Nextion::add_touch_event_callback(std::function<void(uint8_t, uint8_t, bool
|
||||
this->touch_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
void Nextion::add_buffer_overflow_event_callback(std::function<void()> &&callback) {
|
||||
this->buffer_overflow_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
void Nextion::update_all_components() {
|
||||
if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping())
|
||||
return;
|
||||
@ -339,7 +343,7 @@ void Nextion::process_serial_() {
|
||||
}
|
||||
// nextion.tech/instruction-set/
|
||||
void Nextion::process_nextion_commands_() {
|
||||
if (this->command_data_.length() == 0) {
|
||||
if (this->command_data_.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -458,7 +462,9 @@ void Nextion::process_nextion_commands_() {
|
||||
this->remove_from_q_();
|
||||
break;
|
||||
case 0x24: // Serial Buffer overflow occurs
|
||||
ESP_LOGW(TAG, "Nextion reported Serial Buffer overflow!");
|
||||
// Buffer will continue to receive the current instruction, all previous instructions are lost.
|
||||
ESP_LOGE(TAG, "Nextion reported Serial Buffer overflow!");
|
||||
this->buffer_overflow_callback_.call();
|
||||
break;
|
||||
case 0x65: { // touch event return data
|
||||
if (to_process_length != 3) {
|
||||
|
@ -1134,6 +1134,12 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
|
||||
*/
|
||||
void add_touch_event_callback(std::function<void(uint8_t, uint8_t, bool)> &&callback);
|
||||
|
||||
/** Add a callback to be notified when the nextion reports a buffer overflow.
|
||||
*
|
||||
* @param callback The void() callback.
|
||||
*/
|
||||
void add_buffer_overflow_event_callback(std::function<void()> &&callback);
|
||||
|
||||
void update_all_components();
|
||||
|
||||
/**
|
||||
@ -1323,6 +1329,7 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
|
||||
CallbackManager<void()> wake_callback_{};
|
||||
CallbackManager<void(uint8_t)> page_callback_{};
|
||||
CallbackManager<void(uint8_t, uint8_t, bool)> touch_callback_{};
|
||||
CallbackManager<void()> buffer_overflow_callback_{};
|
||||
|
||||
optional<nextion_writer_t> writer_;
|
||||
float brightness_{1.0};
|
||||
|
@ -36,8 +36,8 @@ int Nextion::upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &r
|
||||
ESP_LOGV(TAG, "Requesting range: %s", range_header);
|
||||
esp_http_client_set_header(http_client, "Range", range_header);
|
||||
ESP_LOGV(TAG, "Opening HTTP connetion");
|
||||
esp_err_t err;
|
||||
if ((err = esp_http_client_open(http_client, 0)) != ESP_OK) {
|
||||
esp_err_t err = esp_http_client_open(http_client, 0);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_COMPONENT_ID,
|
||||
)
|
||||
from .. import nextion_ns, CONF_NEXTION_ID
|
||||
from esphome.const import CONF_ID, CONF_COMPONENT_ID, CONF_STATE
|
||||
|
||||
from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION
|
||||
|
||||
from ..base_component import (
|
||||
setup_component_core_,
|
||||
@ -25,6 +24,10 @@ CODEOWNERS = ["@senexcrenshaw"]
|
||||
|
||||
NextionSensor = nextion_ns.class_("NextionSensor", sensor.Sensor, cg.PollingComponent)
|
||||
|
||||
NextionPublishFloatAction = nextion_ns.class_(
|
||||
"NextionPublishFloatAction", automation.Action
|
||||
)
|
||||
|
||||
|
||||
def CheckWaveID(value):
|
||||
value = cv.int_(value)
|
||||
@ -95,3 +98,33 @@ async def to_code(config):
|
||||
|
||||
if CONF_WAVE_MAX_LENGTH in config:
|
||||
cg.add(var.set_wave_max_length(config[CONF_WAVE_MAX_LENGTH]))
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"sensor.nextion.publish",
|
||||
NextionPublishFloatAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(NextionSensor),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.float_),
|
||||
cv.Optional(CONF_PUBLISH_STATE, default="true"): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_SEND_TO_NEXTION, default="true"): cv.templatable(
|
||||
cv.boolean
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def sensor_nextion_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, float)
|
||||
cg.add(var.set_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_PUBLISH_STATE], args, bool)
|
||||
cg.add(var.set_publish_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_SEND_TO_NEXTION], args, bool)
|
||||
cg.add(var.set_send_to_nextion(template_))
|
||||
|
||||
return var
|
||||
|
@ -1,9 +1,11 @@
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import switch
|
||||
|
||||
from esphome.const import CONF_ID
|
||||
from .. import nextion_ns, CONF_NEXTION_ID
|
||||
from esphome.const import CONF_ID, CONF_STATE
|
||||
|
||||
from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION
|
||||
|
||||
from ..base_component import (
|
||||
setup_component_core_,
|
||||
@ -16,6 +18,10 @@ CODEOWNERS = ["@senexcrenshaw"]
|
||||
|
||||
NextionSwitch = nextion_ns.class_("NextionSwitch", switch.Switch, cg.PollingComponent)
|
||||
|
||||
NextionPublishBoolAction = nextion_ns.class_(
|
||||
"NextionPublishBoolAction", automation.Action
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
switch.switch_schema(NextionSwitch)
|
||||
.extend(CONFIG_SWITCH_COMPONENT_SCHEMA)
|
||||
@ -33,3 +39,33 @@ async def to_code(config):
|
||||
cg.add(hub.register_switch_component(var))
|
||||
|
||||
await setup_component_core_(var, config, ".val")
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"switch.nextion.publish",
|
||||
NextionPublishBoolAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(NextionSwitch),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_PUBLISH_STATE, default="true"): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_SEND_TO_NEXTION, default="true"): cv.templatable(
|
||||
cv.boolean
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def sensor_nextion_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, bool)
|
||||
cg.add(var.set_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_PUBLISH_STATE], args, bool)
|
||||
cg.add(var.set_publish_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_SEND_TO_NEXTION], args, bool)
|
||||
cg.add(var.set_send_to_nextion(template_))
|
||||
|
||||
return var
|
||||
|
@ -1,9 +1,10 @@
|
||||
from esphome import automation
|
||||
from esphome.components import text_sensor
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.const import CONF_ID, CONF_STATE
|
||||
|
||||
from .. import nextion_ns, CONF_NEXTION_ID
|
||||
from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION
|
||||
|
||||
from ..base_component import (
|
||||
setup_component_core_,
|
||||
@ -16,6 +17,10 @@ NextionTextSensor = nextion_ns.class_(
|
||||
"NextionTextSensor", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
|
||||
NextionPublishTextAction = nextion_ns.class_(
|
||||
"NextionPublishTextAction", automation.Action
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
text_sensor.text_sensor_schema(NextionTextSensor)
|
||||
.extend(CONFIG_TEXT_COMPONENT_SCHEMA)
|
||||
@ -32,3 +37,33 @@ async def to_code(config):
|
||||
cg.add(hub.register_textsensor_component(var))
|
||||
|
||||
await setup_component_core_(var, config, ".txt")
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"text_sensor.nextion.publish",
|
||||
NextionPublishTextAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(NextionTextSensor),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.string_strict),
|
||||
cv.Optional(CONF_PUBLISH_STATE, default="true"): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_SEND_TO_NEXTION, default="true"): cv.templatable(
|
||||
cv.boolean
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def sensor_nextion_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, cg.const_char_ptr)
|
||||
cg.add(var.set_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_PUBLISH_STATE], args, cg.bool_)
|
||||
cg.add(var.set_publish_state(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_SEND_TO_NEXTION], args, cg.bool_)
|
||||
cg.add(var.set_send_to_nextion(template_))
|
||||
|
||||
return var
|
||||
|
@ -30,13 +30,13 @@ std::vector<uint8_t> NdefRecord::encode(bool first, bool last) {
|
||||
data.push_back(payload_length & 0xFF);
|
||||
}
|
||||
|
||||
if (this->id_.length()) {
|
||||
if (!this->id_.empty()) {
|
||||
data.push_back(this->id_.length());
|
||||
}
|
||||
|
||||
data.insert(data.end(), this->type_.begin(), this->type_.end());
|
||||
|
||||
if (this->id_.length()) {
|
||||
if (!this->id_.empty()) {
|
||||
data.insert(data.end(), this->id_.begin(), this->id_.end());
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ uint8_t NdefRecord::create_flag_byte(bool first, bool last, size_t payload_size)
|
||||
if (payload_size <= 255) {
|
||||
value = value | 0x10; // Set SR bit
|
||||
}
|
||||
if (this->id_.length()) {
|
||||
if (!this->id_.empty()) {
|
||||
value = value | 0x08; // Set IL bit
|
||||
}
|
||||
return value;
|
||||
|
@ -98,6 +98,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
# esp8266_arduino=cv.Version(2, 7, 0),
|
||||
esp32_arduino=cv.Version(0, 0, 0),
|
||||
esp_idf=cv.Version(4, 0, 0),
|
||||
rp2040_arduino=cv.Version(0, 0, 0),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
@ -138,7 +138,7 @@ OpenthermHub::OpenthermHub() : Component(), in_pin_{}, out_pin_{} {}
|
||||
void OpenthermHub::process_response(OpenthermData &data) {
|
||||
ESP_LOGD(TAG, "Received OpenTherm response with id %d (%s)", data.id,
|
||||
this->opentherm_->message_id_to_str((MessageId) data.id));
|
||||
ESP_LOGD(TAG, "%s", this->opentherm_->debug_data(data).c_str());
|
||||
this->opentherm_->debug_data(data);
|
||||
|
||||
switch (data.id) {
|
||||
OPENTHERM_SENSOR_MESSAGE_HANDLERS(OPENTHERM_MESSAGE_RESPONSE_MESSAGE, OPENTHERM_MESSAGE_RESPONSE_ENTITY, ,
|
||||
@ -315,7 +315,7 @@ void OpenthermHub::start_conversation_() {
|
||||
|
||||
ESP_LOGD(TAG, "Sending request with id %d (%s)", request.id,
|
||||
this->opentherm_->message_id_to_str((MessageId) request.id));
|
||||
ESP_LOGD(TAG, "%s", this->opentherm_->debug_data(request).c_str());
|
||||
this->opentherm_->debug_data(request);
|
||||
// Send the request
|
||||
this->last_conversation_start_ = millis();
|
||||
this->opentherm_->send(request);
|
||||
@ -340,19 +340,18 @@ void OpenthermHub::stop_opentherm_() {
|
||||
this->opentherm_->stop();
|
||||
this->last_conversation_end_ = millis();
|
||||
}
|
||||
|
||||
void OpenthermHub::handle_protocol_write_error_() {
|
||||
ESP_LOGW(TAG, "Error while sending request: %s",
|
||||
this->opentherm_->operation_mode_to_str(this->opentherm_->get_mode()));
|
||||
ESP_LOGW(TAG, "%s", this->opentherm_->debug_data(this->last_request_).c_str());
|
||||
this->opentherm_->debug_data(this->last_request_);
|
||||
}
|
||||
|
||||
void OpenthermHub::handle_protocol_read_error_() {
|
||||
OpenThermError error;
|
||||
this->opentherm_->get_protocol_error(error);
|
||||
ESP_LOGW(TAG, "Protocol error occured while receiving response: %s", this->opentherm_->debug_error(error).c_str());
|
||||
ESP_LOGW(TAG, "Protocol error occured while receiving response: %s",
|
||||
this->opentherm_->protocol_error_to_to_str(error.error_type));
|
||||
this->opentherm_->debug_error(error);
|
||||
}
|
||||
|
||||
void OpenthermHub::handle_timeout_error_() {
|
||||
ESP_LOGW(TAG, "Receive response timed out at a protocol level");
|
||||
this->stop_opentherm_();
|
||||
|
@ -15,21 +15,17 @@
|
||||
#include "Arduino.h"
|
||||
#endif
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <bitset>
|
||||
|
||||
namespace esphome {
|
||||
namespace opentherm {
|
||||
|
||||
using std::string;
|
||||
using std::bitset;
|
||||
using std::stringstream;
|
||||
using std::to_string;
|
||||
|
||||
static const char *const TAG = "opentherm";
|
||||
|
||||
#ifdef ESP8266
|
||||
OpenTherm *OpenTherm::instance_ = nullptr;
|
||||
OpenTherm *OpenTherm::instance = nullptr;
|
||||
#endif
|
||||
|
||||
OpenTherm::OpenTherm(InternalGPIOPin *in_pin, InternalGPIOPin *out_pin, int32_t device_timeout)
|
||||
@ -53,7 +49,7 @@ OpenTherm::OpenTherm(InternalGPIOPin *in_pin, InternalGPIOPin *out_pin, int32_t
|
||||
|
||||
bool OpenTherm::initialize() {
|
||||
#ifdef ESP8266
|
||||
OpenTherm::instance_ = this;
|
||||
OpenTherm::instance = this;
|
||||
#endif
|
||||
this->in_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
this->out_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||
@ -216,7 +212,7 @@ bool IRAM_ATTR OpenTherm::timer_isr(OpenTherm *arg) {
|
||||
}
|
||||
|
||||
#ifdef ESP8266
|
||||
void IRAM_ATTR OpenTherm::esp8266_timer_isr() { OpenTherm::timer_isr(OpenTherm::instance_); }
|
||||
void IRAM_ATTR OpenTherm::esp8266_timer_isr() { OpenTherm::timer_isr(OpenTherm::instance); }
|
||||
#endif
|
||||
|
||||
void IRAM_ATTR OpenTherm::bit_read_(uint8_t value) {
|
||||
@ -545,29 +541,17 @@ const char *OpenTherm::message_id_to_str(MessageId id) {
|
||||
}
|
||||
}
|
||||
|
||||
string OpenTherm::debug_data(OpenthermData &data) {
|
||||
stringstream result;
|
||||
result << bitset<8>(data.type) << " " << bitset<8>(data.id) << " " << bitset<8>(data.valueHB) << " "
|
||||
<< bitset<8>(data.valueLB) << "\n";
|
||||
result << "type: " << this->message_type_to_str((MessageType) data.type) << "; ";
|
||||
result << "id: " << to_string(data.id) << "; ";
|
||||
result << "HB: " << to_string(data.valueHB) << "; ";
|
||||
result << "LB: " << to_string(data.valueLB) << "; ";
|
||||
result << "uint_16: " << to_string(data.u16()) << "; ";
|
||||
result << "float: " << to_string(data.f88());
|
||||
|
||||
return result.str();
|
||||
void OpenTherm::debug_data(OpenthermData &data) {
|
||||
ESP_LOGD(TAG, "%s %s %s %s", format_bin(data.type).c_str(), format_bin(data.id).c_str(),
|
||||
format_bin(data.valueHB).c_str(), format_bin(data.valueLB).c_str());
|
||||
ESP_LOGD(TAG, "type: %s; id: %s; HB: %s; LB: %s; uint_16: %s; float: %s",
|
||||
this->message_type_to_str((MessageType) data.type), to_string(data.id).c_str(),
|
||||
to_string(data.valueHB).c_str(), to_string(data.valueLB).c_str(), to_string(data.u16()).c_str(),
|
||||
to_string(data.f88()).c_str());
|
||||
}
|
||||
std::string OpenTherm::debug_error(OpenThermError &error) {
|
||||
stringstream result;
|
||||
result << "type: " << this->protocol_error_to_to_str(error.error_type) << "; ";
|
||||
result << "data: ";
|
||||
result << format_hex(error.data);
|
||||
result << "; clock: " << to_string(clock_);
|
||||
result << "; capture: " << bitset<32>(error.capture);
|
||||
result << "; bit_pos: " << to_string(error.bit_pos);
|
||||
|
||||
return result.str();
|
||||
void OpenTherm::debug_error(OpenThermError &error) const {
|
||||
ESP_LOGD(TAG, "data: %s; clock: %s; capture: %s; bit_pos: %s", format_hex(error.data).c_str(),
|
||||
to_string(clock_).c_str(), format_bin(error.capture).c_str(), to_string(error.bit_pos).c_str());
|
||||
}
|
||||
|
||||
float OpenthermData::f88() { return ((float) this->s16()) / 256.0; }
|
||||
|
@ -8,10 +8,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#if defined(ESP32) || defined(USE_ESP_IDF)
|
||||
#include "driver/timer.h"
|
||||
@ -318,8 +317,8 @@ class OpenTherm {
|
||||
|
||||
OperationMode get_mode() { return mode_; }
|
||||
|
||||
std::string debug_data(OpenthermData &data);
|
||||
std::string debug_error(OpenThermError &error);
|
||||
void debug_data(OpenthermData &data);
|
||||
void debug_error(OpenThermError &error) const;
|
||||
|
||||
const char *protocol_error_to_to_str(ProtocolErrorType error_type);
|
||||
const char *message_type_to_str(MessageType message_type);
|
||||
@ -371,7 +370,7 @@ class OpenTherm {
|
||||
|
||||
#ifdef ESP8266
|
||||
// ESP8266 timer can accept callback with no parameters, so we have this hack to save a static instance of OpenTherm
|
||||
static OpenTherm *instance_;
|
||||
static OpenTherm *instance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -92,6 +92,7 @@ async def to_code(config):
|
||||
|
||||
|
||||
async def ota_to_code(var, config):
|
||||
await cg.past_safe_mode()
|
||||
use_state_callback = False
|
||||
for conf in config.get(CONF_ON_STATE_CHANGE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
|
@ -12,7 +12,7 @@ class OTAStateChangeTrigger : public Trigger<OTAState> {
|
||||
explicit OTAStateChangeTrigger(OTAComponent *parent) {
|
||||
parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
|
||||
if (!parent->is_failed()) {
|
||||
return trigger(state);
|
||||
trigger(state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ void FloatOutput::set_level(float state) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(state == 0.0f && this->zero_means_zero_)) // regardless of min_power_, 0.0 means off
|
||||
if (state != 0.0f || !this->zero_means_zero_) // regardless of min_power_, 0.0 means off
|
||||
state = (state * (this->max_power_ - this->min_power_)) + this->min_power_;
|
||||
|
||||
if (this->is_inverted())
|
||||
|
@ -790,7 +790,7 @@ uint8_t Pipsolar::check_incoming_crc_() {
|
||||
// send next command used
|
||||
uint8_t Pipsolar::send_next_command_() {
|
||||
uint16_t crc16;
|
||||
if (this->command_queue_[this->command_queue_position_].length() != 0) {
|
||||
if (!this->command_queue_[this->command_queue_position_].empty()) {
|
||||
const char *command = this->command_queue_[this->command_queue_position_].c_str();
|
||||
uint8_t byte_command[16];
|
||||
uint8_t length = this->command_queue_[this->command_queue_position_].length();
|
||||
@ -846,7 +846,7 @@ void Pipsolar::queue_command_(const char *command, uint8_t length) {
|
||||
uint8_t next_position = command_queue_position_;
|
||||
for (uint8_t i = 0; i < COMMAND_QUEUE_LENGTH; i++) {
|
||||
uint8_t testposition = (next_position + i) % COMMAND_QUEUE_LENGTH;
|
||||
if (command_queue_[testposition].length() == 0) {
|
||||
if (command_queue_[testposition].empty()) {
|
||||
command_queue_[testposition] = command;
|
||||
ESP_LOGD(TAG, "Command queued successfully: %s with length %u at position %d", command,
|
||||
command_queue_[testposition].length(), testposition);
|
||||
|
@ -10,11 +10,11 @@ static const char *const TAG = "pipsolar.switch";
|
||||
void PipsolarSwitch::dump_config() { LOG_SWITCH("", "Pipsolar Switch", this); }
|
||||
void PipsolarSwitch::write_state(bool state) {
|
||||
if (state) {
|
||||
if (this->on_command_.length() > 0) {
|
||||
if (!this->on_command_.empty()) {
|
||||
this->parent_->switch_command(this->on_command_);
|
||||
}
|
||||
} else {
|
||||
if (this->off_command_.length() > 0) {
|
||||
if (!this->off_command_.empty()) {
|
||||
this->parent_->switch_command(this->off_command_);
|
||||
}
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ bool PN532::is_mifare_ultralight_formatted_(const std::vector<uint8_t> &page_3_t
|
||||
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
|
||||
|
||||
return (page_3_to_6.size() > p4_offset + 3) &&
|
||||
!((page_3_to_6[p4_offset + 0] == 0xFF) && (page_3_to_6[p4_offset + 1] == 0xFF) &&
|
||||
(page_3_to_6[p4_offset + 2] == 0xFF) && (page_3_to_6[p4_offset + 3] == 0xFF));
|
||||
((page_3_to_6[p4_offset + 0] != 0xFF) || (page_3_to_6[p4_offset + 1] != 0xFF) ||
|
||||
(page_3_to_6[p4_offset + 2] != 0xFF) || (page_3_to_6[p4_offset + 3] != 0xFF));
|
||||
}
|
||||
|
||||
uint16_t PN532::read_mifare_ultralight_capacity_() {
|
||||
|
@ -81,8 +81,8 @@ bool PN7150::is_mifare_ultralight_formatted_(const std::vector<uint8_t> &page_3_
|
||||
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
|
||||
|
||||
return (page_3_to_6.size() > p4_offset + 3) &&
|
||||
!((page_3_to_6[p4_offset + 0] == 0xFF) && (page_3_to_6[p4_offset + 1] == 0xFF) &&
|
||||
(page_3_to_6[p4_offset + 2] == 0xFF) && (page_3_to_6[p4_offset + 3] == 0xFF));
|
||||
((page_3_to_6[p4_offset + 0] != 0xFF) || (page_3_to_6[p4_offset + 1] != 0xFF) ||
|
||||
(page_3_to_6[p4_offset + 2] != 0xFF) || (page_3_to_6[p4_offset + 3] != 0xFF));
|
||||
}
|
||||
|
||||
uint16_t PN7150::read_mifare_ultralight_capacity_() {
|
||||
|
@ -81,8 +81,8 @@ bool PN7160::is_mifare_ultralight_formatted_(const std::vector<uint8_t> &page_3_
|
||||
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
|
||||
|
||||
return (page_3_to_6.size() > p4_offset + 3) &&
|
||||
!((page_3_to_6[p4_offset + 0] == 0xFF) && (page_3_to_6[p4_offset + 1] == 0xFF) &&
|
||||
(page_3_to_6[p4_offset + 2] == 0xFF) && (page_3_to_6[p4_offset + 3] == 0xFF));
|
||||
((page_3_to_6[p4_offset + 0] != 0xFF) || (page_3_to_6[p4_offset + 1] != 0xFF) ||
|
||||
(page_3_to_6[p4_offset + 2] != 0xFF) || (page_3_to_6[p4_offset + 3] != 0xFF));
|
||||
}
|
||||
|
||||
uint16_t PN7160::read_mifare_ultralight_capacity_() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Commands
|
||||
SW_RESET_CMD = 0x01
|
||||
SLEEP_OUT = 0x11
|
||||
NORON = 0x13
|
||||
INVERT_OFF = 0x20
|
||||
INVERT_ON = 0x21
|
||||
ALL_ON = 0x23
|
||||
@ -55,6 +56,8 @@ chip.cmd(PAGESEL, 0x00)
|
||||
chip.cmd(0xC2, 0x00)
|
||||
chip.delay(10)
|
||||
chip.cmd(TEON, 0x00)
|
||||
chip.cmd(PIXFMT, 0x55)
|
||||
chip.cmd(NORON)
|
||||
|
||||
chip = DriverChip("AXS15231")
|
||||
chip.cmd(0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5)
|
||||
|
@ -111,7 +111,6 @@ void QspiDbi::reset_params_(bool ready) {
|
||||
mad |= MADCTL_MY;
|
||||
this->write_command_(MADCTL_CMD, mad);
|
||||
this->write_command_(BRIGHTNESS, this->brightness_);
|
||||
this->write_command_(NORON);
|
||||
this->write_command_(DISPLAY_ON);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ bool RawDumper::dump(RemoteReceiveData src) {
|
||||
ESP_LOGI(TAG, "%s", buffer);
|
||||
buffer_offset = 0;
|
||||
written = sprintf(buffer, " ");
|
||||
if (i + 1 < src.size()) {
|
||||
if (i + 1 < src.size() - 1) {
|
||||
written += sprintf(buffer + written, "%" PRId32 ", ", value);
|
||||
} else {
|
||||
written += sprintf(buffer + written, "%" PRId32, value);
|
||||
|
@ -40,13 +40,7 @@ class Rtttl : public Component {
|
||||
void set_speaker(speaker::Speaker *speaker) { this->speaker_ = speaker; }
|
||||
#endif
|
||||
float get_gain() { return gain_; }
|
||||
void set_gain(float gain) {
|
||||
if (gain < 0.1f)
|
||||
gain = 0.1f;
|
||||
if (gain > 1.0f)
|
||||
gain = 1.0f;
|
||||
this->gain_ = gain;
|
||||
}
|
||||
void set_gain(float gain) { this->gain_ = clamp(gain, 0.0f, 1.0f); }
|
||||
void play(std::string rtttl);
|
||||
void stop();
|
||||
void dump_config() override;
|
||||
|
@ -9,7 +9,7 @@ namespace safe_mode {
|
||||
class SafeModeTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit SafeModeTrigger(SafeModeComponent *parent) {
|
||||
parent->add_on_safe_mode_callback([this, parent]() { trigger(); });
|
||||
parent->add_on_safe_mode_callback([this]() { trigger(); });
|
||||
}
|
||||
};
|
||||
|
||||
|
41
esphome/components/seeed_mr60fda2/__init__.py
Normal file
41
esphome/components/seeed_mr60fda2/__init__.py
Normal file
@ -0,0 +1,41 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import uart
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
CODEOWNERS = ["@limengdu"]
|
||||
DEPENDENCIES = ["uart"]
|
||||
MULTI_CONF = True
|
||||
|
||||
mr60fda2_ns = cg.esphome_ns.namespace("seeed_mr60fda2")
|
||||
|
||||
MR60FDA2Component = mr60fda2_ns.class_(
|
||||
"MR60FDA2Component", cg.Component, uart.UARTDevice
|
||||
)
|
||||
|
||||
CONF_MR60FDA2_ID = "mr60fda2_id"
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(MR60FDA2Component),
|
||||
}
|
||||
)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||
"seeed_mr60fda2",
|
||||
require_tx=True,
|
||||
require_rx=True,
|
||||
baud_rate=115200,
|
||||
parity="NONE",
|
||||
stop_bits=1,
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
33
esphome/components/seeed_mr60fda2/binary_sensor.py
Normal file
33
esphome/components/seeed_mr60fda2/binary_sensor.py
Normal file
@ -0,0 +1,33 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import binary_sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_SAFETY
|
||||
|
||||
from . import CONF_MR60FDA2_ID, MR60FDA2Component
|
||||
|
||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||
|
||||
CONF_PEOPLE_EXIST = "people_exist"
|
||||
CONF_FALL_DETECTED = "fall_detected"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||
cv.Optional(CONF_PEOPLE_EXIST): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_OCCUPANCY, icon="mdi:motion-sensor"
|
||||
),
|
||||
cv.Optional(CONF_FALL_DETECTED): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_SAFETY, icon="mdi:emergency"
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
||||
|
||||
if people_exist_config := config.get(CONF_PEOPLE_EXIST):
|
||||
sens = await binary_sensor.new_binary_sensor(people_exist_config)
|
||||
cg.add(mr60fda2_component.set_people_exist_binary_sensor(sens))
|
||||
|
||||
if is_fall_config := config.get(CONF_FALL_DETECTED):
|
||||
sens = await binary_sensor.new_binary_sensor(is_fall_config)
|
||||
cg.add(mr60fda2_component.set_fall_detected_binary_sensor(sens))
|
45
esphome/components/seeed_mr60fda2/button/__init__.py
Normal file
45
esphome/components/seeed_mr60fda2/button/__init__.py
Normal file
@ -0,0 +1,45 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
DEVICE_CLASS_RESTART,
|
||||
DEVICE_CLASS_UPDATE,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
ENTITY_CATEGORY_NONE,
|
||||
CONF_FACTORY_RESET,
|
||||
)
|
||||
|
||||
from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns
|
||||
|
||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||
|
||||
GetRadarParametersButton = mr60fda2_ns.class_("GetRadarParametersButton", button.Button)
|
||||
ResetRadarButton = mr60fda2_ns.class_("ResetRadarButton", button.Button)
|
||||
|
||||
CONF_GET_RADAR_PARAMETERS = "get_radar_parameters"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||
cv.Optional(CONF_GET_RADAR_PARAMETERS): button.button_schema(
|
||||
GetRadarParametersButton,
|
||||
device_class=DEVICE_CLASS_UPDATE,
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
ResetRadarButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
||||
if get_radar_parameters_config := config.get(CONF_GET_RADAR_PARAMETERS):
|
||||
b = await button.new_button(get_radar_parameters_config)
|
||||
await cg.register_parented(b, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_get_radar_parameters_button(b))
|
||||
if factory_reset_config := config.get(CONF_FACTORY_RESET):
|
||||
b = await button.new_button(factory_reset_config)
|
||||
await cg.register_parented(b, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_factory_reset_button(b))
|
@ -0,0 +1,9 @@
|
||||
#include "get_radar_parameters_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void GetRadarParametersButton::press_action() { this->parent_->get_radar_parameters(); }
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class GetRadarParametersButton : public button::Button, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
GetRadarParametersButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,9 @@
|
||||
#include "reset_radar_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void ResetRadarButton::press_action() { this->parent_->factory_reset(); }
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class ResetRadarButton : public button::Button, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
ResetRadarButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
368
esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp
Normal file
368
esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp
Normal file
@ -0,0 +1,368 @@
|
||||
#include "seeed_mr60fda2.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <utility>
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
static const char *const TAG = "seeed_mr60fda2";
|
||||
|
||||
// Prints the component's configuration data. dump_config() prints all of the component's configuration
|
||||
// items in an easy-to-read format, including the configuration key-value pairs.
|
||||
void MR60FDA2Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "MR60FDA2:");
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
LOG_BINARY_SENSOR(" ", "People Exist Binary Sensor", this->people_exist_binary_sensor_);
|
||||
LOG_BINARY_SENSOR(" ", "Is Fall Binary Sensor", this->fall_detected_binary_sensor_);
|
||||
#endif
|
||||
#ifdef USE_BUTTON
|
||||
LOG_BUTTON(" ", "Get Radar Parameters Button", this->get_radar_parameters_button_);
|
||||
LOG_BUTTON(" ", "Reset Radar Button", this->factory_reset_button_);
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
LOG_SELECT(" ", "Install Height Select", this->install_height_select_);
|
||||
LOG_SELECT(" ", "Height Threshold Select", this->height_threshold_select_);
|
||||
LOG_SELECT(" ", "Sensitivity Select", this->sensitivity_select_);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Initialisation functions
|
||||
void MR60FDA2Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up MR60FDA2...");
|
||||
this->check_uart_settings(115200);
|
||||
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
this->current_frame_id_ = 0;
|
||||
this->current_frame_len_ = 0;
|
||||
this->current_data_frame_len_ = 0;
|
||||
this->current_frame_type_ = 0;
|
||||
this->get_radar_parameters();
|
||||
|
||||
memset(this->current_frame_buf_, 0, FRAME_BUF_MAX_SIZE);
|
||||
memset(this->current_data_buf_, 0, DATA_BUF_MAX_SIZE);
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Set up MR60FDA2 complete");
|
||||
}
|
||||
|
||||
// main loop
|
||||
void MR60FDA2Component::loop() {
|
||||
uint8_t byte;
|
||||
|
||||
// Is there data on the serial port
|
||||
while (this->available()) {
|
||||
this->read_byte(&byte);
|
||||
this->split_frame_(byte); // split data frame
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the checksum for a byte array.
|
||||
*
|
||||
* This function calculates the checksum for the provided byte array using an
|
||||
* XOR-based checksum algorithm.
|
||||
*
|
||||
* @param data The byte array to calculate the checksum for.
|
||||
* @param len The length of the byte array.
|
||||
* @return The calculated checksum.
|
||||
*/
|
||||
static uint8_t calculate_checksum(const uint8_t *data, size_t len) {
|
||||
uint8_t checksum = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
checksum ^= data[i];
|
||||
}
|
||||
checksum = ~checksum;
|
||||
return checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Validate the checksum of a byte array.
|
||||
*
|
||||
* This function validates the checksum of the provided byte array by comparing
|
||||
* it to the expected checksum.
|
||||
*
|
||||
* @param data The byte array to validate.
|
||||
* @param len The length of the byte array.
|
||||
* @param expected_checksum The expected checksum.
|
||||
* @return True if the checksum is valid, false otherwise.
|
||||
*/
|
||||
static bool validate_checksum(const uint8_t *data, size_t len, uint8_t expected_checksum) {
|
||||
return calculate_checksum(data, len) == expected_checksum;
|
||||
}
|
||||
|
||||
static uint8_t find_nearest_index(float value, const float *arr, int size) {
|
||||
int nearest_index = 0;
|
||||
float min_diff = std::abs(value - arr[0]);
|
||||
for (int i = 1; i < size; ++i) {
|
||||
float diff = std::abs(value - arr[i]);
|
||||
if (diff < min_diff) {
|
||||
min_diff = diff;
|
||||
nearest_index = i;
|
||||
}
|
||||
}
|
||||
return nearest_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a float value to a byte array.
|
||||
*
|
||||
* This function converts a float value to a byte array.
|
||||
*
|
||||
* @param value The float value to convert.
|
||||
* @param bytes The byte array to store the converted value.
|
||||
*/
|
||||
static void float_to_bytes(float value, unsigned char *bytes) {
|
||||
union {
|
||||
float float_value;
|
||||
unsigned char byte_array[4];
|
||||
} u;
|
||||
|
||||
u.float_value = value;
|
||||
memcpy(bytes, u.byte_array, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a 32-bit unsigned integer to a byte array.
|
||||
*
|
||||
* This function converts a 32-bit unsigned integer to a byte array.
|
||||
*
|
||||
* @param value The 32-bit unsigned integer to convert.
|
||||
* @param bytes The byte array to store the converted value.
|
||||
*/
|
||||
static void int_to_bytes(uint32_t value, unsigned char *bytes) {
|
||||
bytes[0] = value & 0xFF;
|
||||
bytes[1] = (value >> 8) & 0xFF;
|
||||
bytes[2] = (value >> 16) & 0xFF;
|
||||
bytes[3] = (value >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
void MR60FDA2Component::split_frame_(uint8_t buffer) {
|
||||
switch (this->current_frame_locate_) {
|
||||
case LOCATE_FRAME_HEADER: // starting buffer
|
||||
if (buffer == FRAME_HEADER_BUFFER) {
|
||||
this->current_frame_len_ = 1;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
}
|
||||
break;
|
||||
case LOCATE_ID_FRAME1:
|
||||
this->current_frame_id_ = buffer << 8;
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
break;
|
||||
case LOCATE_ID_FRAME2:
|
||||
this->current_frame_id_ += buffer;
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
break;
|
||||
case LOCATE_LENGTH_FRAME_H:
|
||||
this->current_data_frame_len_ = buffer << 8;
|
||||
if (this->current_data_frame_len_ == 0x00) {
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
} else {
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
}
|
||||
break;
|
||||
case LOCATE_LENGTH_FRAME_L:
|
||||
this->current_data_frame_len_ += buffer;
|
||||
if (this->current_data_frame_len_ > DATA_BUF_MAX_SIZE) {
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
} else {
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
}
|
||||
break;
|
||||
case LOCATE_TYPE_FRAME1:
|
||||
this->current_frame_type_ = buffer << 8;
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
break;
|
||||
case LOCATE_TYPE_FRAME2:
|
||||
this->current_frame_type_ += buffer;
|
||||
if ((this->current_frame_type_ == IS_FALL_TYPE_BUFFER) ||
|
||||
(this->current_frame_type_ == PEOPLE_EXIST_TYPE_BUFFER) ||
|
||||
(this->current_frame_type_ == RESULT_INSTALL_HEIGHT) || (this->current_frame_type_ == RESULT_PARAMETERS) ||
|
||||
(this->current_frame_type_ == RESULT_HEIGHT_THRESHOLD) || (this->current_frame_type_ == RESULT_SENSITIVITY)) {
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
} else {
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
}
|
||||
break;
|
||||
case LOCATE_HEAD_CKSUM_FRAME:
|
||||
if (validate_checksum(this->current_frame_buf_, this->current_frame_len_, buffer)) {
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
} else {
|
||||
ESP_LOGD(TAG, "HEAD_CKSUM_FRAME ERROR: 0x%02x", buffer);
|
||||
ESP_LOGV(TAG, "CURRENT_FRAME: %s %s",
|
||||
format_hex_pretty(this->current_frame_buf_, this->current_frame_len_).c_str(),
|
||||
format_hex_pretty(&buffer, 1).c_str());
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
}
|
||||
break;
|
||||
case LOCATE_DATA_FRAME:
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_data_buf_[this->current_frame_len_ - LEN_TO_DATA_FRAME] = buffer;
|
||||
if (this->current_frame_len_ - LEN_TO_HEAD_CKSUM == this->current_data_frame_len_) {
|
||||
this->current_frame_locate_++;
|
||||
}
|
||||
if (this->current_frame_len_ > FRAME_BUF_MAX_SIZE) {
|
||||
ESP_LOGD(TAG, "PRACTICE_DATA_FRAME_LEN ERROR: %d", this->current_frame_len_ - LEN_TO_HEAD_CKSUM);
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
}
|
||||
break;
|
||||
case LOCATE_DATA_CKSUM_FRAME:
|
||||
if (validate_checksum(this->current_data_buf_, this->current_data_frame_len_, buffer)) {
|
||||
this->current_frame_len_++;
|
||||
this->current_frame_buf_[this->current_frame_len_ - 1] = buffer;
|
||||
this->current_frame_locate_++;
|
||||
this->process_frame_();
|
||||
} else {
|
||||
ESP_LOGD(TAG, "DATA_CKSUM_FRAME ERROR: 0x%02x", buffer);
|
||||
ESP_LOGV(TAG, "GET CURRENT_FRAME: %s %s",
|
||||
format_hex_pretty(this->current_frame_buf_, this->current_frame_len_).c_str(),
|
||||
format_hex_pretty(&buffer, 1).c_str());
|
||||
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MR60FDA2Component::process_frame_() {
|
||||
switch (this->current_frame_type_) {
|
||||
case IS_FALL_TYPE_BUFFER:
|
||||
if (this->fall_detected_binary_sensor_ != nullptr) {
|
||||
this->fall_detected_binary_sensor_->publish_state(this->current_frame_buf_[LEN_TO_HEAD_CKSUM]);
|
||||
}
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
break;
|
||||
|
||||
case PEOPLE_EXIST_TYPE_BUFFER:
|
||||
if (this->people_exist_binary_sensor_ != nullptr)
|
||||
this->people_exist_binary_sensor_->publish_state(this->current_frame_buf_[LEN_TO_HEAD_CKSUM]);
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
break;
|
||||
|
||||
case RESULT_INSTALL_HEIGHT:
|
||||
if (this->current_data_buf_[0]) {
|
||||
ESP_LOGD(TAG, "Successfully set the mounting height");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Failed to set the mounting height");
|
||||
}
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
break;
|
||||
|
||||
case RESULT_HEIGHT_THRESHOLD:
|
||||
if (this->current_data_buf_[0]) {
|
||||
ESP_LOGD(TAG, "Successfully set the height threshold");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Failed to set the height threshold");
|
||||
}
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
break;
|
||||
|
||||
case RESULT_SENSITIVITY:
|
||||
if (this->current_data_buf_[0]) {
|
||||
ESP_LOGD(TAG, "Successfully set the sensitivity");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Failed to set the sensitivity");
|
||||
}
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
break;
|
||||
|
||||
case RESULT_PARAMETERS: {
|
||||
float install_height_float = 0;
|
||||
float height_threshold_float = 0;
|
||||
uint32_t current_sensitivity = 0;
|
||||
if (this->install_height_select_ != nullptr) {
|
||||
uint32_t current_install_height_int =
|
||||
encode_uint32(current_data_buf_[3], current_data_buf_[2], current_data_buf_[1], current_data_buf_[0]);
|
||||
|
||||
install_height_float = bit_cast<float>(current_install_height_int);
|
||||
uint32_t select_index = find_nearest_index(install_height_float, INSTALL_HEIGHT, 7);
|
||||
this->install_height_select_->publish_state(this->install_height_select_->at(select_index).value());
|
||||
}
|
||||
|
||||
if (this->height_threshold_select_ != nullptr) {
|
||||
uint32_t current_height_threshold_int =
|
||||
encode_uint32(current_data_buf_[7], current_data_buf_[6], current_data_buf_[5], current_data_buf_[4]);
|
||||
|
||||
height_threshold_float = bit_cast<float>(current_height_threshold_int);
|
||||
size_t select_index = find_nearest_index(height_threshold_float, HEIGHT_THRESHOLD, 7);
|
||||
this->height_threshold_select_->publish_state(this->height_threshold_select_->at(select_index).value());
|
||||
}
|
||||
|
||||
if (this->sensitivity_select_ != nullptr) {
|
||||
current_sensitivity =
|
||||
encode_uint32(current_data_buf_[11], current_data_buf_[10], current_data_buf_[9], current_data_buf_[8]);
|
||||
|
||||
uint32_t select_index = find_nearest_index(current_sensitivity, SENSITIVITY, 3);
|
||||
this->sensitivity_select_->publish_state(this->sensitivity_select_->at(select_index).value());
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Mounting height: %.2f, Height threshold: %.2f, Sensitivity: %" PRIu32, install_height_float,
|
||||
height_threshold_float, current_sensitivity);
|
||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Send Heartbeat Packet Command
|
||||
void MR60FDA2Component::set_install_height(uint8_t index) {
|
||||
uint8_t send_data[13] = {0x01, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x04, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
float_to_bytes(INSTALL_HEIGHT[index], &send_data[8]);
|
||||
send_data[12] = calculate_checksum(send_data + 8, 4);
|
||||
this->write_array(send_data, 13);
|
||||
ESP_LOGV(TAG, "SEND INSTALL HEIGHT FRAME: %s", format_hex_pretty(send_data, 13).c_str());
|
||||
}
|
||||
|
||||
void MR60FDA2Component::set_height_threshold(uint8_t index) {
|
||||
uint8_t send_data[13] = {0x01, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x08, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
float_to_bytes(INSTALL_HEIGHT[index], &send_data[8]);
|
||||
send_data[12] = calculate_checksum(send_data + 8, 4);
|
||||
this->write_array(send_data, 13);
|
||||
ESP_LOGV(TAG, "SEND HEIGHT THRESHOLD: %s", format_hex_pretty(send_data, 13).c_str());
|
||||
}
|
||||
|
||||
void MR60FDA2Component::set_sensitivity(uint8_t index) {
|
||||
uint8_t send_data[13] = {0x01, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x0A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
int_to_bytes(SENSITIVITY[index], &send_data[8]);
|
||||
|
||||
send_data[12] = calculate_checksum(send_data + 8, 4);
|
||||
this->write_array(send_data, 13);
|
||||
ESP_LOGV(TAG, "SEND SET SENSITIVITY: %s", format_hex_pretty(send_data, 13).c_str());
|
||||
}
|
||||
|
||||
void MR60FDA2Component::get_radar_parameters() {
|
||||
uint8_t send_data[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x06, 0xF6};
|
||||
this->write_array(send_data, 8);
|
||||
ESP_LOGV(TAG, "SEND GET PARAMETERS: %s", format_hex_pretty(send_data, 8).c_str());
|
||||
}
|
||||
|
||||
void MR60FDA2Component::factory_reset() {
|
||||
uint8_t send_data[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x21, 0x10, 0xCF};
|
||||
this->write_array(send_data, 8);
|
||||
ESP_LOGV(TAG, "SEND RESET: %s", format_hex_pretty(send_data, 8).c_str());
|
||||
this->get_radar_parameters();
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
101
esphome/components/seeed_mr60fda2/seeed_mr60fda2.h
Normal file
101
esphome/components/seeed_mr60fda2/seeed_mr60fda2.h
Normal file
@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#endif
|
||||
#ifdef USE_BUTTON
|
||||
#include "esphome/components/button/button.h"
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
#include "esphome/components/select/select.h"
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#endif
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
static const uint8_t DATA_BUF_MAX_SIZE = 28;
|
||||
static const uint8_t FRAME_BUF_MAX_SIZE = 37;
|
||||
static const uint8_t LEN_TO_HEAD_CKSUM = 8;
|
||||
static const uint8_t LEN_TO_DATA_FRAME = 9;
|
||||
|
||||
static const uint8_t FRAME_HEADER_BUFFER = 0x01;
|
||||
static const uint16_t IS_FALL_TYPE_BUFFER = 0x0E02;
|
||||
static const uint16_t PEOPLE_EXIST_TYPE_BUFFER = 0x0F09;
|
||||
static const uint16_t RESULT_INSTALL_HEIGHT = 0x0E04;
|
||||
static const uint16_t RESULT_PARAMETERS = 0x0E06;
|
||||
static const uint16_t RESULT_HEIGHT_THRESHOLD = 0x0E08;
|
||||
static const uint16_t RESULT_SENSITIVITY = 0x0E0A;
|
||||
|
||||
enum FrameLocation {
|
||||
LOCATE_FRAME_HEADER,
|
||||
LOCATE_ID_FRAME1,
|
||||
LOCATE_ID_FRAME2,
|
||||
LOCATE_LENGTH_FRAME_H,
|
||||
LOCATE_LENGTH_FRAME_L,
|
||||
LOCATE_TYPE_FRAME1,
|
||||
LOCATE_TYPE_FRAME2,
|
||||
LOCATE_HEAD_CKSUM_FRAME, // Header checksum: [from the first byte to the previous byte of the HEAD_CKSUM bit]
|
||||
LOCATE_DATA_FRAME,
|
||||
LOCATE_DATA_CKSUM_FRAME, // Data checksum: [from the first to the previous byte of the DATA_CKSUM bit]
|
||||
LOCATE_PROCESS_FRAME,
|
||||
};
|
||||
|
||||
static const float INSTALL_HEIGHT[7] = {2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f};
|
||||
static const float HEIGHT_THRESHOLD[7] = {0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f};
|
||||
static const float SENSITIVITY[3] = {3, 15, 30};
|
||||
|
||||
static const char *const INSTALL_HEIGHT_STR[7] = {"2.4m", "2.5m", "2.6", "2.7m", "2.8", "2.9m", "3.0m"};
|
||||
static const char *const HEIGHT_THRESHOLD_STR[7] = {"0.0m", "0.1m", "0.2m", "0.3m", "0.4m", "0.5m", "0.6m"};
|
||||
static const char *const SENSITIVITY_STR[3] = {"1", "2", "3"};
|
||||
|
||||
class MR60FDA2Component : public Component,
|
||||
public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
SUB_BINARY_SENSOR(people_exist)
|
||||
SUB_BINARY_SENSOR(fall_detected)
|
||||
#endif
|
||||
#ifdef USE_BUTTON
|
||||
SUB_BUTTON(get_radar_parameters)
|
||||
SUB_BUTTON(factory_reset)
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
SUB_SELECT(install_height)
|
||||
SUB_SELECT(height_threshold)
|
||||
SUB_SELECT(sensitivity)
|
||||
#endif
|
||||
|
||||
protected:
|
||||
uint8_t current_frame_locate_;
|
||||
uint8_t current_frame_buf_[FRAME_BUF_MAX_SIZE];
|
||||
uint8_t current_data_buf_[DATA_BUF_MAX_SIZE];
|
||||
uint16_t current_frame_id_;
|
||||
size_t current_frame_len_;
|
||||
size_t current_data_frame_len_;
|
||||
uint16_t current_frame_type_;
|
||||
|
||||
void split_frame_(uint8_t buffer);
|
||||
void process_frame_();
|
||||
|
||||
public:
|
||||
float get_setup_priority() const override { return esphome::setup_priority::LATE; }
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void loop() override;
|
||||
void set_install_height(uint8_t index);
|
||||
void set_height_threshold(uint8_t index);
|
||||
void set_sensitivity(uint8_t index);
|
||||
void get_radar_parameters();
|
||||
void factory_reset();
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
59
esphome/components/seeed_mr60fda2/select/__init__.py
Normal file
59
esphome/components/seeed_mr60fda2/select/__init__.py
Normal file
@ -0,0 +1,59 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import select
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_SENSITIVITY, ENTITY_CATEGORY_CONFIG, ICON_ACCELERATION_Z
|
||||
|
||||
from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns
|
||||
|
||||
|
||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||
|
||||
InstallHeightSelect = mr60fda2_ns.class_("InstallHeightSelect", select.Select)
|
||||
HeightThresholdSelect = mr60fda2_ns.class_("HeightThresholdSelect", select.Select)
|
||||
SensitivitySelect = mr60fda2_ns.class_("SensitivitySelect", select.Select)
|
||||
|
||||
CONF_INSTALL_HEIGHT = "install_height"
|
||||
CONF_HEIGHT_THRESHOLD = "height_threshold"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||
cv.Optional(CONF_INSTALL_HEIGHT): select.select_schema(
|
||||
InstallHeightSelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_ACCELERATION_Z,
|
||||
),
|
||||
cv.Optional(CONF_HEIGHT_THRESHOLD): select.select_schema(
|
||||
HeightThresholdSelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_ACCELERATION_Z,
|
||||
),
|
||||
cv.Optional(CONF_SENSITIVITY): select.select_schema(
|
||||
SensitivitySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
||||
if install_height_config := config.get(CONF_INSTALL_HEIGHT):
|
||||
s = await select.new_select(
|
||||
install_height_config,
|
||||
options=["2.4m", "2.5m", "2.6m", "2.7m", "2.8m", "2.9m", "3.0m"],
|
||||
)
|
||||
await cg.register_parented(s, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_install_height_select(s))
|
||||
if height_threshold_config := config.get(CONF_HEIGHT_THRESHOLD):
|
||||
s = await select.new_select(
|
||||
height_threshold_config,
|
||||
options=["0.0m", "0.1m", "0.2m", "0.3m", "0.4m", "0.5m", "0.6m"],
|
||||
)
|
||||
await cg.register_parented(s, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_height_threshold_select(s))
|
||||
if sensitivity_config := config.get(CONF_SENSITIVITY):
|
||||
s = await select.new_select(
|
||||
sensitivity_config,
|
||||
options=["1", "2", "3"],
|
||||
)
|
||||
await cg.register_parented(s, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_sensitivity_select(s))
|
@ -0,0 +1,15 @@
|
||||
#include "height_threshold_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void HeightThresholdSelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value()) {
|
||||
this->parent_->set_height_threshold(index.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class HeightThresholdSelect : public select::Select, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
HeightThresholdSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,15 @@
|
||||
#include "install_height_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void InstallHeightSelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value()) {
|
||||
this->parent_->set_install_height(index.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class InstallHeightSelect : public select::Select, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
InstallHeightSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,15 @@
|
||||
#include "sensitivity_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void SensitivitySelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value()) {
|
||||
this->parent_->set_sensitivity(index.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class SensitivitySelect : public select::Select, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
SensitivitySelect() = default;
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
@ -466,7 +466,7 @@ bool ShellyDimmer::handle_frame_() {
|
||||
}
|
||||
case SHELLY_DIMMER_PROTO_CMD_SWITCH:
|
||||
case SHELLY_DIMMER_PROTO_CMD_SETTINGS: {
|
||||
return !(payload_len < 1 || payload[0] != 0x01);
|
||||
return payload_len >= 1 && payload[0] == 0x01;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
|
@ -324,7 +324,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
|
||||
this->sms_received_callback_.call(this->message_, this->sender_);
|
||||
this->state_ = STATE_RECEIVED_SMS;
|
||||
} else {
|
||||
if (this->message_.length() > 0)
|
||||
if (!this->message_.empty())
|
||||
this->message_ += "\n";
|
||||
this->message_ += message;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ from esphome.const import CONF_DATA, CONF_ID, CONF_VOLUME
|
||||
from esphome.core import CORE
|
||||
from esphome.coroutine import coroutine_with_priority
|
||||
|
||||
AUTO_LOAD = ["audio"]
|
||||
CODEOWNERS = ["@jesserockz", "@kahrendt"]
|
||||
|
||||
IS_PLATFORM_COMPONENT = True
|
||||
|
@ -419,7 +419,7 @@ void Sprinkler::add_valve(SprinklerControllerSwitch *valve_sw, SprinklerControll
|
||||
SprinklerValve *new_valve = &this->valve_[new_valve_number];
|
||||
|
||||
new_valve->controller_switch = valve_sw;
|
||||
new_valve->controller_switch->set_state_lambda([=]() -> optional<bool> {
|
||||
new_valve->controller_switch->set_state_lambda([this, new_valve_number]() -> optional<bool> {
|
||||
if (this->valve_pump_switch(new_valve_number) != nullptr) {
|
||||
return this->valve_switch(new_valve_number)->state() && this->valve_pump_switch(new_valve_number)->state();
|
||||
}
|
||||
@ -445,7 +445,7 @@ void Sprinkler::add_controller(Sprinkler *other_controller) { this->other_contro
|
||||
|
||||
void Sprinkler::set_controller_main_switch(SprinklerControllerSwitch *controller_switch) {
|
||||
this->controller_sw_ = controller_switch;
|
||||
controller_switch->set_state_lambda([=]() -> optional<bool> {
|
||||
controller_switch->set_state_lambda([this]() -> optional<bool> {
|
||||
for (size_t valve_number = 0; valve_number < this->number_of_valves(); valve_number++) {
|
||||
if (this->valve_[valve_number].controller_switch->state) {
|
||||
return true;
|
||||
|
@ -6,6 +6,8 @@ from esphome.const import (
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["network"]
|
||||
|
||||
status_ns = cg.esphome_ns.namespace("status")
|
||||
StatusBinarySensor = status_ns.class_(
|
||||
"StatusBinarySensor", binary_sensor.BinarySensor, cg.Component
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/stepper/stepper.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace stepper {
|
||||
|
@ -83,7 +83,7 @@ void SunGTIL2::handle_char_(uint8_t c) {
|
||||
memcpy(&msg, this->rx_message_.data(), MESSAGE_SIZE);
|
||||
this->rx_message_.clear();
|
||||
|
||||
if (!((msg.end[0] == 0) && (msg.end[38] == 0x08)))
|
||||
if ((msg.end[0] != 0) || (msg.end[38] != 0x08))
|
||||
return;
|
||||
|
||||
ESP_LOGVV(TAG, "Frequency raw value: %02x", msg.frequency);
|
||||
|
31
esphome/components/switch/binary_sensor/__init__.py
Normal file
31
esphome/components/switch/binary_sensor/__init__.py
Normal file
@ -0,0 +1,31 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import binary_sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_SOURCE_ID
|
||||
|
||||
from .. import Switch, switch_ns
|
||||
|
||||
CODEOWNERS = ["@ssieb"]
|
||||
|
||||
SwitchBinarySensor = switch_ns.class_(
|
||||
"SwitchBinarySensor", binary_sensor.BinarySensor, cg.Component
|
||||
)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
binary_sensor.binary_sensor_schema(SwitchBinarySensor)
|
||||
.extend(
|
||||
{
|
||||
cv.Required(CONF_SOURCE_ID): cv.use_id(Switch),
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await binary_sensor.new_binary_sensor(config)
|
||||
await cg.register_component(var, config)
|
||||
|
||||
source = await cg.get_variable(config[CONF_SOURCE_ID])
|
||||
cg.add(var.set_source(source))
|
@ -0,0 +1,17 @@
|
||||
#include "switch_binary_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace switch_ {
|
||||
|
||||
static const char *const TAG = "switch.binary_sensor";
|
||||
|
||||
void SwitchBinarySensor::setup() {
|
||||
source_->add_on_state_callback([this](bool value) { this->publish_state(value); });
|
||||
this->publish_state(source_->state);
|
||||
}
|
||||
|
||||
void SwitchBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Switch Binary Sensor", this); }
|
||||
|
||||
} // namespace switch_
|
||||
} // namespace esphome
|
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "../switch.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace switch_ {
|
||||
|
||||
class SwitchBinarySensor : public binary_sensor::BinarySensor, public Component {
|
||||
public:
|
||||
void set_source(Switch *source) { source_ = source; }
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||
|
||||
protected:
|
||||
Switch *source_;
|
||||
};
|
||||
|
||||
} // namespace switch_
|
||||
} // namespace esphome
|
@ -1,5 +1,6 @@
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "sx1509.h"
|
||||
#include "sx1509_gpio_pin.h"
|
||||
|
||||
namespace esphome {
|
||||
@ -13,7 +14,7 @@ bool SX1509GPIOPin::digital_read() { return this->parent_->digital_read(this->pi
|
||||
void SX1509GPIOPin::digital_write(bool value) { this->parent_->digital_write(this->pin_, value != this->inverted_); }
|
||||
std::string SX1509GPIOPin::dump_summary() const {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%u via sx1509", pin_);
|
||||
snprintf(buffer, sizeof(buffer), "%u via sx1509", this->pin_);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "sx1509.h"
|
||||
#include "esphome/core/gpio.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace sx1509 {
|
||||
@ -15,10 +15,10 @@ class SX1509GPIOPin : public GPIOPin {
|
||||
void digital_write(bool value) override;
|
||||
std::string dump_summary() const override;
|
||||
|
||||
void set_parent(SX1509Component *parent) { parent_ = parent; }
|
||||
void set_pin(uint8_t pin) { pin_ = pin; }
|
||||
void set_inverted(bool inverted) { inverted_ = inverted; }
|
||||
void set_flags(gpio::Flags flags) { flags_ = flags; }
|
||||
void set_parent(SX1509Component *parent) { this->parent_ = parent; }
|
||||
void set_pin(uint8_t pin) { this->pin_ = pin; }
|
||||
void set_inverted(bool inverted) { this->inverted_ = inverted; }
|
||||
void set_flags(gpio::Flags flags) { this->flags_ = flags; }
|
||||
|
||||
protected:
|
||||
SX1509Component *parent_;
|
||||
|
@ -40,7 +40,7 @@ class UARTDevice {
|
||||
|
||||
int available() { return this->parent_->available(); }
|
||||
|
||||
void flush() { return this->parent_->flush(); }
|
||||
void flush() { this->parent_->flush(); }
|
||||
|
||||
// Compat APIs
|
||||
int read() {
|
||||
|
@ -27,6 +27,9 @@ WaveshareEPaperBWR = waveshare_epaper_ns.class_(
|
||||
WaveshareEPaperTypeA = waveshare_epaper_ns.class_(
|
||||
"WaveshareEPaperTypeA", WaveshareEPaper
|
||||
)
|
||||
WaveshareEpaper1P54INBV2 = waveshare_epaper_ns.class_(
|
||||
"WaveshareEPaper1P54InBV2", WaveshareEPaperBWR
|
||||
)
|
||||
WaveshareEPaper2P7In = waveshare_epaper_ns.class_(
|
||||
"WaveshareEPaper2P7In", WaveshareEPaper
|
||||
)
|
||||
@ -76,6 +79,9 @@ WaveshareEPaper7P5InBV2 = waveshare_epaper_ns.class_(
|
||||
WaveshareEPaper7P5InBV3 = waveshare_epaper_ns.class_(
|
||||
"WaveshareEPaper7P5InBV3", WaveshareEPaper
|
||||
)
|
||||
WaveshareEPaper7P5InBV3BWR = waveshare_epaper_ns.class_(
|
||||
"WaveshareEPaper7P5InBV3BWR", WaveshareEPaperBWR
|
||||
)
|
||||
WaveshareEPaper7P5InV2 = waveshare_epaper_ns.class_(
|
||||
"WaveshareEPaper7P5InV2", WaveshareEPaper
|
||||
)
|
||||
@ -105,6 +111,7 @@ WaveshareEPaperTypeBModel = waveshare_epaper_ns.enum("WaveshareEPaperTypeBModel"
|
||||
MODELS = {
|
||||
"1.54in": ("a", WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_1_54_IN),
|
||||
"1.54inv2": ("a", WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_1_54_IN_V2),
|
||||
"1.54inv2-b": ("b", WaveshareEpaper1P54INBV2),
|
||||
"2.13in": ("a", WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_13_IN),
|
||||
"2.13inv2": ("a", WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_13_IN_V2),
|
||||
"2.13in-ttgo": ("a", WaveshareEPaperTypeAModel.TTGO_EPAPER_2_13_IN),
|
||||
@ -129,6 +136,7 @@ MODELS = {
|
||||
"7.50in": ("b", WaveshareEPaper7P5In),
|
||||
"7.50in-bv2": ("b", WaveshareEPaper7P5InBV2),
|
||||
"7.50in-bv3": ("b", WaveshareEPaper7P5InBV3),
|
||||
"7.50in-bv3-bwr": ("b", WaveshareEPaper7P5InBV3BWR),
|
||||
"7.50in-bc": ("b", WaveshareEPaper7P5InBC),
|
||||
"7.50inv2": ("b", WaveshareEPaper7P5InV2),
|
||||
"7.50inv2alt": ("b", WaveshareEPaper7P5InV2alt),
|
||||
|
@ -808,6 +808,90 @@ void WaveshareEPaper2P7InV2::dump_config() {
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
// ========================================================
|
||||
// 1.54inch_v2_e-paper_b
|
||||
// ========================================================
|
||||
// Datasheet:
|
||||
// - https://files.waveshare.com/upload/9/9e/1.54inch-e-paper-b-v2-specification.pdf
|
||||
// - https://www.waveshare.com/wiki/1.54inch_e-Paper_Module_(B)_Manual
|
||||
|
||||
void WaveshareEPaper1P54InBV2::initialize() {
|
||||
this->reset_();
|
||||
|
||||
this->wait_until_idle_();
|
||||
|
||||
this->command(0x12);
|
||||
this->wait_until_idle_();
|
||||
|
||||
this->command(0x01);
|
||||
this->data(0xC7);
|
||||
this->data(0x00);
|
||||
this->data(0x01);
|
||||
|
||||
this->command(0x11); // data entry mode
|
||||
this->data(0x01);
|
||||
|
||||
this->command(0x44); // set Ram-X address start/end position
|
||||
this->data(0x00);
|
||||
this->data(0x18); // 0x18-->(24+1)*8=200
|
||||
|
||||
this->command(0x45); // set Ram-Y address start/end position
|
||||
this->data(0xC7); // 0xC7-->(199+1)=200
|
||||
this->data(0x00);
|
||||
this->data(0x00);
|
||||
this->data(0x00);
|
||||
|
||||
this->command(0x3C); // BorderWavefrom
|
||||
this->data(0x05);
|
||||
|
||||
this->command(0x18); // Read built-in temperature sensor
|
||||
this->data(0x80);
|
||||
|
||||
this->command(0x4E); // set RAM x address count to 0;
|
||||
this->data(0x00);
|
||||
this->command(0x4F); // set RAM y address count to 0X199;
|
||||
this->data(0xC7);
|
||||
this->data(0x00);
|
||||
|
||||
this->wait_until_idle_();
|
||||
}
|
||||
|
||||
void HOT WaveshareEPaper1P54InBV2::display() {
|
||||
uint32_t buf_len_half = this->get_buffer_length_() >> 1;
|
||||
this->initialize();
|
||||
|
||||
// COMMAND DATA START TRANSMISSION 1 (BLACK)
|
||||
this->command(0x24);
|
||||
delay(2);
|
||||
for (uint32_t i = 0; i < buf_len_half; i++) {
|
||||
this->data(~this->buffer_[i]);
|
||||
}
|
||||
delay(2);
|
||||
|
||||
// COMMAND DATA START TRANSMISSION 2 (RED)
|
||||
this->command(0x26);
|
||||
delay(2);
|
||||
for (uint32_t i = buf_len_half; i < buf_len_half * 2u; i++) {
|
||||
this->data(this->buffer_[i]);
|
||||
}
|
||||
this->command(0x22);
|
||||
this->data(0xf7);
|
||||
this->command(0x20);
|
||||
this->wait_until_idle_();
|
||||
|
||||
this->deep_sleep();
|
||||
}
|
||||
int WaveshareEPaper1P54InBV2::get_height_internal() { return 200; }
|
||||
int WaveshareEPaper1P54InBV2::get_width_internal() { return 200; }
|
||||
void WaveshareEPaper1P54InBV2::dump_config() {
|
||||
LOG_DISPLAY("", "Waveshare E-Paper", this);
|
||||
ESP_LOGCONFIG(TAG, " Model: 1.54in V2 B");
|
||||
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
||||
LOG_PIN(" DC Pin: ", this->dc_pin_);
|
||||
LOG_PIN(" Busy Pin: ", this->busy_pin_);
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
// ========================================================
|
||||
// 2.7inch_e-paper_b
|
||||
// ========================================================
|
||||
@ -2315,6 +2399,113 @@ void WaveshareEPaper7P5InBV3::dump_config() {
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
void WaveshareEPaper7P5InBV3BWR::initialize() { this->init_display_(); }
|
||||
bool WaveshareEPaper7P5InBV3BWR::wait_until_idle_() {
|
||||
if (this->busy_pin_ == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint32_t start = millis();
|
||||
while (this->busy_pin_->digital_read()) {
|
||||
this->command(0x71);
|
||||
if (millis() - start > this->idle_timeout_()) {
|
||||
ESP_LOGI(TAG, "Timeout while displaying image!");
|
||||
return false;
|
||||
}
|
||||
App.feed_wdt();
|
||||
delay(10);
|
||||
}
|
||||
delay(200); // NOLINT
|
||||
return true;
|
||||
};
|
||||
void WaveshareEPaper7P5InBV3BWR::init_display_() {
|
||||
this->reset_();
|
||||
|
||||
// COMMAND POWER SETTING
|
||||
this->command(0x01);
|
||||
|
||||
// 1-0=11: internal power
|
||||
this->data(0x07);
|
||||
this->data(0x17); // VGH&VGL
|
||||
this->data(0x3F); // VSH
|
||||
this->data(0x26); // VSL
|
||||
this->data(0x11); // VSHR
|
||||
|
||||
// VCOM DC Setting
|
||||
this->command(0x82);
|
||||
this->data(0x24); // VCOM
|
||||
|
||||
// Booster Setting
|
||||
this->command(0x06);
|
||||
this->data(0x27);
|
||||
this->data(0x27);
|
||||
this->data(0x2F);
|
||||
this->data(0x17);
|
||||
|
||||
// POWER ON
|
||||
this->command(0x04);
|
||||
|
||||
delay(100); // NOLINT
|
||||
this->wait_until_idle_();
|
||||
// COMMAND PANEL SETTING
|
||||
this->command(0x00);
|
||||
this->data(0x0F); // KW-3f KWR-2F BWROTP 0f BWOTP 1f
|
||||
|
||||
// COMMAND RESOLUTION SETTING
|
||||
this->command(0x61);
|
||||
this->data(0x03); // source 800
|
||||
this->data(0x20);
|
||||
this->data(0x01); // gate 480
|
||||
this->data(0xE0);
|
||||
// COMMAND ...?
|
||||
this->command(0x15);
|
||||
this->data(0x00);
|
||||
// COMMAND VCOM AND DATA INTERVAL SETTING
|
||||
this->command(0x50);
|
||||
this->data(0x20);
|
||||
this->data(0x00);
|
||||
// COMMAND TCON SETTING
|
||||
this->command(0x60);
|
||||
this->data(0x22);
|
||||
// Resolution setting
|
||||
this->command(0x65);
|
||||
this->data(0x00);
|
||||
this->data(0x00); // 800*480
|
||||
this->data(0x00);
|
||||
this->data(0x00);
|
||||
};
|
||||
void HOT WaveshareEPaper7P5InBV3BWR::display() {
|
||||
this->init_display_();
|
||||
const uint32_t buf_len = this->get_buffer_length_() / 2u;
|
||||
|
||||
this->command(0x10); // Send BW data Transmission
|
||||
delay(2);
|
||||
for (uint32_t i = 0; i < buf_len; i++) {
|
||||
this->data(this->buffer_[i]);
|
||||
}
|
||||
|
||||
this->command(0x13); // Send red data Transmission
|
||||
delay(2);
|
||||
for (uint32_t i = 0; i < buf_len; i++) {
|
||||
this->data(this->buffer_[i + buf_len]);
|
||||
}
|
||||
|
||||
this->command(0x12); // Display Refresh
|
||||
delay(100); // NOLINT
|
||||
this->wait_until_idle_();
|
||||
this->deep_sleep();
|
||||
}
|
||||
int WaveshareEPaper7P5InBV3BWR::get_width_internal() { return 800; }
|
||||
int WaveshareEPaper7P5InBV3BWR::get_height_internal() { return 480; }
|
||||
void WaveshareEPaper7P5InBV3BWR::dump_config() {
|
||||
LOG_DISPLAY("", "Waveshare E-Paper", this);
|
||||
ESP_LOGCONFIG(TAG, " Model: 7.5in-bv3 BWR-Mode");
|
||||
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
||||
LOG_PIN(" DC Pin: ", this->dc_pin_);
|
||||
LOG_PIN(" Busy Pin: ", this->busy_pin_);
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
void WaveshareEPaper7P5In::initialize() {
|
||||
// COMMAND POWER SETTING
|
||||
this->command(0x01);
|
||||
|
@ -166,6 +166,24 @@ enum WaveshareEPaperTypeBModel {
|
||||
WAVESHARE_EPAPER_13_3_IN_K,
|
||||
};
|
||||
|
||||
class WaveshareEPaper1P54InBV2 : public WaveshareEPaperBWR {
|
||||
public:
|
||||
void initialize() override;
|
||||
|
||||
void display() override;
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
void deep_sleep() override {
|
||||
this->command(0x10);
|
||||
this->data(0x01);
|
||||
}
|
||||
|
||||
protected:
|
||||
int get_width_internal() override;
|
||||
int get_height_internal() override;
|
||||
};
|
||||
|
||||
class WaveshareEPaper2P7In : public WaveshareEPaper {
|
||||
public:
|
||||
void initialize() override;
|
||||
@ -619,6 +637,44 @@ class WaveshareEPaper7P5InBV3 : public WaveshareEPaper {
|
||||
void init_display_();
|
||||
};
|
||||
|
||||
class WaveshareEPaper7P5InBV3BWR : public WaveshareEPaperBWR {
|
||||
public:
|
||||
bool wait_until_idle_();
|
||||
|
||||
void initialize() override;
|
||||
|
||||
void display() override;
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
void deep_sleep() override {
|
||||
this->command(0x02); // Power off
|
||||
this->wait_until_idle_();
|
||||
this->command(0x07); // Deep sleep
|
||||
this->data(0xA5);
|
||||
}
|
||||
|
||||
void clear_screen();
|
||||
|
||||
protected:
|
||||
int get_width_internal() override;
|
||||
|
||||
int get_height_internal() override;
|
||||
|
||||
void reset_() {
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
this->reset_pin_->digital_write(true);
|
||||
delay(200); // NOLINT
|
||||
this->reset_pin_->digital_write(false);
|
||||
delay(5);
|
||||
this->reset_pin_->digital_write(true);
|
||||
delay(200); // NOLINT
|
||||
}
|
||||
};
|
||||
|
||||
void init_display_();
|
||||
};
|
||||
|
||||
class WaveshareEPaper7P5InBC : public WaveshareEPaper {
|
||||
public:
|
||||
void initialize() override;
|
||||
|
@ -1,8 +1,8 @@
|
||||
from esphome import automation, pins
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins, automation
|
||||
from esphome.components import key_provider
|
||||
from esphome.const import CONF_ID, CONF_ON_TAG, CONF_TRIGGER_ID
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID, CONF_ON_KEY, CONF_ON_TAG, CONF_TRIGGER_ID
|
||||
|
||||
CODEOWNERS = ["@ssieb"]
|
||||
|
||||
@ -25,7 +25,6 @@ WiegandKeyTrigger = wiegand_ns.class_(
|
||||
|
||||
CONF_D0 = "d0"
|
||||
CONF_D1 = "d1"
|
||||
CONF_ON_KEY = "on_key"
|
||||
CONF_ON_RAW = "on_raw"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
|
@ -27,6 +27,7 @@ from esphome.const import (
|
||||
CONF_NETWORKS,
|
||||
CONF_ON_CONNECT,
|
||||
CONF_ON_DISCONNECT,
|
||||
CONF_ON_ERROR,
|
||||
CONF_PASSWORD,
|
||||
CONF_POWER_SAVE_MODE,
|
||||
CONF_PRIORITY,
|
||||
@ -34,6 +35,7 @@ from esphome.const import (
|
||||
CONF_SSID,
|
||||
CONF_STATIC_IP,
|
||||
CONF_SUBNET,
|
||||
CONF_TIMEOUT,
|
||||
CONF_TTLS_PHASE_2,
|
||||
CONF_USE_ADDRESS,
|
||||
CONF_USERNAME,
|
||||
@ -46,6 +48,7 @@ from . import wpa2_eap
|
||||
AUTO_LOAD = ["network"]
|
||||
|
||||
NO_WIFI_VARIANTS = [const.VARIANT_ESP32H2]
|
||||
CONF_SAVE = "save"
|
||||
|
||||
wifi_ns = cg.esphome_ns.namespace("wifi")
|
||||
EAPAuth = wifi_ns.struct("EAPAuth")
|
||||
@ -63,6 +66,9 @@ WiFiConnectedCondition = wifi_ns.class_("WiFiConnectedCondition", Condition)
|
||||
WiFiEnabledCondition = wifi_ns.class_("WiFiEnabledCondition", Condition)
|
||||
WiFiEnableAction = wifi_ns.class_("WiFiEnableAction", automation.Action)
|
||||
WiFiDisableAction = wifi_ns.class_("WiFiDisableAction", automation.Action)
|
||||
WiFiConfigureAction = wifi_ns.class_(
|
||||
"WiFiConfigureAction", automation.Action, cg.Component
|
||||
)
|
||||
|
||||
|
||||
def validate_password(value):
|
||||
@ -483,3 +489,39 @@ async def wifi_enable_to_code(config, action_id, template_arg, args):
|
||||
@automation.register_action("wifi.disable", WiFiDisableAction, cv.Schema({}))
|
||||
async def wifi_disable_to_code(config, action_id, template_arg, args):
|
||||
return cg.new_Pvariable(action_id, template_arg)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"wifi.configure",
|
||||
WiFiConfigureAction,
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_SSID): cv.templatable(cv.ssid),
|
||||
cv.Required(CONF_PASSWORD): cv.templatable(validate_password),
|
||||
cv.Optional(CONF_SAVE, default=True): cv.templatable(cv.boolean),
|
||||
cv.Optional(CONF_TIMEOUT, default="30000ms"): cv.templatable(
|
||||
cv.positive_time_period_milliseconds
|
||||
),
|
||||
cv.Optional(CONF_ON_CONNECT): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_ON_ERROR): automation.validate_automation(single=True),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def wifi_set_sta_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
ssid = await cg.templatable(config[CONF_SSID], args, cg.std_string)
|
||||
password = await cg.templatable(config[CONF_PASSWORD], args, cg.std_string)
|
||||
save = await cg.templatable(config[CONF_SAVE], args, cg.bool_)
|
||||
timeout = await cg.templatable(config.get(CONF_TIMEOUT), args, cg.uint32)
|
||||
cg.add(var.set_ssid(ssid))
|
||||
cg.add(var.set_password(password))
|
||||
cg.add(var.set_save(save))
|
||||
cg.add(var.set_connection_timeout(timeout))
|
||||
if on_connect_config := config.get(CONF_ON_CONNECT):
|
||||
await automation.build_automation(
|
||||
var.get_connect_trigger(), [], on_connect_config
|
||||
)
|
||||
if on_error_config := config.get(CONF_ON_ERROR):
|
||||
await automation.build_automation(var.get_error_trigger(), [], on_error_config)
|
||||
await cg.register_component(var, config)
|
||||
return var
|
||||
|
@ -444,7 +444,7 @@ void WiFiComponent::print_connect_params_() {
|
||||
if (this->selected_ap_.get_bssid().has_value()) {
|
||||
ESP_LOGV(TAG, " Priority: %.1f", this->get_sta_priority(*this->selected_ap_.get_bssid()));
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Channel: %" PRId32, wifi_channel_());
|
||||
ESP_LOGCONFIG(TAG, " Channel: %" PRId32, get_wifi_channel());
|
||||
ESP_LOGCONFIG(TAG, " Subnet: %s", wifi_subnet_mask_().str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Gateway: %s", wifi_gateway_ip_().str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " DNS1: %s", wifi_dns_ip_(0).str().c_str());
|
||||
@ -763,7 +763,7 @@ void WiFiComponent::load_fast_connect_settings_() {
|
||||
|
||||
void WiFiComponent::save_fast_connect_settings_() {
|
||||
bssid_t bssid = wifi_bssid();
|
||||
uint8_t channel = wifi_channel_();
|
||||
uint8_t channel = get_wifi_channel();
|
||||
|
||||
if (bssid != this->selected_ap_.get_bssid() || channel != this->selected_ap_.get_channel()) {
|
||||
SavedWifiFastConnectSettings fast_connect_save{};
|
||||
|
@ -209,6 +209,7 @@ class WiFiComponent : public Component {
|
||||
WiFiComponent();
|
||||
|
||||
void set_sta(const WiFiAP &ap);
|
||||
WiFiAP get_sta() { return this->selected_ap_; }
|
||||
void add_sta(const WiFiAP &ap);
|
||||
void clear_sta();
|
||||
|
||||
@ -317,6 +318,8 @@ class WiFiComponent : public Component {
|
||||
Trigger<> *get_connect_trigger() const { return this->connect_trigger_; };
|
||||
Trigger<> *get_disconnect_trigger() const { return this->disconnect_trigger_; };
|
||||
|
||||
int32_t get_wifi_channel();
|
||||
|
||||
protected:
|
||||
static std::string format_mac_addr(const uint8_t mac[6]);
|
||||
|
||||
@ -344,7 +347,7 @@ class WiFiComponent : public Component {
|
||||
#endif // USE_WIFI_AP
|
||||
|
||||
bool wifi_disconnect_();
|
||||
int32_t wifi_channel_();
|
||||
|
||||
network::IPAddress wifi_subnet_mask_();
|
||||
network::IPAddress wifi_gateway_ip_();
|
||||
network::IPAddress wifi_dns_ip_(int num);
|
||||
@ -441,6 +444,84 @@ template<typename... Ts> class WiFiDisableAction : public Action<Ts...> {
|
||||
void play(Ts... x) override { global_wifi_component->disable(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class WiFiConfigureAction : public Action<Ts...>, public Component {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(std::string, ssid)
|
||||
TEMPLATABLE_VALUE(std::string, password)
|
||||
TEMPLATABLE_VALUE(bool, save)
|
||||
TEMPLATABLE_VALUE(uint32_t, connection_timeout)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto ssid = this->ssid_.value(x...);
|
||||
auto password = this->password_.value(x...);
|
||||
// Avoid multiple calls
|
||||
if (this->connecting_)
|
||||
return;
|
||||
// If already connected to the same AP, do nothing
|
||||
if (global_wifi_component->wifi_ssid() == ssid) {
|
||||
// Callback to notify the user that the connection was successful
|
||||
this->connect_trigger_->trigger();
|
||||
return;
|
||||
}
|
||||
// Create a new WiFiAP object with the new SSID and password
|
||||
this->new_sta_.set_ssid(ssid);
|
||||
this->new_sta_.set_password(password);
|
||||
// Save the current STA
|
||||
this->old_sta_ = global_wifi_component->get_sta();
|
||||
// Disable WiFi
|
||||
global_wifi_component->disable();
|
||||
// Set the state to connecting
|
||||
this->connecting_ = true;
|
||||
// Store the new STA so once the WiFi is enabled, it will connect to it
|
||||
// This is necessary because the WiFiComponent will raise an error and fallback to the saved STA
|
||||
// if trying to connect to a new STA while already connected to another one
|
||||
if (this->save_.value(x...)) {
|
||||
global_wifi_component->save_wifi_sta(new_sta_.get_ssid(), new_sta_.get_password());
|
||||
} else {
|
||||
global_wifi_component->set_sta(new_sta_);
|
||||
}
|
||||
// Enable WiFi
|
||||
global_wifi_component->enable();
|
||||
// Set timeout for the connection
|
||||
this->set_timeout("wifi-connect-timeout", this->connection_timeout_.value(x...), [this]() {
|
||||
this->connecting_ = false;
|
||||
// If the timeout is reached, stop connecting and revert to the old AP
|
||||
global_wifi_component->disable();
|
||||
global_wifi_component->save_wifi_sta(old_sta_.get_ssid(), old_sta_.get_password());
|
||||
global_wifi_component->enable();
|
||||
// Callback to notify the user that the connection failed
|
||||
this->error_trigger_->trigger();
|
||||
});
|
||||
}
|
||||
|
||||
Trigger<> *get_connect_trigger() const { return this->connect_trigger_; }
|
||||
Trigger<> *get_error_trigger() const { return this->error_trigger_; }
|
||||
|
||||
void loop() override {
|
||||
if (!this->connecting_)
|
||||
return;
|
||||
if (global_wifi_component->is_connected()) {
|
||||
// The WiFi is connected, stop the timeout and reset the connecting flag
|
||||
this->cancel_timeout("wifi-connect-timeout");
|
||||
this->connecting_ = false;
|
||||
if (global_wifi_component->wifi_ssid() == this->new_sta_.get_ssid()) {
|
||||
// Callback to notify the user that the connection was successful
|
||||
this->connect_trigger_->trigger();
|
||||
} else {
|
||||
// Callback to notify the user that the connection failed
|
||||
this->error_trigger_->trigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool connecting_{false};
|
||||
WiFiAP new_sta_;
|
||||
WiFiAP old_sta_;
|
||||
Trigger<> *connect_trigger_{new Trigger<>()};
|
||||
Trigger<> *error_trigger_{new Trigger<>()};
|
||||
};
|
||||
|
||||
} // namespace wifi
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
@ -137,8 +137,16 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
|
||||
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html#_CPPv417wifi_sta_config_t
|
||||
wifi_config_t conf;
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
snprintf(reinterpret_cast<char *>(conf.sta.ssid), sizeof(conf.sta.ssid), "%s", ap.get_ssid().c_str());
|
||||
snprintf(reinterpret_cast<char *>(conf.sta.password), sizeof(conf.sta.password), "%s", ap.get_password().c_str());
|
||||
if (ap.get_ssid().size() > sizeof(conf.sta.ssid)) {
|
||||
ESP_LOGE(TAG, "SSID is too long");
|
||||
return false;
|
||||
}
|
||||
if (ap.get_password().size() > sizeof(conf.sta.password)) {
|
||||
ESP_LOGE(TAG, "password is too long");
|
||||
return false;
|
||||
}
|
||||
memcpy(reinterpret_cast<char *>(conf.sta.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
|
||||
memcpy(reinterpret_cast<char *>(conf.sta.password), ap.get_password().c_str(), ap.get_password().size());
|
||||
|
||||
// The weakest authmode to accept in the fast scan mode
|
||||
if (ap.get_password().empty()) {
|
||||
@ -746,7 +754,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
|
||||
|
||||
wifi_config_t conf;
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
snprintf(reinterpret_cast<char *>(conf.ap.ssid), sizeof(conf.ap.ssid), "%s", ap.get_ssid().c_str());
|
||||
if (ap.get_ssid().size() > sizeof(conf.ap.ssid)) {
|
||||
ESP_LOGE(TAG, "AP SSID is too long");
|
||||
return false;
|
||||
}
|
||||
memcpy(reinterpret_cast<char *>(conf.ap.ssid), ap.get_ssid().c_str(), ap.get_ssid().size());
|
||||
conf.ap.channel = ap.get_channel().value_or(1);
|
||||
conf.ap.ssid_hidden = ap.get_ssid().size();
|
||||
conf.ap.max_connection = 5;
|
||||
@ -757,7 +769,11 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
|
||||
*conf.ap.password = 0;
|
||||
} else {
|
||||
conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
|
||||
snprintf(reinterpret_cast<char *>(conf.ap.password), sizeof(conf.ap.password), "%s", ap.get_password().c_str());
|
||||
if (ap.get_password().size() > sizeof(conf.ap.password)) {
|
||||
ESP_LOGE(TAG, "AP password is too long");
|
||||
return false;
|
||||
}
|
||||
memcpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), ap.get_password().size());
|
||||
}
|
||||
|
||||
// pairwise cipher of SoftAP, group cipher will be derived using this.
|
||||
@ -799,7 +815,7 @@ bssid_t WiFiComponent::wifi_bssid() {
|
||||
}
|
||||
std::string WiFiComponent::wifi_ssid() { return WiFi.SSID().c_str(); }
|
||||
int8_t WiFiComponent::wifi_rssi() { return WiFi.RSSI(); }
|
||||
int32_t WiFiComponent::wifi_channel_() { return WiFi.channel(); }
|
||||
int32_t WiFiComponent::get_wifi_channel() { return WiFi.channel(); }
|
||||
network::IPAddress WiFiComponent::wifi_subnet_mask_() { return network::IPAddress(WiFi.subnetMask()); }
|
||||
network::IPAddress WiFiComponent::wifi_gateway_ip_() { return network::IPAddress(WiFi.gatewayIP()); }
|
||||
network::IPAddress WiFiComponent::wifi_dns_ip_(int num) { return network::IPAddress(WiFi.dnsIP(num)); }
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user