Merge remote-tracking branch 'origin/dev' into nrf52_core

This commit is contained in:
Tomasz Duda 2024-07-12 15:48:14 +02:00
commit e10bd36559
9 changed files with 63 additions and 7 deletions

View file

@ -11,6 +11,7 @@ from esphome.components.esp32.const import (
VARIANT_ESP32S2, VARIANT_ESP32S2,
VARIANT_ESP32S3, VARIANT_ESP32S3,
VARIANT_ESP32C3, VARIANT_ESP32C3,
VARIANT_ESP32C6,
VARIANT_ESP32H2, VARIANT_ESP32H2,
) )
@ -47,6 +48,7 @@ CAN_SPEEDS_ESP32_S2 = {
CAN_SPEEDS_ESP32_S3 = {**CAN_SPEEDS_ESP32_S2} CAN_SPEEDS_ESP32_S3 = {**CAN_SPEEDS_ESP32_S2}
CAN_SPEEDS_ESP32_C3 = {**CAN_SPEEDS_ESP32_S2} CAN_SPEEDS_ESP32_C3 = {**CAN_SPEEDS_ESP32_S2}
CAN_SPEEDS_ESP32_C6 = {**CAN_SPEEDS_ESP32_S2}
CAN_SPEEDS_ESP32_H2 = {**CAN_SPEEDS_ESP32_S2} CAN_SPEEDS_ESP32_H2 = {**CAN_SPEEDS_ESP32_S2}
CAN_SPEEDS = { CAN_SPEEDS = {
@ -54,6 +56,7 @@ CAN_SPEEDS = {
VARIANT_ESP32S2: CAN_SPEEDS_ESP32_S2, VARIANT_ESP32S2: CAN_SPEEDS_ESP32_S2,
VARIANT_ESP32S3: CAN_SPEEDS_ESP32_S3, VARIANT_ESP32S3: CAN_SPEEDS_ESP32_S3,
VARIANT_ESP32C3: CAN_SPEEDS_ESP32_C3, VARIANT_ESP32C3: CAN_SPEEDS_ESP32_C3,
VARIANT_ESP32C6: CAN_SPEEDS_ESP32_C6,
VARIANT_ESP32H2: CAN_SPEEDS_ESP32_H2, VARIANT_ESP32H2: CAN_SPEEDS_ESP32_H2,
} }

View file

@ -16,6 +16,7 @@ MODELS = {
"yan": Model.GREE_YAN, "yan": Model.GREE_YAN,
"yaa": Model.GREE_YAA, "yaa": Model.GREE_YAA,
"yac": Model.GREE_YAC, "yac": Model.GREE_YAC,
"yac1fb9": Model.GREE_YAC1FB9,
} }
CONFIG_SCHEMA = climate_ir.CLIMATE_IR_WITH_RECEIVER_SCHEMA.extend( CONFIG_SCHEMA = climate_ir.CLIMATE_IR_WITH_RECEIVER_SCHEMA.extend(

View file

@ -24,7 +24,7 @@ void GreeClimate::transmit_state() {
remote_state[4] |= (this->horizontal_swing_() << 4); remote_state[4] |= (this->horizontal_swing_() << 4);
} }
if (this->model_ == GREE_YAA || this->model_ == GREE_YAC) { if (this->model_ == GREE_YAA || this->model_ == GREE_YAC || this->model_ == GREE_YAC1FB9) {
remote_state[2] = 0x20; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN remote_state[2] = 0x20; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN
remote_state[3] = 0x50; // bits 4..7 always 0101 remote_state[3] = 0x50; // bits 4..7 always 0101
remote_state[6] = 0x20; // YAA1FB, FAA1FB1, YB1F2 bits 4..7 always 0010 remote_state[6] = 0x20; // YAA1FB, FAA1FB1, YB1F2 bits 4..7 always 0010
@ -53,7 +53,11 @@ void GreeClimate::transmit_state() {
data->set_carrier_frequency(GREE_IR_FREQUENCY); data->set_carrier_frequency(GREE_IR_FREQUENCY);
data->mark(GREE_HEADER_MARK); data->mark(GREE_HEADER_MARK);
if (this->model_ == GREE_YAC1FB9) {
data->space(GREE_YAC1FB9_HEADER_SPACE);
} else {
data->space(GREE_HEADER_SPACE); data->space(GREE_HEADER_SPACE);
}
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (uint8_t mask = 1; mask > 0; mask <<= 1) { // iterate through bit mask for (uint8_t mask = 1; mask > 0; mask <<= 1) { // iterate through bit mask
@ -71,7 +75,11 @@ void GreeClimate::transmit_state() {
data->space(GREE_ZERO_SPACE); data->space(GREE_ZERO_SPACE);
data->mark(GREE_BIT_MARK); data->mark(GREE_BIT_MARK);
if (this->model_ == GREE_YAC1FB9) {
data->space(GREE_YAC1FB9_MESSAGE_SPACE);
} else {
data->space(GREE_MESSAGE_SPACE); data->space(GREE_MESSAGE_SPACE);
}
for (int i = 4; i < 8; i++) { for (int i = 4; i < 8; i++) {
for (uint8_t mask = 1; mask > 0; mask <<= 1) { // iterate through bit mask for (uint8_t mask = 1; mask > 0; mask <<= 1) { // iterate through bit mask

View file

@ -41,6 +41,10 @@ const uint32_t GREE_YAC_HEADER_MARK = 6000;
const uint32_t GREE_YAC_HEADER_SPACE = 3000; const uint32_t GREE_YAC_HEADER_SPACE = 3000;
const uint32_t GREE_YAC_BIT_MARK = 650; const uint32_t GREE_YAC_BIT_MARK = 650;
// Timing specific to YAC1FB9
const uint32_t GREE_YAC1FB9_HEADER_SPACE = 4500;
const uint32_t GREE_YAC1FB9_MESSAGE_SPACE = 19980;
// State Frame size // State Frame size
const uint8_t GREE_STATE_FRAME_SIZE = 8; const uint8_t GREE_STATE_FRAME_SIZE = 8;
@ -67,7 +71,7 @@ const uint8_t GREE_HDIR_MRIGHT = 0x05;
const uint8_t GREE_HDIR_RIGHT = 0x06; const uint8_t GREE_HDIR_RIGHT = 0x06;
// Model codes // Model codes
enum Model { GREE_GENERIC, GREE_YAN, GREE_YAA, GREE_YAC }; enum Model { GREE_GENERIC, GREE_YAN, GREE_YAA, GREE_YAC, GREE_YAC1FB9 };
class GreeClimate : public climate_ir::ClimateIR { class GreeClimate : public climate_ir::ClimateIR {
public: public:

View file

@ -31,7 +31,16 @@ void Jsnsr04tComponent::loop() {
} }
void Jsnsr04tComponent::check_buffer_() { void Jsnsr04tComponent::check_buffer_() {
uint8_t checksum = this->buffer_[0] + this->buffer_[1] + this->buffer_[2]; uint8_t checksum = 0;
switch (this->model_) {
case JSN_SR04T:
checksum = this->buffer_[0] + this->buffer_[1] + this->buffer_[2];
break;
case AJ_SR04M:
checksum = this->buffer_[1] + this->buffer_[2];
break;
}
if (this->buffer_[3] == checksum) { if (this->buffer_[3] == checksum) {
uint16_t distance = encode_uint16(this->buffer_[1], this->buffer_[2]); uint16_t distance = encode_uint16(this->buffer_[1], this->buffer_[2]);
if (distance > 250) { if (distance > 250) {
@ -49,6 +58,14 @@ void Jsnsr04tComponent::check_buffer_() {
void Jsnsr04tComponent::dump_config() { void Jsnsr04tComponent::dump_config() {
LOG_SENSOR("", "JST_SR04T Sensor", this); LOG_SENSOR("", "JST_SR04T Sensor", this);
switch (this->model_) {
case JSN_SR04T:
ESP_LOGCONFIG(TAG, " sensor model: jsn_sr04t");
break;
case AJ_SR04M:
ESP_LOGCONFIG(TAG, " sensor model: aj_sr04m");
break;
}
LOG_UPDATE_INTERVAL(this); LOG_UPDATE_INTERVAL(this);
} }

View file

@ -9,9 +9,14 @@
namespace esphome { namespace esphome {
namespace jsn_sr04t { namespace jsn_sr04t {
enum Model {
JSN_SR04T,
AJ_SR04M,
};
class Jsnsr04tComponent : public sensor::Sensor, public PollingComponent, public uart::UARTDevice { class Jsnsr04tComponent : public sensor::Sensor, public PollingComponent, public uart::UARTDevice {
public: public:
// Nothing really public. void set_model(Model model) { this->model_ = model; }
// ========== INTERNAL METHODS ========== // ========== INTERNAL METHODS ==========
void update() override; void update() override;
@ -20,6 +25,7 @@ class Jsnsr04tComponent : public sensor::Sensor, public PollingComponent, public
protected: protected:
void check_buffer_(); void check_buffer_();
Model model_;
std::vector<uint8_t> buffer_; std::vector<uint8_t> buffer_;
}; };

View file

@ -5,6 +5,7 @@ from esphome.const import (
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_METER, UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL, ICON_ARROW_EXPAND_VERTICAL,
CONF_MODEL,
) )
CODEOWNERS = ["@Mafus1"] CODEOWNERS = ["@Mafus1"]
@ -14,6 +15,11 @@ jsn_sr04t_ns = cg.esphome_ns.namespace("jsn_sr04t")
Jsnsr04tComponent = jsn_sr04t_ns.class_( Jsnsr04tComponent = jsn_sr04t_ns.class_(
"Jsnsr04tComponent", sensor.Sensor, cg.PollingComponent, uart.UARTDevice "Jsnsr04tComponent", sensor.Sensor, cg.PollingComponent, uart.UARTDevice
) )
Model = jsn_sr04t_ns.enum("Model")
MODEL = {
"jsn_sr04t": Model.JSN_SR04T,
"aj_sr04m": Model.AJ_SR04M,
}
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema( sensor.sensor_schema(
@ -25,6 +31,11 @@ CONFIG_SCHEMA = (
) )
.extend(cv.polling_component_schema("60s")) .extend(cv.polling_component_schema("60s"))
.extend(uart.UART_DEVICE_SCHEMA) .extend(uart.UART_DEVICE_SCHEMA)
.extend(
{
cv.Optional(CONF_MODEL, default="jsn_sr04t"): cv.enum(MODEL, upper=False),
}
)
) )
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
@ -42,3 +53,5 @@ async def to_code(config):
var = await sensor.new_sensor(config) var = await sensor.new_sensor(config)
await cg.register_component(var, config) await cg.register_component(var, config)
await uart.register_uart_device(var, config) await uart.register_uart_device(var, config)
cg.add(var.set_model(config[CONF_MODEL]))

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_RESTART, DEVICE_CLASS_RESTART,
ENTITY_CATEGORY_CONFIG, ENTITY_CATEGORY_CONFIG,
ICON_RESTART,
) )
restart_ns = cg.esphome_ns.namespace("restart") restart_ns = cg.esphome_ns.namespace("restart")
@ -12,6 +13,7 @@ RestartButton = restart_ns.class_("RestartButton", button.Button, cg.Component)
CONFIG_SCHEMA = button.button_schema( CONFIG_SCHEMA = button.button_schema(
RestartButton, RestartButton,
icon=ICON_RESTART,
device_class=DEVICE_CLASS_RESTART, device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_CONFIG, entity_category=ENTITY_CATEGORY_CONFIG,
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -684,7 +684,9 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
this->defer([this, text]() { this->defer([this, text]() {
this->tts_start_trigger_->trigger(text); this->tts_start_trigger_->trigger(text);
#ifdef USE_SPEAKER #ifdef USE_SPEAKER
if (this->speaker_ != nullptr) {
this->speaker_->start(); this->speaker_->start();
}
#endif #endif
}); });
break; break;