1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-20 10:43:48 +01:00

Merge remote-tracking branch 'upstream/dev' into min_filter_ring_buffer

This commit is contained in:
J. Nick Koston
2025-10-17 21:04:24 -10:00
154 changed files with 1742 additions and 328 deletions

View File

@@ -58,7 +58,7 @@ jobs:
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8 uses: github/codeql-action/init@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }} build-mode: ${{ matrix.build-mode }}
@@ -86,6 +86,6 @@ jobs:
exit 1 exit 1
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8 uses: github/codeql-action/analyze@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
with: with:
category: "/language:${{matrix.language}}" category: "/language:${{matrix.language}}"

View File

@@ -11,7 +11,7 @@ ci:
repos: repos:
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version. # Ruff version.
rev: v0.14.0 rev: v0.14.1
hooks: hooks:
# Run the linter. # Run the linter.
- id: ruff - id: ruff

View File

@@ -62,6 +62,7 @@ esphome/components/bedjet/fan/* @jhansche
esphome/components/bedjet/sensor/* @javawizard @jhansche esphome/components/bedjet/sensor/* @javawizard @jhansche
esphome/components/beken_spi_led_strip/* @Mat931 esphome/components/beken_spi_led_strip/* @Mat931
esphome/components/bh1750/* @OttoWinter esphome/components/bh1750/* @OttoWinter
esphome/components/bh1900nux/* @B48D81EFCC
esphome/components/binary_sensor/* @esphome/core esphome/components/binary_sensor/* @esphome/core
esphome/components/bk72xx/* @kuba2k2 esphome/components/bk72xx/* @kuba2k2
esphome/components/bl0906/* @athom-tech @jesserockz @tarontop esphome/components/bl0906/* @athom-tech @jesserockz @tarontop

View File

View File

@@ -0,0 +1,54 @@
#include "esphome/core/log.h"
#include "bh1900nux.h"
namespace esphome {
namespace bh1900nux {
static const char *const TAG = "bh1900nux.sensor";
// I2C Registers
static const uint8_t TEMPERATURE_REG = 0x00;
static const uint8_t CONFIG_REG = 0x01; // Not used and supported yet
static const uint8_t TEMPERATURE_LOW_REG = 0x02; // Not used and supported yet
static const uint8_t TEMPERATURE_HIGH_REG = 0x03; // Not used and supported yet
static const uint8_t SOFT_RESET_REG = 0x04;
// I2C Command payloads
static const uint8_t SOFT_RESET_PAYLOAD = 0x01; // Soft Reset value
static const float SENSOR_RESOLUTION = 0.0625f; // Sensor resolution per bit in degrees celsius
void BH1900NUXSensor::setup() {
// Initialize I2C device
i2c::ErrorCode result_code =
this->write_register(SOFT_RESET_REG, &SOFT_RESET_PAYLOAD, 1); // Software Reset to check communication
if (result_code != i2c::ERROR_OK) {
this->mark_failed(ESP_LOG_MSG_COMM_FAIL);
return;
}
}
void BH1900NUXSensor::update() {
uint8_t temperature_raw[2];
if (this->read_register(TEMPERATURE_REG, temperature_raw, 2) != i2c::ERROR_OK) {
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
return;
}
// Combined raw value, unsigned and unaligned 16 bit
// Temperature is represented in just 12 bits, shift needed
int16_t raw_temperature_register_value = encode_uint16(temperature_raw[0], temperature_raw[1]);
raw_temperature_register_value >>= 4;
float temperature_value = raw_temperature_register_value * SENSOR_RESOLUTION; // Apply sensor resolution
this->publish_state(temperature_value);
}
void BH1900NUXSensor::dump_config() {
LOG_SENSOR("", "BH1900NUX", this);
LOG_I2C_DEVICE(this);
LOG_UPDATE_INTERVAL(this);
}
} // namespace bh1900nux
} // namespace esphome

View File

@@ -0,0 +1,18 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace bh1900nux {
class BH1900NUXSensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice {
public:
void setup() override;
void update() override;
void dump_config() override;
};
} // namespace bh1900nux
} // namespace esphome

View File

@@ -0,0 +1,34 @@
import esphome.codegen as cg
from esphome.components import i2c, sensor
import esphome.config_validation as cv
from esphome.const import (
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
)
DEPENDENCIES = ["i2c"]
CODEOWNERS = ["@B48D81EFCC"]
sensor_ns = cg.esphome_ns.namespace("bh1900nux")
BH1900NUXSensor = sensor_ns.class_(
"BH1900NUXSensor", cg.PollingComponent, i2c.I2CDevice
)
CONFIG_SCHEMA = (
sensor.sensor_schema(
BH1900NUXSensor,
accuracy_decimals=1,
unit_of_measurement=UNIT_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
)
.extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x48))
)
async def to_code(config):
var = await sensor.new_sensor(config)
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)

View File

@@ -8,17 +8,30 @@ namespace cap1188 {
static const char *const TAG = "cap1188"; static const char *const TAG = "cap1188";
void CAP1188Component::setup() { void CAP1188Component::setup() {
// Reset device using the reset pin this->disable_loop();
if (this->reset_pin_ != nullptr) {
this->reset_pin_->setup(); // no reset pin
this->reset_pin_->digital_write(false); if (this->reset_pin_ == nullptr) {
delay(100); // NOLINT this->finish_setup_();
this->reset_pin_->digital_write(true); return;
delay(100); // NOLINT
this->reset_pin_->digital_write(false);
delay(100); // NOLINT
} }
// reset pin configured so reset before finishing setup
this->reset_pin_->setup();
this->reset_pin_->digital_write(false);
// delay after reset pin write
this->set_timeout(100, [this]() {
this->reset_pin_->digital_write(true);
// delay after reset pin write
this->set_timeout(100, [this]() {
this->reset_pin_->digital_write(false);
// delay after reset pin write
this->set_timeout(100, [this]() { this->finish_setup_(); });
});
});
}
void CAP1188Component::finish_setup_() {
// Check if CAP1188 is actually connected // Check if CAP1188 is actually connected
this->read_byte(CAP1188_PRODUCT_ID, &this->cap1188_product_id_); this->read_byte(CAP1188_PRODUCT_ID, &this->cap1188_product_id_);
this->read_byte(CAP1188_MANUFACTURE_ID, &this->cap1188_manufacture_id_); this->read_byte(CAP1188_MANUFACTURE_ID, &this->cap1188_manufacture_id_);
@@ -44,6 +57,9 @@ void CAP1188Component::setup() {
// Speed up a bit // Speed up a bit
this->write_byte(CAP1188_STAND_BY_CONFIGURATION, 0x30); this->write_byte(CAP1188_STAND_BY_CONFIGURATION, 0x30);
// Setup successful, so enable loop
this->enable_loop();
} }
void CAP1188Component::dump_config() { void CAP1188Component::dump_config() {

View File

@@ -49,6 +49,8 @@ class CAP1188Component : public Component, public i2c::I2CDevice {
void loop() override; void loop() override;
protected: protected:
void finish_setup_();
std::vector<CAP1188Channel *> channels_{}; std::vector<CAP1188Channel *> channels_{};
uint8_t touch_threshold_{0x20}; uint8_t touch_threshold_{0x20};
uint8_t allow_multiple_touches_{0x80}; uint8_t allow_multiple_touches_{0x80};

View File

@@ -11,8 +11,6 @@
#include <esp_chip_info.h> #include <esp_chip_info.h>
#include <esp_partition.h> #include <esp_partition.h>
#include <map>
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
#include <Esp.h> #include <Esp.h>
#endif #endif
@@ -125,7 +123,12 @@ void DebugComponent::log_partition_info_() {
uint32_t DebugComponent::get_free_heap_() { return heap_caps_get_free_size(MALLOC_CAP_INTERNAL); } uint32_t DebugComponent::get_free_heap_() { return heap_caps_get_free_size(MALLOC_CAP_INTERNAL); }
static const std::map<int, const char *> CHIP_FEATURES = { struct ChipFeature {
int bit;
const char *name;
};
static constexpr ChipFeature CHIP_FEATURES[] = {
{CHIP_FEATURE_BLE, "BLE"}, {CHIP_FEATURE_BLE, "BLE"},
{CHIP_FEATURE_BT, "BT"}, {CHIP_FEATURE_BT, "BT"},
{CHIP_FEATURE_EMB_FLASH, "EMB Flash"}, {CHIP_FEATURE_EMB_FLASH, "EMB Flash"},
@@ -170,11 +173,13 @@ void DebugComponent::get_device_info_(std::string &device_info) {
esp_chip_info(&info); esp_chip_info(&info);
const char *model = ESPHOME_VARIANT; const char *model = ESPHOME_VARIANT;
std::string features; std::string features;
for (auto feature : CHIP_FEATURES) {
if (info.features & feature.first) { // Check each known feature bit
features += feature.second; for (const auto &feature : CHIP_FEATURES) {
if (info.features & feature.bit) {
features += feature.name;
features += ", "; features += ", ";
info.features &= ~feature.first; info.features &= ~feature.bit;
} }
} }
if (info.features != 0) if (info.features != 0)

View File

@@ -25,10 +25,37 @@ static void show_reset_reason(std::string &reset_reason, bool set, const char *r
reset_reason += reason; reset_reason += reason;
} }
inline uint32_t read_mem_u32(uintptr_t addr) { static inline uint32_t read_mem_u32(uintptr_t addr) {
return *reinterpret_cast<volatile uint32_t *>(addr); // NOLINT(performance-no-int-to-ptr) return *reinterpret_cast<volatile uint32_t *>(addr); // NOLINT(performance-no-int-to-ptr)
} }
static inline uint8_t read_mem_u8(uintptr_t addr) {
return *reinterpret_cast<volatile uint8_t *>(addr); // NOLINT(performance-no-int-to-ptr)
}
// defines from https://github.com/adafruit/Adafruit_nRF52_Bootloader which prints those information
constexpr uint32_t SD_MAGIC_NUMBER = 0x51B1E5DB;
constexpr uintptr_t MBR_SIZE = 0x1000;
constexpr uintptr_t SOFTDEVICE_INFO_STRUCT_OFFSET = 0x2000;
constexpr uintptr_t SD_ID_OFFSET = SOFTDEVICE_INFO_STRUCT_OFFSET + 0x10;
constexpr uintptr_t SD_VERSION_OFFSET = SOFTDEVICE_INFO_STRUCT_OFFSET + 0x14;
static inline bool is_sd_present() {
return read_mem_u32(SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE + 4) == SD_MAGIC_NUMBER;
}
static inline uint32_t sd_id_get() {
if (read_mem_u8(MBR_SIZE + SOFTDEVICE_INFO_STRUCT_OFFSET) > (SD_ID_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) {
return read_mem_u32(MBR_SIZE + SD_ID_OFFSET);
}
return 0;
}
static inline uint32_t sd_version_get() {
if (read_mem_u8(MBR_SIZE + SOFTDEVICE_INFO_STRUCT_OFFSET) > (SD_VERSION_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) {
return read_mem_u32(MBR_SIZE + SD_VERSION_OFFSET);
}
return 0;
}
std::string DebugComponent::get_reset_reason_() { std::string DebugComponent::get_reset_reason_() {
uint32_t cause; uint32_t cause;
auto ret = hwinfo_get_reset_cause(&cause); auto ret = hwinfo_get_reset_cause(&cause);
@@ -271,6 +298,29 @@ void DebugComponent::get_device_info_(std::string &device_info) {
NRF_UICR->NRFFW[0]); NRF_UICR->NRFFW[0]);
ESP_LOGD(TAG, "MBR param page addr 0x%08x, UICR param page addr 0x%08x", read_mem_u32(MBR_PARAM_PAGE_ADDR), ESP_LOGD(TAG, "MBR param page addr 0x%08x, UICR param page addr 0x%08x", read_mem_u32(MBR_PARAM_PAGE_ADDR),
NRF_UICR->NRFFW[1]); NRF_UICR->NRFFW[1]);
if (is_sd_present()) {
uint32_t const sd_id = sd_id_get();
uint32_t const sd_version = sd_version_get();
uint32_t ver[3];
ver[0] = sd_version / 1000000;
ver[1] = (sd_version - ver[0] * 1000000) / 1000;
ver[2] = (sd_version - ver[0] * 1000000 - ver[1] * 1000);
ESP_LOGD(TAG, "SoftDevice: S%u %u.%u.%u", sd_id, ver[0], ver[1], ver[2]);
#ifdef USE_SOFTDEVICE_ID
#ifdef USE_SOFTDEVICE_VERSION
if (USE_SOFTDEVICE_ID != sd_id || USE_SOFTDEVICE_VERSION != ver[0]) {
ESP_LOGE(TAG, "Built for SoftDevice S%u %u.x.y. It may crash due to mismatch of bootloader version.",
USE_SOFTDEVICE_ID, USE_SOFTDEVICE_VERSION);
}
#else
if (USE_SOFTDEVICE_ID != sd_id) {
ESP_LOGE(TAG, "Built for SoftDevice S%u. It may crash due to mismatch of bootloader version.", USE_SOFTDEVICE_ID);
}
#endif
#endif
}
#endif #endif
} }

View File

@@ -828,6 +828,9 @@ async def to_code(config):
# Disable dynamic log level control to save memory # Disable dynamic log level control to save memory
add_idf_sdkconfig_option("CONFIG_LOG_DYNAMIC_LEVEL_CONTROL", False) add_idf_sdkconfig_option("CONFIG_LOG_DYNAMIC_LEVEL_CONTROL", False)
# Reduce PHY TX power in the event of a brownout
add_idf_sdkconfig_option("CONFIG_ESP_PHY_REDUCE_TX_POWER", True)
# Set default CPU frequency # Set default CPU frequency
add_idf_sdkconfig_option( add_idf_sdkconfig_option(
f"CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_{config[CONF_CPU_FREQUENCY][:-3]}", True f"CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_{config[CONF_CPU_FREQUENCY][:-3]}", True

View File

@@ -35,6 +35,7 @@ CONF_CHARGE = "charge"
CONF_CHARGE_COULOMBS = "charge_coulombs" CONF_CHARGE_COULOMBS = "charge_coulombs"
CONF_ENERGY_JOULES = "energy_joules" CONF_ENERGY_JOULES = "energy_joules"
CONF_TEMPERATURE_COEFFICIENT = "temperature_coefficient" CONF_TEMPERATURE_COEFFICIENT = "temperature_coefficient"
CONF_RESET_ON_BOOT = "reset_on_boot"
UNIT_AMPERE_HOURS = "Ah" UNIT_AMPERE_HOURS = "Ah"
UNIT_COULOMB = "C" UNIT_COULOMB = "C"
UNIT_JOULE = "J" UNIT_JOULE = "J"
@@ -113,6 +114,7 @@ INA2XX_SCHEMA = cv.Schema(
cv.Optional(CONF_TEMPERATURE_COEFFICIENT, default=0): cv.int_range( cv.Optional(CONF_TEMPERATURE_COEFFICIENT, default=0): cv.int_range(
min=0, max=16383 min=0, max=16383
), ),
cv.Optional(CONF_RESET_ON_BOOT, default=True): cv.boolean,
cv.Optional(CONF_SHUNT_VOLTAGE): cv.maybe_simple_value( cv.Optional(CONF_SHUNT_VOLTAGE): cv.maybe_simple_value(
sensor.sensor_schema( sensor.sensor_schema(
unit_of_measurement=UNIT_MILLIVOLT, unit_of_measurement=UNIT_MILLIVOLT,
@@ -206,6 +208,7 @@ async def setup_ina2xx(var, config):
cg.add(var.set_adc_range(config[CONF_ADC_RANGE])) cg.add(var.set_adc_range(config[CONF_ADC_RANGE]))
cg.add(var.set_adc_avg_samples(config[CONF_ADC_AVERAGING])) cg.add(var.set_adc_avg_samples(config[CONF_ADC_AVERAGING]))
cg.add(var.set_shunt_tempco(config[CONF_TEMPERATURE_COEFFICIENT])) cg.add(var.set_shunt_tempco(config[CONF_TEMPERATURE_COEFFICIENT]))
cg.add(var.set_reset_on_boot(config[CONF_RESET_ON_BOOT]))
adc_time_config = config[CONF_ADC_TIME] adc_time_config = config[CONF_ADC_TIME]
if isinstance(adc_time_config, dict): if isinstance(adc_time_config, dict):

View File

@@ -257,7 +257,12 @@ bool INA2XX::reset_energy_counters() {
bool INA2XX::reset_config_() { bool INA2XX::reset_config_() {
ESP_LOGV(TAG, "Reset"); ESP_LOGV(TAG, "Reset");
ConfigurationRegister cfg{0}; ConfigurationRegister cfg{0};
if (!this->reset_on_boot_) {
ESP_LOGI(TAG, "Skipping on-boot device reset");
cfg.RST = false;
} else {
cfg.RST = true; cfg.RST = true;
}
return this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16); return this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
} }

View File

@@ -127,6 +127,7 @@ class INA2XX : public PollingComponent {
void set_adc_time_die_temperature(AdcTime time) { this->adc_time_die_temperature_ = time; } void set_adc_time_die_temperature(AdcTime time) { this->adc_time_die_temperature_ = time; }
void set_adc_avg_samples(AdcAvgSamples samples) { this->adc_avg_samples_ = samples; } void set_adc_avg_samples(AdcAvgSamples samples) { this->adc_avg_samples_ = samples; }
void set_shunt_tempco(uint16_t coeff) { this->shunt_tempco_ppm_c_ = coeff; } void set_shunt_tempco(uint16_t coeff) { this->shunt_tempco_ppm_c_ = coeff; }
void set_reset_on_boot(bool reset) { this->reset_on_boot_ = reset; }
void set_shunt_voltage_sensor(sensor::Sensor *sensor) { this->shunt_voltage_sensor_ = sensor; } void set_shunt_voltage_sensor(sensor::Sensor *sensor) { this->shunt_voltage_sensor_ = sensor; }
void set_bus_voltage_sensor(sensor::Sensor *sensor) { this->bus_voltage_sensor_ = sensor; } void set_bus_voltage_sensor(sensor::Sensor *sensor) { this->bus_voltage_sensor_ = sensor; }
@@ -172,6 +173,7 @@ class INA2XX : public PollingComponent {
AdcTime adc_time_die_temperature_{AdcTime::ADC_TIME_4120US}; AdcTime adc_time_die_temperature_{AdcTime::ADC_TIME_4120US};
AdcAvgSamples adc_avg_samples_{AdcAvgSamples::ADC_AVG_SAMPLES_128}; AdcAvgSamples adc_avg_samples_{AdcAvgSamples::ADC_AVG_SAMPLES_128};
uint16_t shunt_tempco_ppm_c_{0}; uint16_t shunt_tempco_ppm_c_{0};
bool reset_on_boot_{true};
// //
// Calculated coefficients // Calculated coefficients

View File

@@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
import logging
from pathlib import Path from pathlib import Path
from esphome import pins from esphome import pins
@@ -48,6 +49,7 @@ from .gpio import nrf52_pin_to_code # noqa
CODEOWNERS = ["@tomaszduda23"] CODEOWNERS = ["@tomaszduda23"]
AUTO_LOAD = ["zephyr"] AUTO_LOAD = ["zephyr"]
IS_TARGET_PLATFORM = True IS_TARGET_PLATFORM = True
_LOGGER = logging.getLogger(__name__)
def set_core_data(config: ConfigType) -> ConfigType: def set_core_data(config: ConfigType) -> ConfigType:
@@ -127,6 +129,10 @@ def _validate_mcumgr(config):
def _final_validate(config): def _final_validate(config):
if CONF_DFU in config: if CONF_DFU in config:
_validate_mcumgr(config) _validate_mcumgr(config)
if config[KEY_BOOTLOADER] == BOOTLOADER_ADAFRUIT:
_LOGGER.warning(
"Selected generic Adafruit bootloader. The board might crash. Consider settings `bootloader:`"
)
FINAL_VALIDATE_SCHEMA = _final_validate FINAL_VALIDATE_SCHEMA = _final_validate
@@ -157,6 +163,13 @@ async def to_code(config: ConfigType) -> None:
if config[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT: if config[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT:
cg.add_define("USE_BOOTLOADER_MCUBOOT") cg.add_define("USE_BOOTLOADER_MCUBOOT")
else: else:
if "_sd" in config[KEY_BOOTLOADER]:
bootloader = config[KEY_BOOTLOADER].split("_")
sd_id = bootloader[2][2:]
cg.add_define("USE_SOFTDEVICE_ID", int(sd_id))
if (len(bootloader)) > 3:
sd_version = bootloader[3][1:]
cg.add_define("USE_SOFTDEVICE_VERSION", int(sd_version))
# make sure that firmware.zip is created # make sure that firmware.zip is created
# for Adafruit_nRF52_Bootloader # for Adafruit_nRF52_Bootloader
cg.add_platformio_option("board_upload.protocol", "nrfutil") cg.add_platformio_option("board_upload.protocol", "nrfutil")

View File

@@ -11,10 +11,18 @@ from .const import (
BOARDS_ZEPHYR = { BOARDS_ZEPHYR = {
"adafruit_itsybitsy_nrf52840": { "adafruit_itsybitsy_nrf52840": {
KEY_BOOTLOADER: [ KEY_BOOTLOADER: [
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6,
BOOTLOADER_ADAFRUIT,
BOOTLOADER_ADAFRUIT_NRF52_SD132,
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
]
},
"xiao_ble": {
KEY_BOOTLOADER: [
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
BOOTLOADER_ADAFRUIT, BOOTLOADER_ADAFRUIT,
BOOTLOADER_ADAFRUIT_NRF52_SD132, BOOTLOADER_ADAFRUIT_NRF52_SD132,
BOOTLOADER_ADAFRUIT_NRF52_SD140_V6, BOOTLOADER_ADAFRUIT_NRF52_SD140_V6,
BOOTLOADER_ADAFRUIT_NRF52_SD140_V7,
] ]
}, },
} }

View File

@@ -66,6 +66,7 @@ from esphome.const import (
DEVICE_CLASS_SPEED, DEVICE_CLASS_SPEED,
DEVICE_CLASS_SULPHUR_DIOXIDE, DEVICE_CLASS_SULPHUR_DIOXIDE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE_DELTA,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
@@ -130,6 +131,7 @@ DEVICE_CLASSES = [
DEVICE_CLASS_SPEED, DEVICE_CLASS_SPEED,
DEVICE_CLASS_SULPHUR_DIOXIDE, DEVICE_CLASS_SULPHUR_DIOXIDE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE_DELTA,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,

View File

@@ -1056,6 +1056,52 @@ async def sony_action(var, config, args):
cg.add(var.set_nbits(template_)) cg.add(var.set_nbits(template_))
# Symphony
SymphonyData, SymphonyBinarySensor, SymphonyTrigger, SymphonyAction, SymphonyDumper = (
declare_protocol("Symphony")
)
SYMPHONY_SCHEMA = cv.Schema(
{
cv.Required(CONF_DATA): cv.hex_uint32_t,
cv.Required(CONF_NBITS): cv.int_range(min=1, max=32),
cv.Optional(CONF_COMMAND_REPEATS, default=2): cv.uint8_t,
}
)
@register_binary_sensor("symphony", SymphonyBinarySensor, SYMPHONY_SCHEMA)
def symphony_binary_sensor(var, config):
cg.add(
var.set_data(
cg.StructInitializer(
SymphonyData,
("data", config[CONF_DATA]),
("nbits", config[CONF_NBITS]),
)
)
)
@register_trigger("symphony", SymphonyTrigger, SymphonyData)
def symphony_trigger(var, config):
pass
@register_dumper("symphony", SymphonyDumper)
def symphony_dumper(var, config):
pass
@register_action("symphony", SymphonyAction, SYMPHONY_SCHEMA)
async def symphony_action(var, config, args):
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32)
cg.add(var.set_data(template_))
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint32)
cg.add(var.set_nbits(template_))
template_ = await cg.templatable(config[CONF_COMMAND_REPEATS], args, cg.uint8)
cg.add(var.set_repeats(template_))
# Raw # Raw
def validate_raw_alternating(value): def validate_raw_alternating(value):
assert isinstance(value, list) assert isinstance(value, list)

View File

@@ -0,0 +1,120 @@
#include "symphony_protocol.h"
#include "esphome/core/log.h"
namespace esphome {
namespace remote_base {
static const char *const TAG = "remote.symphony";
// Reference implementation and timing details:
// IRremoteESP8266 ir_Symphony.cpp
// https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Symphony.cpp
// The implementation below mirrors the constant bit-time mapping and
// footer-gap handling used there.
// Symphony protocol timing specifications (tuned to handset captures)
static const uint32_t BIT_ZERO_HIGH_US = 460; // short
static const uint32_t BIT_ZERO_LOW_US = 1260; // long
static const uint32_t BIT_ONE_HIGH_US = 1260; // long
static const uint32_t BIT_ONE_LOW_US = 460; // short
static const uint32_t CARRIER_FREQUENCY = 38000;
// IRremoteESP8266 reference: kSymphonyFooterGap = 4 * (mark + space)
static const uint32_t FOOTER_GAP_US = 4 * (BIT_ZERO_HIGH_US + BIT_ZERO_LOW_US);
// Typical inter-frame gap (~34.8 ms observed)
static const uint32_t INTER_FRAME_GAP_US = 34760;
void SymphonyProtocol::encode(RemoteTransmitData *dst, const SymphonyData &data) {
dst->set_carrier_frequency(CARRIER_FREQUENCY);
ESP_LOGD(TAG, "Sending Symphony: data=0x%0*X nbits=%u repeats=%u", (data.nbits + 3) / 4, (uint32_t) data.data,
data.nbits, data.repeats);
// Each bit produces a mark+space (2 entries). We fold the inter-frame/footer gap
// into the last bit's space of each frame to avoid over-length gaps.
dst->reserve(data.nbits * 2u * data.repeats);
for (uint8_t repeats = 0; repeats < data.repeats; repeats++) {
// Data bits (MSB first)
for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) {
const bool is_last_bit = (mask == 1);
const bool is_last_frame = (repeats == (data.repeats - 1));
if (is_last_bit) {
// Emit last bit's mark; replace its space with the proper gap
if (data.data & mask) {
dst->mark(BIT_ONE_HIGH_US);
} else {
dst->mark(BIT_ZERO_HIGH_US);
}
dst->space(is_last_frame ? FOOTER_GAP_US : INTER_FRAME_GAP_US);
} else {
if (data.data & mask) {
dst->item(BIT_ONE_HIGH_US, BIT_ONE_LOW_US);
} else {
dst->item(BIT_ZERO_HIGH_US, BIT_ZERO_LOW_US);
}
}
}
}
}
optional<SymphonyData> SymphonyProtocol::decode(RemoteReceiveData src) {
auto is_valid_len = [](uint8_t nbits) -> bool { return nbits == 8 || nbits == 12 || nbits == 16; };
RemoteReceiveData s = src; // copy
SymphonyData out{0, 0, 1};
for (; out.nbits < 32; out.nbits++) {
if (s.expect_mark(BIT_ONE_HIGH_US)) {
if (!s.expect_space(BIT_ONE_LOW_US)) {
// Allow footer gap immediately after the last mark
if (s.peek_space_at_least(FOOTER_GAP_US)) {
uint8_t bits_with_this = out.nbits + 1;
if (is_valid_len(bits_with_this)) {
out.data = (out.data << 1UL) | 1UL;
out.nbits = bits_with_this;
return out;
}
}
return {};
}
// Successfully consumed a '1' bit (mark + space)
out.data = (out.data << 1UL) | 1UL;
continue;
} else if (s.expect_mark(BIT_ZERO_HIGH_US)) {
if (!s.expect_space(BIT_ZERO_LOW_US)) {
// Allow footer gap immediately after the last mark
if (s.peek_space_at_least(FOOTER_GAP_US)) {
uint8_t bits_with_this = out.nbits + 1;
if (is_valid_len(bits_with_this)) {
out.data = (out.data << 1UL) | 0UL;
out.nbits = bits_with_this;
return out;
}
}
return {};
}
// Successfully consumed a '0' bit (mark + space)
out.data = (out.data << 1UL) | 0UL;
continue;
} else {
// Completed a valid-length frame followed by a footer gap
if (is_valid_len(out.nbits) && s.peek_space_at_least(FOOTER_GAP_US)) {
return out;
}
return {};
}
}
if (is_valid_len(out.nbits) && s.peek_space_at_least(FOOTER_GAP_US)) {
return out;
}
return {};
}
void SymphonyProtocol::dump(const SymphonyData &data) {
const int32_t hex_width = (data.nbits + 3) / 4; // pad to nibble width
ESP_LOGI(TAG, "Received Symphony: data=0x%0*X, nbits=%d", hex_width, (uint32_t) data.data, data.nbits);
}
} // namespace remote_base
} // namespace esphome

View File

@@ -0,0 +1,44 @@
#pragma once
#include "esphome/core/component.h"
#include "remote_base.h"
#include <cinttypes>
namespace esphome {
namespace remote_base {
struct SymphonyData {
uint32_t data;
uint8_t nbits;
uint8_t repeats{1};
bool operator==(const SymphonyData &rhs) const { return data == rhs.data && nbits == rhs.nbits; }
};
class SymphonyProtocol : public RemoteProtocol<SymphonyData> {
public:
void encode(RemoteTransmitData *dst, const SymphonyData &data) override;
optional<SymphonyData> decode(RemoteReceiveData src) override;
void dump(const SymphonyData &data) override;
};
DECLARE_REMOTE_PROTOCOL(Symphony)
template<typename... Ts> class SymphonyAction : public RemoteTransmitterActionBase<Ts...> {
public:
TEMPLATABLE_VALUE(uint32_t, data)
TEMPLATABLE_VALUE(uint8_t, nbits)
TEMPLATABLE_VALUE(uint8_t, repeats)
void encode(RemoteTransmitData *dst, Ts... x) override {
SymphonyData data{};
data.data = this->data_.value(x...);
data.nbits = this->nbits_.value(x...);
data.repeats = this->repeats_.value(x...);
SymphonyProtocol().encode(dst, data);
}
};
} // namespace remote_base
} // namespace esphome

View File

@@ -89,6 +89,7 @@ from esphome.const import (
DEVICE_CLASS_SPEED, DEVICE_CLASS_SPEED,
DEVICE_CLASS_SULPHUR_DIOXIDE, DEVICE_CLASS_SULPHUR_DIOXIDE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE_DELTA,
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,
@@ -157,6 +158,7 @@ DEVICE_CLASSES = [
DEVICE_CLASS_SPEED, DEVICE_CLASS_SPEED,
DEVICE_CLASS_SULPHUR_DIOXIDE, DEVICE_CLASS_SULPHUR_DIOXIDE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE_DELTA,
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,

View File

@@ -14,6 +14,7 @@ MODELS = {
"GENERIC": Model.MODEL_GENERIC, "GENERIC": Model.MODEL_GENERIC,
"RAC-PT1411HWRU-C": Model.MODEL_RAC_PT1411HWRU_C, "RAC-PT1411HWRU-C": Model.MODEL_RAC_PT1411HWRU_C,
"RAC-PT1411HWRU-F": Model.MODEL_RAC_PT1411HWRU_F, "RAC-PT1411HWRU-F": Model.MODEL_RAC_PT1411HWRU_F,
"RAS-2819T": Model.MODEL_RAS_2819T,
} }
CONFIG_SCHEMA = climate_ir.climate_ir_with_receiver_schema(ToshibaClimate).extend( CONFIG_SCHEMA = climate_ir.climate_ir_with_receiver_schema(ToshibaClimate).extend(

View File

@@ -1,4 +1,5 @@
#include "toshiba.h" #include "toshiba.h"
#include "esphome/components/remote_base/toshiba_ac_protocol.h"
#include <vector> #include <vector>
@@ -97,6 +98,282 @@ const std::vector<uint8_t> RAC_PT1411HWRU_TEMPERATURE_F{0x10, 0x30, 0x00, 0x20,
0x22, 0x06, 0x26, 0x07, 0x05, 0x25, 0x04, 0x24, 0x0C, 0x22, 0x06, 0x26, 0x07, 0x05, 0x25, 0x04, 0x24, 0x0C,
0x2C, 0x0D, 0x2D, 0x09, 0x08, 0x28, 0x0A, 0x2A, 0x0B}; 0x2C, 0x0D, 0x2D, 0x09, 0x08, 0x28, 0x0A, 0x2A, 0x0B};
// RAS-2819T protocol constants
const uint16_t RAS_2819T_HEADER1 = 0xC23D;
const uint8_t RAS_2819T_HEADER2 = 0xD5;
const uint8_t RAS_2819T_MESSAGE_LENGTH = 6;
// RAS-2819T fan speed codes for rc_code_1 (bytes 2-3)
const uint16_t RAS_2819T_FAN_AUTO = 0xBF40;
const uint16_t RAS_2819T_FAN_QUIET = 0xFF00;
const uint16_t RAS_2819T_FAN_LOW = 0x9F60;
const uint16_t RAS_2819T_FAN_MEDIUM = 0x5FA0;
const uint16_t RAS_2819T_FAN_HIGH = 0x3FC0;
// RAS-2819T fan speed codes for rc_code_2 (byte 1)
const uint8_t RAS_2819T_FAN2_AUTO = 0x66;
const uint8_t RAS_2819T_FAN2_QUIET = 0x01;
const uint8_t RAS_2819T_FAN2_LOW = 0x28;
const uint8_t RAS_2819T_FAN2_MEDIUM = 0x3C;
const uint8_t RAS_2819T_FAN2_HIGH = 0x50;
// RAS-2819T second packet suffix bytes for rc_code_2 (bytes 3-5)
// These are fixed patterns, not actual checksums
struct Ras2819tPacketSuffix {
uint8_t byte3;
uint8_t byte4;
uint8_t byte5;
};
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_AUTO{0x00, 0x02, 0x3D};
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_QUIET{0x00, 0x02, 0xD8};
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_LOW{0x00, 0x02, 0xFF};
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_MEDIUM{0x00, 0x02, 0x13};
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_HIGH{0x00, 0x02, 0x27};
// RAS-2819T swing toggle command
const uint64_t RAS_2819T_SWING_TOGGLE = 0xC23D6B94E01F;
// RAS-2819T single-packet commands
const uint64_t RAS_2819T_POWER_OFF_COMMAND = 0xC23D7B84E01F;
// RAS-2819T known valid command patterns for validation
const std::array<uint64_t, 2> RAS_2819T_VALID_SINGLE_COMMANDS = {
RAS_2819T_POWER_OFF_COMMAND, // Power off
RAS_2819T_SWING_TOGGLE, // Swing toggle
};
const uint16_t RAS_2819T_VALID_HEADER1 = 0xC23D;
const uint8_t RAS_2819T_VALID_HEADER2 = 0xD5;
const uint8_t RAS_2819T_DRY_BYTE2 = 0x1F;
const uint8_t RAS_2819T_DRY_BYTE3 = 0xE0;
const uint8_t RAS_2819T_DRY_TEMP_OFFSET = 0x24;
const uint8_t RAS_2819T_AUTO_BYTE2 = 0x1F;
const uint8_t RAS_2819T_AUTO_BYTE3 = 0xE0;
const uint8_t RAS_2819T_AUTO_TEMP_OFFSET = 0x08;
const uint8_t RAS_2819T_FAN_ONLY_TEMP = 0xE4;
const uint8_t RAS_2819T_FAN_ONLY_TEMP_INV = 0x1B;
const uint8_t RAS_2819T_HEAT_TEMP_OFFSET = 0x0C;
// RAS-2819T second packet fixed values
const uint8_t RAS_2819T_AUTO_DRY_FAN_BYTE = 0x65;
const uint8_t RAS_2819T_AUTO_DRY_SUFFIX = 0x3A;
const uint8_t RAS_2819T_HEAT_SUFFIX = 0x3B;
// RAS-2819T temperature codes for 18-30°C
static const uint8_t RAS_2819T_TEMP_CODES[] = {
0x10, // 18°C
0x30, // 19°C
0x20, // 20°C
0x60, // 21°C
0x70, // 22°C
0x50, // 23°C
0x40, // 24°C
0xC0, // 25°C
0xD0, // 26°C
0x90, // 27°C
0x80, // 28°C
0xA0, // 29°C
0xB0 // 30°C
};
// Helper functions for RAS-2819T protocol
//
// ===== RAS-2819T PROTOCOL DOCUMENTATION =====
//
// The RAS-2819T uses a two-packet IR protocol with some exceptions for simple commands.
//
// PACKET STRUCTURE:
// All packets are 6 bytes (48 bits) transmitted with standard Toshiba timing.
//
// TWO-PACKET COMMANDS (Mode/Temperature/Fan changes):
//
// First Packet (rc_code_1): [C2 3D] [FAN_HI FAN_LO] [TEMP] [~TEMP]
// Byte 0-1: Header (always 0xC23D)
// Byte 2-3: Fan speed encoding (varies by mode, see fan tables below)
// Byte 4: Temperature + mode encoding
// Byte 5: Bitwise complement of temperature byte
//
// Second Packet (rc_code_2): [D5] [FAN2] [00] [SUF1] [SUF2] [SUF3]
// Byte 0: Header (always 0xD5)
// Byte 1: Fan speed secondary encoding
// Byte 2: Always 0x00
// Byte 3-5: Fixed suffix pattern (depends on fan speed and mode)
//
// TEMPERATURE ENCODING:
// Base temp codes: 18°C=0x10, 19°C=0x30, 20°C=0x20, 21°C=0x60, 22°C=0x70,
// 23°C=0x50, 24°C=0x40, 25°C=0xC0, 26°C=0xD0, 27°C=0x90,
// 28°C=0x80, 29°C=0xA0, 30°C=0xB0
// Mode offsets added to base temp:
// COOL: No offset
// HEAT: +0x0C (e.g., 24°C heat = 0x40 | 0x0C = 0x4C)
// AUTO: +0x08 (e.g., 24°C auto = 0x40 | 0x08 = 0x48)
// DRY: +0x24 (e.g., 24°C dry = 0x40 | 0x24 = 0x64)
//
// FAN SPEED ENCODING (First packet bytes 2-3):
// AUTO: 0xBF40, QUIET: 0xFF00, LOW: 0x9F60, MEDIUM: 0x5FA0, HIGH: 0x3FC0
// Special cases: AUTO/DRY modes use 0x1FE0 instead
//
// SINGLE-PACKET COMMANDS:
// Power Off: 0xC23D7B84E01F (6 bytes, no second packet)
// Swing Toggle: 0xC23D6B94E01F (6 bytes, no second packet)
//
// MODE DETECTION (from first packet):
// - Check bytes 2-3: if 0x7B84 → OFF mode
// - Check bytes 2-3: if 0x1FE0 → AUTO/DRY/low-temp-COOL (distinguish by temp code)
// - Otherwise: COOL/HEAT/FAN_ONLY (distinguish by temp code and byte 5)
/**
* Get fan speed encoding for RAS-2819T first packet (rc_code_1, bytes 2-3)
*/
static uint16_t get_ras_2819t_fan_code(climate::ClimateFanMode fan_mode) {
switch (fan_mode) {
case climate::CLIMATE_FAN_QUIET:
return RAS_2819T_FAN_QUIET;
case climate::CLIMATE_FAN_LOW:
return RAS_2819T_FAN_LOW;
case climate::CLIMATE_FAN_MEDIUM:
return RAS_2819T_FAN_MEDIUM;
case climate::CLIMATE_FAN_HIGH:
return RAS_2819T_FAN_HIGH;
case climate::CLIMATE_FAN_AUTO:
default:
return RAS_2819T_FAN_AUTO;
}
}
/**
* Get fan speed encoding for RAS-2819T rc_code_2 packet (second packet)
*/
struct Ras2819tSecondPacketCodes {
uint8_t fan_byte;
Ras2819tPacketSuffix suffix;
};
static Ras2819tSecondPacketCodes get_ras_2819t_second_packet_codes(climate::ClimateFanMode fan_mode) {
switch (fan_mode) {
case climate::CLIMATE_FAN_QUIET:
return {RAS_2819T_FAN2_QUIET, RAS_2819T_SUFFIX_QUIET};
case climate::CLIMATE_FAN_LOW:
return {RAS_2819T_FAN2_LOW, RAS_2819T_SUFFIX_LOW};
case climate::CLIMATE_FAN_MEDIUM:
return {RAS_2819T_FAN2_MEDIUM, RAS_2819T_SUFFIX_MEDIUM};
case climate::CLIMATE_FAN_HIGH:
return {RAS_2819T_FAN2_HIGH, RAS_2819T_SUFFIX_HIGH};
case climate::CLIMATE_FAN_AUTO:
default:
return {RAS_2819T_FAN2_AUTO, RAS_2819T_SUFFIX_AUTO};
}
}
/**
* Get temperature code for RAS-2819T protocol
*/
static uint8_t get_ras_2819t_temp_code(float temperature) {
int temp_index = static_cast<int>(temperature) - 18;
if (temp_index < 0 || temp_index >= static_cast<int>(sizeof(RAS_2819T_TEMP_CODES))) {
ESP_LOGW(TAG, "Temperature %.1f°C out of range [18-30°C], defaulting to 24°C", temperature);
return 0x40; // Default to 24°C
}
return RAS_2819T_TEMP_CODES[temp_index];
}
/**
* Decode temperature from RAS-2819T temp code
*/
static float decode_ras_2819t_temperature(uint8_t temp_code) {
uint8_t base_temp_code = temp_code & 0xF0;
// Find the code in the temperature array
for (size_t temp_index = 0; temp_index < sizeof(RAS_2819T_TEMP_CODES); temp_index++) {
if (RAS_2819T_TEMP_CODES[temp_index] == base_temp_code) {
return static_cast<float>(temp_index + 18); // 18°C is the minimum
}
}
ESP_LOGW(TAG, "Unknown temp code: 0x%02X, defaulting to 24°C", base_temp_code);
return 24.0f; // Default to 24°C
}
/**
* Decode fan speed from RAS-2819T IR codes
*/
static climate::ClimateFanMode decode_ras_2819t_fan_mode(uint16_t fan_code) {
switch (fan_code) {
case RAS_2819T_FAN_QUIET:
return climate::CLIMATE_FAN_QUIET;
case RAS_2819T_FAN_LOW:
return climate::CLIMATE_FAN_LOW;
case RAS_2819T_FAN_MEDIUM:
return climate::CLIMATE_FAN_MEDIUM;
case RAS_2819T_FAN_HIGH:
return climate::CLIMATE_FAN_HIGH;
case RAS_2819T_FAN_AUTO:
default:
return climate::CLIMATE_FAN_AUTO;
}
}
/**
* Validate RAS-2819T IR command structure and content
*/
static bool is_valid_ras_2819t_command(uint64_t rc_code_1, uint64_t rc_code_2 = 0) {
// Check header of first packet
uint16_t header1 = (rc_code_1 >> 32) & 0xFFFF;
if (header1 != RAS_2819T_VALID_HEADER1) {
return false;
}
// Single packet commands
if (rc_code_2 == 0) {
for (uint64_t valid_cmd : RAS_2819T_VALID_SINGLE_COMMANDS) {
if (rc_code_1 == valid_cmd) {
return true;
}
}
// Additional validation for unknown single packets
return false;
}
// Two-packet commands - validate second packet header
uint8_t header2 = (rc_code_2 >> 40) & 0xFF;
if (header2 != RAS_2819T_VALID_HEADER2) {
return false;
}
// Validate temperature complement in first packet (byte 4 should be ~byte 5)
uint8_t temp_byte = (rc_code_1 >> 8) & 0xFF;
uint8_t temp_complement = rc_code_1 & 0xFF;
if (temp_byte != static_cast<uint8_t>(~temp_complement)) {
return false;
}
// Validate fan speed combinations make sense
uint16_t fan_code = (rc_code_1 >> 16) & 0xFFFF;
uint8_t fan2_byte = (rc_code_2 >> 32) & 0xFF;
// Check if fan codes are from known valid patterns
bool valid_fan_combo = false;
if (fan_code == RAS_2819T_FAN_AUTO && fan2_byte == RAS_2819T_FAN2_AUTO)
valid_fan_combo = true;
if (fan_code == RAS_2819T_FAN_QUIET && fan2_byte == RAS_2819T_FAN2_QUIET)
valid_fan_combo = true;
if (fan_code == RAS_2819T_FAN_LOW && fan2_byte == RAS_2819T_FAN2_LOW)
valid_fan_combo = true;
if (fan_code == RAS_2819T_FAN_MEDIUM && fan2_byte == RAS_2819T_FAN2_MEDIUM)
valid_fan_combo = true;
if (fan_code == RAS_2819T_FAN_HIGH && fan2_byte == RAS_2819T_FAN2_HIGH)
valid_fan_combo = true;
if (fan_code == 0x1FE0 && fan2_byte == RAS_2819T_AUTO_DRY_FAN_BYTE)
valid_fan_combo = true; // AUTO/DRY
return valid_fan_combo;
}
void ToshibaClimate::setup() { void ToshibaClimate::setup() {
if (this->sensor_) { if (this->sensor_) {
this->sensor_->add_on_state_callback([this](float state) { this->sensor_->add_on_state_callback([this](float state) {
@@ -126,16 +403,43 @@ void ToshibaClimate::setup() {
this->minimum_temperature_ = this->temperature_min_(); this->minimum_temperature_ = this->temperature_min_();
this->maximum_temperature_ = this->temperature_max_(); this->maximum_temperature_ = this->temperature_max_();
this->swing_modes_ = this->toshiba_swing_modes_(); this->swing_modes_ = this->toshiba_swing_modes_();
// Ensure swing mode is always initialized to a valid value
if (this->swing_modes_.empty() || this->swing_modes_.find(this->swing_mode) == this->swing_modes_.end()) {
// No swing support for this model or current swing mode not supported, reset to OFF
this->swing_mode = climate::CLIMATE_SWING_OFF;
}
// Ensure mode is valid - ESPHome should only use standard climate modes
if (this->mode != climate::CLIMATE_MODE_OFF && this->mode != climate::CLIMATE_MODE_HEAT &&
this->mode != climate::CLIMATE_MODE_COOL && this->mode != climate::CLIMATE_MODE_HEAT_COOL &&
this->mode != climate::CLIMATE_MODE_DRY && this->mode != climate::CLIMATE_MODE_FAN_ONLY) {
ESP_LOGW(TAG, "Invalid mode detected during setup, resetting to OFF");
this->mode = climate::CLIMATE_MODE_OFF;
}
// Ensure fan mode is valid
if (!this->fan_mode.has_value()) {
ESP_LOGW(TAG, "Fan mode not set during setup, defaulting to AUTO");
this->fan_mode = climate::CLIMATE_FAN_AUTO;
}
// Never send nan to HA // Never send nan to HA
if (std::isnan(this->target_temperature)) if (std::isnan(this->target_temperature))
this->target_temperature = 24; this->target_temperature = 24;
// Log final state for debugging HA errors
ESP_LOGV(TAG, "Setup complete - Mode: %d, Fan: %s, Swing: %d, Temp: %.1f", static_cast<int>(this->mode),
this->fan_mode.has_value() ? std::to_string(static_cast<int>(this->fan_mode.value())).c_str() : "NONE",
static_cast<int>(this->swing_mode), this->target_temperature);
} }
void ToshibaClimate::transmit_state() { void ToshibaClimate::transmit_state() {
if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F) { if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F) {
transmit_rac_pt1411hwru_(); this->transmit_rac_pt1411hwru_();
} else if (this->model_ == MODEL_RAS_2819T) {
this->transmit_ras_2819t_();
} else { } else {
transmit_generic_(); this->transmit_generic_();
} }
} }
@@ -230,7 +534,7 @@ void ToshibaClimate::transmit_generic_() {
auto transmit = this->transmitter_->transmit(); auto transmit = this->transmitter_->transmit();
auto *data = transmit.get_data(); auto *data = transmit.get_data();
encode_(data, message, message_length, 1); this->encode_(data, message, message_length, 1);
transmit.perform(); transmit.perform();
} }
@@ -348,15 +652,12 @@ void ToshibaClimate::transmit_rac_pt1411hwru_() {
message[11] += message[index]; message[11] += message[index];
} }
} }
ESP_LOGV(TAG, "*** Generated codes: 0x%.2X%.2X%.2X%.2X%.2X%.2X 0x%.2X%.2X%.2X%.2X%.2X%.2X", message[0], message[1],
message[2], message[3], message[4], message[5], message[6], message[7], message[8], message[9], message[10],
message[11]);
// load first block of IR code and repeat it once // load first block of IR code and repeat it once
encode_(data, &message[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1); this->encode_(data, &message[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
// load second block of IR code, if present // load second block of IR code, if present
if (message[6] != 0) { if (message[6] != 0) {
encode_(data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH, 0); this->encode_(data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH, 0);
} }
transmit.perform(); transmit.perform();
@@ -366,19 +667,19 @@ void ToshibaClimate::transmit_rac_pt1411hwru_() {
data->space(TOSHIBA_PACKET_SPACE); data->space(TOSHIBA_PACKET_SPACE);
switch (this->swing_mode) { switch (this->swing_mode) {
case climate::CLIMATE_SWING_VERTICAL: case climate::CLIMATE_SWING_VERTICAL:
encode_(data, &RAC_PT1411HWRU_SWING_VERTICAL[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1); this->encode_(data, &RAC_PT1411HWRU_SWING_VERTICAL[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
break; break;
case climate::CLIMATE_SWING_OFF: case climate::CLIMATE_SWING_OFF:
default: default:
encode_(data, &RAC_PT1411HWRU_SWING_OFF[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1); this->encode_(data, &RAC_PT1411HWRU_SWING_OFF[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
} }
data->space(TOSHIBA_PACKET_SPACE); data->space(TOSHIBA_PACKET_SPACE);
transmit.perform(); transmit.perform();
if (this->sensor_) { if (this->sensor_) {
transmit_rac_pt1411hwru_temp_(true, false); this->transmit_rac_pt1411hwru_temp_(true, false);
} }
} }
@@ -430,15 +731,217 @@ void ToshibaClimate::transmit_rac_pt1411hwru_temp_(const bool cs_state, const bo
// Byte 5: Footer lower/bitwise complement of byte 4 // Byte 5: Footer lower/bitwise complement of byte 4
message[5] = ~message[4]; message[5] = ~message[4];
ESP_LOGV(TAG, "*** Generated code: 0x%.2X%.2X%.2X%.2X%.2X%.2X", message[0], message[1], message[2], message[3],
message[4], message[5]);
// load IR code and repeat it once // load IR code and repeat it once
encode_(data, message, RAC_PT1411HWRU_MESSAGE_LENGTH, 1); this->encode_(data, message, RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
transmit.perform(); transmit.perform();
} }
} }
void ToshibaClimate::transmit_ras_2819t_() {
// Handle swing mode transmission for RAS-2819T
// Note: RAS-2819T uses a toggle command, so we need to track state changes
// Check if ONLY swing mode changed (and no other climate parameters)
bool swing_changed = (this->swing_mode != this->last_swing_mode_);
bool mode_changed = (this->mode != this->last_mode_);
bool fan_changed = (this->fan_mode != this->last_fan_mode_);
bool temp_changed = (abs(this->target_temperature - this->last_target_temperature_) > 0.1f);
bool only_swing_changed = swing_changed && !mode_changed && !fan_changed && !temp_changed;
if (only_swing_changed) {
// Send ONLY swing toggle command (like the physical remote does)
auto swing_transmit = this->transmitter_->transmit();
auto *swing_data = swing_transmit.get_data();
// Convert toggle command to bytes for transmission
uint8_t swing_message[RAS_2819T_MESSAGE_LENGTH];
swing_message[0] = (RAS_2819T_SWING_TOGGLE >> 40) & 0xFF;
swing_message[1] = (RAS_2819T_SWING_TOGGLE >> 32) & 0xFF;
swing_message[2] = (RAS_2819T_SWING_TOGGLE >> 24) & 0xFF;
swing_message[3] = (RAS_2819T_SWING_TOGGLE >> 16) & 0xFF;
swing_message[4] = (RAS_2819T_SWING_TOGGLE >> 8) & 0xFF;
swing_message[5] = RAS_2819T_SWING_TOGGLE & 0xFF;
// Use single packet transmission WITH repeat (like regular commands)
this->encode_(swing_data, swing_message, RAS_2819T_MESSAGE_LENGTH, 1);
swing_transmit.perform();
// Update all state tracking
this->last_swing_mode_ = this->swing_mode;
this->last_mode_ = this->mode;
this->last_fan_mode_ = this->fan_mode;
this->last_target_temperature_ = this->target_temperature;
// Immediately publish the state change to Home Assistant
this->publish_state();
return; // Exit early - don't send climate command
}
// If we get here, send the regular climate command (temperature/mode/fan)
uint8_t message1[RAS_2819T_MESSAGE_LENGTH] = {0};
uint8_t message2[RAS_2819T_MESSAGE_LENGTH] = {0};
float temperature =
clamp<float>(this->target_temperature, TOSHIBA_RAS_2819T_TEMP_C_MIN, TOSHIBA_RAS_2819T_TEMP_C_MAX);
// Build first packet (RAS_2819T_HEADER1 + 4 bytes)
message1[0] = (RAS_2819T_HEADER1 >> 8) & 0xFF;
message1[1] = RAS_2819T_HEADER1 & 0xFF;
// Handle OFF mode
if (this->mode == climate::CLIMATE_MODE_OFF) {
// Extract bytes from power off command constant
message1[2] = (RAS_2819T_POWER_OFF_COMMAND >> 24) & 0xFF;
message1[3] = (RAS_2819T_POWER_OFF_COMMAND >> 16) & 0xFF;
message1[4] = (RAS_2819T_POWER_OFF_COMMAND >> 8) & 0xFF;
message1[5] = RAS_2819T_POWER_OFF_COMMAND & 0xFF;
// No second packet for OFF
} else {
// Get temperature and fan encoding
uint8_t temp_code = get_ras_2819t_temp_code(temperature);
// Get fan speed encoding for rc_code_1
climate::ClimateFanMode effective_fan_mode = this->fan_mode.value();
// Dry mode only supports AUTO fan speed
if (this->mode == climate::CLIMATE_MODE_DRY) {
effective_fan_mode = climate::CLIMATE_FAN_AUTO;
if (this->fan_mode.value() != climate::CLIMATE_FAN_AUTO) {
ESP_LOGW(TAG, "Dry mode only supports AUTO fan speed, forcing AUTO");
}
}
uint16_t fan_code = get_ras_2819t_fan_code(effective_fan_mode);
// Mode and temperature encoding
switch (this->mode) {
case climate::CLIMATE_MODE_COOL:
// All cooling temperatures support fan speed control
message1[2] = (fan_code >> 8) & 0xFF;
message1[3] = fan_code & 0xFF;
message1[4] = temp_code;
message1[5] = ~temp_code;
break;
case climate::CLIMATE_MODE_HEAT:
// Heating supports fan speed control
message1[2] = (fan_code >> 8) & 0xFF;
message1[3] = fan_code & 0xFF;
// Heat mode adds offset to temperature code
message1[4] = temp_code | RAS_2819T_HEAT_TEMP_OFFSET;
message1[5] = ~(temp_code | RAS_2819T_HEAT_TEMP_OFFSET);
break;
case climate::CLIMATE_MODE_HEAT_COOL:
// Auto mode uses fixed encoding
message1[2] = RAS_2819T_AUTO_BYTE2;
message1[3] = RAS_2819T_AUTO_BYTE3;
message1[4] = temp_code | RAS_2819T_AUTO_TEMP_OFFSET;
message1[5] = ~(temp_code | RAS_2819T_AUTO_TEMP_OFFSET);
break;
case climate::CLIMATE_MODE_DRY:
// Dry mode uses fixed encoding and forces AUTO fan
message1[2] = RAS_2819T_DRY_BYTE2;
message1[3] = RAS_2819T_DRY_BYTE3;
message1[4] = temp_code | RAS_2819T_DRY_TEMP_OFFSET;
message1[5] = ~message1[4];
break;
case climate::CLIMATE_MODE_FAN_ONLY:
// Fan only mode supports fan speed control
message1[2] = (fan_code >> 8) & 0xFF;
message1[3] = fan_code & 0xFF;
message1[4] = RAS_2819T_FAN_ONLY_TEMP;
message1[5] = RAS_2819T_FAN_ONLY_TEMP_INV;
break;
default:
// Default case supports fan speed control
message1[2] = (fan_code >> 8) & 0xFF;
message1[3] = fan_code & 0xFF;
message1[4] = temp_code;
message1[5] = ~temp_code;
break;
}
// Build second packet (RAS_2819T_HEADER2 + 4 bytes)
message2[0] = RAS_2819T_HEADER2;
// Get fan speed encoding for rc_code_2
Ras2819tSecondPacketCodes second_packet_codes = get_ras_2819t_second_packet_codes(effective_fan_mode);
// Determine header byte 2 and fan encoding based on mode
switch (this->mode) {
case climate::CLIMATE_MODE_COOL:
message2[1] = second_packet_codes.fan_byte;
message2[2] = 0x00;
message2[3] = second_packet_codes.suffix.byte3;
message2[4] = second_packet_codes.suffix.byte4;
message2[5] = second_packet_codes.suffix.byte5;
break;
case climate::CLIMATE_MODE_HEAT:
message2[1] = second_packet_codes.fan_byte;
message2[2] = 0x00;
message2[3] = second_packet_codes.suffix.byte3;
message2[4] = 0x00;
message2[5] = RAS_2819T_HEAT_SUFFIX;
break;
case climate::CLIMATE_MODE_HEAT_COOL:
case climate::CLIMATE_MODE_DRY:
// Auto/Dry modes use fixed values regardless of fan setting
message2[1] = RAS_2819T_AUTO_DRY_FAN_BYTE;
message2[2] = 0x00;
message2[3] = 0x00;
message2[4] = 0x00;
message2[5] = RAS_2819T_AUTO_DRY_SUFFIX;
break;
case climate::CLIMATE_MODE_FAN_ONLY:
message2[1] = second_packet_codes.fan_byte;
message2[2] = 0x00;
message2[3] = second_packet_codes.suffix.byte3;
message2[4] = 0x00;
message2[5] = RAS_2819T_HEAT_SUFFIX;
break;
default:
message2[1] = second_packet_codes.fan_byte;
message2[2] = 0x00;
message2[3] = second_packet_codes.suffix.byte3;
message2[4] = second_packet_codes.suffix.byte4;
message2[5] = second_packet_codes.suffix.byte5;
break;
}
}
// Log final messages being transmitted
// Transmit using proper Toshiba protocol timing
auto transmit = this->transmitter_->transmit();
auto *data = transmit.get_data();
// Use existing Toshiba encode function for proper timing
this->encode_(data, message1, RAS_2819T_MESSAGE_LENGTH, 1);
if (this->mode != climate::CLIMATE_MODE_OFF) {
// Send second packet with gap
this->encode_(data, message2, RAS_2819T_MESSAGE_LENGTH, 0);
}
transmit.perform();
// Update all state tracking after successful transmission
this->last_swing_mode_ = this->swing_mode;
this->last_mode_ = this->mode;
this->last_fan_mode_ = this->fan_mode;
this->last_target_temperature_ = this->target_temperature;
}
uint8_t ToshibaClimate::is_valid_rac_pt1411hwru_header_(const uint8_t *message) { uint8_t ToshibaClimate::is_valid_rac_pt1411hwru_header_(const uint8_t *message) {
const std::vector<uint8_t> header{RAC_PT1411HWRU_MESSAGE_HEADER0, RAC_PT1411HWRU_CS_HEADER, const std::vector<uint8_t> header{RAC_PT1411HWRU_MESSAGE_HEADER0, RAC_PT1411HWRU_CS_HEADER,
RAC_PT1411HWRU_SWING_HEADER}; RAC_PT1411HWRU_SWING_HEADER};
@@ -464,11 +967,11 @@ bool ToshibaClimate::compare_rac_pt1411hwru_packets_(const uint8_t *message1, co
bool ToshibaClimate::is_valid_rac_pt1411hwru_message_(const uint8_t *message) { bool ToshibaClimate::is_valid_rac_pt1411hwru_message_(const uint8_t *message) {
uint8_t checksum = 0; uint8_t checksum = 0;
switch (is_valid_rac_pt1411hwru_header_(message)) { switch (this->is_valid_rac_pt1411hwru_header_(message)) {
case RAC_PT1411HWRU_MESSAGE_HEADER0: case RAC_PT1411HWRU_MESSAGE_HEADER0:
case RAC_PT1411HWRU_CS_HEADER: case RAC_PT1411HWRU_CS_HEADER:
case RAC_PT1411HWRU_SWING_HEADER: case RAC_PT1411HWRU_SWING_HEADER:
if (is_valid_rac_pt1411hwru_header_(message) && (message[2] == static_cast<uint8_t>(~message[3])) && if (this->is_valid_rac_pt1411hwru_header_(message) && (message[2] == static_cast<uint8_t>(~message[3])) &&
(message[4] == static_cast<uint8_t>(~message[5]))) { (message[4] == static_cast<uint8_t>(~message[5]))) {
return true; return true;
} }
@@ -490,7 +993,103 @@ bool ToshibaClimate::is_valid_rac_pt1411hwru_message_(const uint8_t *message) {
return false; return false;
} }
bool ToshibaClimate::process_ras_2819t_command_(const remote_base::ToshibaAcData &toshiba_data) {
// Check for power-off command (single packet)
if (toshiba_data.rc_code_2 == 0 && toshiba_data.rc_code_1 == RAS_2819T_POWER_OFF_COMMAND) {
this->mode = climate::CLIMATE_MODE_OFF;
ESP_LOGI(TAG, "Mode: OFF");
this->publish_state();
return true;
}
// Check for swing toggle command (single packet)
if (toshiba_data.rc_code_2 == 0 && toshiba_data.rc_code_1 == RAS_2819T_SWING_TOGGLE) {
// Toggle swing mode
if (this->swing_mode == climate::CLIMATE_SWING_VERTICAL) {
this->swing_mode = climate::CLIMATE_SWING_OFF;
ESP_LOGI(TAG, "Swing: OFF");
} else {
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
ESP_LOGI(TAG, "Swing: VERTICAL");
}
this->publish_state();
return true;
}
// Handle regular two-packet commands (mode/temperature/fan changes)
if (toshiba_data.rc_code_2 != 0) {
// Convert to byte array for easier processing
uint8_t message1[6], message2[6];
for (uint8_t i = 0; i < 6; i++) {
message1[i] = (toshiba_data.rc_code_1 >> (40 - i * 8)) & 0xFF;
message2[i] = (toshiba_data.rc_code_2 >> (40 - i * 8)) & 0xFF;
}
// Decode the protocol using message1 (rc_code_1)
uint8_t temp_code = message1[4];
// Decode mode - check bytes 2-3 pattern and temperature code
if ((message1[2] == 0x7B) && (message1[3] == 0x84)) {
// OFF mode has specific pattern
this->mode = climate::CLIMATE_MODE_OFF;
ESP_LOGI(TAG, "Mode: OFF");
} else if ((message1[2] == 0x1F) && (message1[3] == 0xE0)) {
// 0x1FE0 pattern is used for AUTO, DRY, and low-temp COOL
if ((temp_code & 0x0F) == 0x08) {
this->mode = climate::CLIMATE_MODE_HEAT_COOL;
ESP_LOGI(TAG, "Mode: AUTO");
} else if ((temp_code & 0x0F) == 0x04) {
this->mode = climate::CLIMATE_MODE_DRY;
ESP_LOGI(TAG, "Mode: DRY");
} else {
this->mode = climate::CLIMATE_MODE_COOL;
ESP_LOGI(TAG, "Mode: COOL (low temp)");
}
} else {
// Variable fan speed patterns - decode by temperature code
if ((temp_code & 0x0F) == 0x0C) {
this->mode = climate::CLIMATE_MODE_HEAT;
ESP_LOGI(TAG, "Mode: HEAT");
} else if (message1[5] == 0x1B) {
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
ESP_LOGI(TAG, "Mode: FAN_ONLY");
} else {
this->mode = climate::CLIMATE_MODE_COOL;
ESP_LOGI(TAG, "Mode: COOL");
}
}
// Decode fan speed from rc_code_1
uint16_t fan_code = (message1[2] << 8) | message1[3];
this->fan_mode = decode_ras_2819t_fan_mode(fan_code);
// Decode temperature
if (this->mode != climate::CLIMATE_MODE_OFF && this->mode != climate::CLIMATE_MODE_FAN_ONLY) {
this->target_temperature = decode_ras_2819t_temperature(temp_code);
}
this->publish_state();
return true;
} else {
ESP_LOGD(TAG, "Unknown single-packet RAS-2819T command: 0x%" PRIX64, toshiba_data.rc_code_1);
return false;
}
}
bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) { bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) {
// Try modern ToshibaAcProtocol decoder first (handles RAS-2819T and potentially others)
remote_base::ToshibaAcProtocol toshiba_protocol;
auto decode_result = toshiba_protocol.decode(data);
if (decode_result.has_value()) {
auto toshiba_data = decode_result.value();
// Validate and process RAS-2819T commands
if (is_valid_ras_2819t_command(toshiba_data.rc_code_1, toshiba_data.rc_code_2)) {
return this->process_ras_2819t_command_(toshiba_data);
}
}
// Fall back to generic processing for older protocols
uint8_t message[18] = {0}; uint8_t message[18] = {0};
uint8_t message_length = TOSHIBA_HEADER_LENGTH, temperature_code = 0; uint8_t message_length = TOSHIBA_HEADER_LENGTH, temperature_code = 0;
@@ -499,11 +1098,11 @@ bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) {
return false; return false;
} }
// Read incoming bits into buffer // Read incoming bits into buffer
if (!decode_(&data, message, message_length)) { if (!this->decode_(&data, message, message_length)) {
return false; return false;
} }
// Determine incoming message protocol version and/or length // Determine incoming message protocol version and/or length
if (is_valid_rac_pt1411hwru_header_(message)) { if (this->is_valid_rac_pt1411hwru_header_(message)) {
// We already received four bytes // We already received four bytes
message_length = RAC_PT1411HWRU_MESSAGE_LENGTH - 4; message_length = RAC_PT1411HWRU_MESSAGE_LENGTH - 4;
} else if ((message[0] ^ message[1] ^ message[2]) != message[3]) { } else if ((message[0] ^ message[1] ^ message[2]) != message[3]) {
@@ -514,11 +1113,11 @@ bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) {
message_length = message[2] + 2; message_length = message[2] + 2;
} }
// Decode the remaining bytes // Decode the remaining bytes
if (!decode_(&data, &message[4], message_length)) { if (!this->decode_(&data, &message[4], message_length)) {
return false; return false;
} }
// If this is a RAC-PT1411HWRU message, we expect the first packet a second time and also possibly a third packet // If this is a RAC-PT1411HWRU message, we expect the first packet a second time and also possibly a third packet
if (is_valid_rac_pt1411hwru_header_(message)) { if (this->is_valid_rac_pt1411hwru_header_(message)) {
// There is always a space between packets // There is always a space between packets
if (!data.expect_item(TOSHIBA_BIT_MARK, TOSHIBA_GAP_SPACE)) { if (!data.expect_item(TOSHIBA_BIT_MARK, TOSHIBA_GAP_SPACE)) {
return false; return false;
@@ -527,7 +1126,7 @@ bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) {
if (!data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE)) { if (!data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE)) {
return false; return false;
} }
if (!decode_(&data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH)) { if (!this->decode_(&data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH)) {
return false; return false;
} }
// If this is a RAC-PT1411HWRU message, there may also be a third packet. // If this is a RAC-PT1411HWRU message, there may also be a third packet.
@@ -535,25 +1134,25 @@ bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) {
if (data.expect_item(TOSHIBA_BIT_MARK, TOSHIBA_GAP_SPACE)) { if (data.expect_item(TOSHIBA_BIT_MARK, TOSHIBA_GAP_SPACE)) {
// Validate header 3 // Validate header 3
data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE); data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE);
if (decode_(&data, &message[12], RAC_PT1411HWRU_MESSAGE_LENGTH)) { if (this->decode_(&data, &message[12], RAC_PT1411HWRU_MESSAGE_LENGTH)) {
if (!is_valid_rac_pt1411hwru_message_(&message[12])) { if (!this->is_valid_rac_pt1411hwru_message_(&message[12])) {
// If a third packet was received but the checksum is not valid, fail // If a third packet was received but the checksum is not valid, fail
return false; return false;
} }
} }
} }
if (!compare_rac_pt1411hwru_packets_(&message[0], &message[6])) { if (!this->compare_rac_pt1411hwru_packets_(&message[0], &message[6])) {
// If the first two packets don't match each other, fail // If the first two packets don't match each other, fail
return false; return false;
} }
if (!is_valid_rac_pt1411hwru_message_(&message[0])) { if (!this->is_valid_rac_pt1411hwru_message_(&message[0])) {
// If the first packet isn't valid, fail // If the first packet isn't valid, fail
return false; return false;
} }
} }
// Header has been verified, now determine protocol version and set the climate component properties // Header has been verified, now determine protocol version and set the climate component properties
switch (is_valid_rac_pt1411hwru_header_(message)) { switch (this->is_valid_rac_pt1411hwru_header_(message)) {
// Power, temperature, mode, fan speed // Power, temperature, mode, fan speed
case RAC_PT1411HWRU_MESSAGE_HEADER0: case RAC_PT1411HWRU_MESSAGE_HEADER0:
// Get the mode // Get the mode
@@ -608,7 +1207,7 @@ bool ToshibaClimate::on_receive(remote_base::RemoteReceiveData data) {
break; break;
} }
// Get the target temperature // Get the target temperature
if (is_valid_rac_pt1411hwru_message_(&message[12])) { if (this->is_valid_rac_pt1411hwru_message_(&message[12])) {
temperature_code = temperature_code =
(message[4] >> 4) | (message[14] & RAC_PT1411HWRU_FLAG_FRAC) | (message[15] & RAC_PT1411HWRU_FLAG_NEG); (message[4] >> 4) | (message[14] & RAC_PT1411HWRU_FLAG_FRAC) | (message[15] & RAC_PT1411HWRU_FLAG_NEG);
if (message[15] & RAC_PT1411HWRU_FLAG_FAH) { if (message[15] & RAC_PT1411HWRU_FLAG_FAH) {

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "esphome/components/climate_ir/climate_ir.h" #include "esphome/components/climate_ir/climate_ir.h"
#include "esphome/components/remote_base/toshiba_ac_protocol.h"
namespace esphome { namespace esphome {
namespace toshiba { namespace toshiba {
@@ -10,6 +11,7 @@ enum Model {
MODEL_GENERIC = 0, // Temperature range is from 17 to 30 MODEL_GENERIC = 0, // Temperature range is from 17 to 30
MODEL_RAC_PT1411HWRU_C = 1, // Temperature range is from 16 to 30 MODEL_RAC_PT1411HWRU_C = 1, // Temperature range is from 16 to 30
MODEL_RAC_PT1411HWRU_F = 2, // Temperature range is from 16 to 30 MODEL_RAC_PT1411HWRU_F = 2, // Temperature range is from 16 to 30
MODEL_RAS_2819T = 3, // RAS-2819T protocol variant, temperature range 18 to 30
}; };
// Supported temperature ranges // Supported temperature ranges
@@ -19,6 +21,8 @@ const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MIN = 16.0;
const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX = 30.0; const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX = 30.0;
const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MIN = 60.0; const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MIN = 60.0;
const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MAX = 86.0; const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MAX = 86.0;
const float TOSHIBA_RAS_2819T_TEMP_C_MIN = 18.0;
const float TOSHIBA_RAS_2819T_TEMP_C_MAX = 30.0;
class ToshibaClimate : public climate_ir::ClimateIR { class ToshibaClimate : public climate_ir::ClimateIR {
public: public:
@@ -35,6 +39,9 @@ class ToshibaClimate : public climate_ir::ClimateIR {
void transmit_generic_(); void transmit_generic_();
void transmit_rac_pt1411hwru_(); void transmit_rac_pt1411hwru_();
void transmit_rac_pt1411hwru_temp_(bool cs_state = true, bool cs_send_update = true); void transmit_rac_pt1411hwru_temp_(bool cs_state = true, bool cs_send_update = true);
void transmit_ras_2819t_();
// Process RAS-2819T IR command data
bool process_ras_2819t_command_(const remote_base::ToshibaAcData &toshiba_data);
// Returns the header if valid, else returns zero // Returns the header if valid, else returns zero
uint8_t is_valid_rac_pt1411hwru_header_(const uint8_t *message); uint8_t is_valid_rac_pt1411hwru_header_(const uint8_t *message);
// Returns true if message is a valid RAC-PT1411HWRU IR message, regardless if first or second packet // Returns true if message is a valid RAC-PT1411HWRU IR message, regardless if first or second packet
@@ -43,11 +50,26 @@ class ToshibaClimate : public climate_ir::ClimateIR {
bool compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2); bool compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2);
bool on_receive(remote_base::RemoteReceiveData data) override; bool on_receive(remote_base::RemoteReceiveData data) override;
private:
// RAS-2819T state tracking for swing mode optimization
climate::ClimateSwingMode last_swing_mode_{climate::CLIMATE_SWING_OFF};
climate::ClimateMode last_mode_{climate::CLIMATE_MODE_OFF};
optional<climate::ClimateFanMode> last_fan_mode_{};
float last_target_temperature_{24.0f};
float temperature_min_() { float temperature_min_() {
return (this->model_ == MODEL_GENERIC) ? TOSHIBA_GENERIC_TEMP_C_MIN : TOSHIBA_RAC_PT1411HWRU_TEMP_C_MIN; if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F)
return TOSHIBA_RAC_PT1411HWRU_TEMP_C_MIN;
if (this->model_ == MODEL_RAS_2819T)
return TOSHIBA_RAS_2819T_TEMP_C_MIN;
return TOSHIBA_GENERIC_TEMP_C_MIN; // Default to GENERIC for unknown models
} }
float temperature_max_() { float temperature_max_() {
return (this->model_ == MODEL_GENERIC) ? TOSHIBA_GENERIC_TEMP_C_MAX : TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX; if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F)
return TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX;
if (this->model_ == MODEL_RAS_2819T)
return TOSHIBA_RAS_2819T_TEMP_C_MAX;
return TOSHIBA_GENERIC_TEMP_C_MAX; // Default to GENERIC for unknown models
} }
std::set<climate::ClimateSwingMode> toshiba_swing_modes_() { std::set<climate::ClimateSwingMode> toshiba_swing_modes_() {
return (this->model_ == MODEL_GENERIC) return (this->model_ == MODEL_GENERIC)

View File

@@ -3,6 +3,7 @@ from esphome.components import i2c, sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
CONF_OVERSAMPLING,
CONF_PRESSURE, CONF_PRESSURE,
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
@@ -18,6 +19,17 @@ CODEOWNERS = ["@gcormier"]
CONF_K_VALUE = "k_value" CONF_K_VALUE = "k_value"
xgzp68xx_ns = cg.esphome_ns.namespace("xgzp68xx") xgzp68xx_ns = cg.esphome_ns.namespace("xgzp68xx")
XGZP68XXOversampling = xgzp68xx_ns.enum("XGZP68XXOversampling")
OVERSAMPLING_OPTIONS = {
"256X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_256X,
"512X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_512X,
"1024X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_1024X,
"2048X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_2048X,
"4096X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_4096X,
"8192X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_8192X,
"16384X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_16384X,
"32768X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_32768X,
}
XGZP68XXComponent = xgzp68xx_ns.class_( XGZP68XXComponent = xgzp68xx_ns.class_(
"XGZP68XXComponent", cg.PollingComponent, i2c.I2CDevice "XGZP68XXComponent", cg.PollingComponent, i2c.I2CDevice
) )
@@ -31,6 +43,12 @@ CONFIG_SCHEMA = (
accuracy_decimals=1, accuracy_decimals=1,
device_class=DEVICE_CLASS_PRESSURE, device_class=DEVICE_CLASS_PRESSURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
).extend(
{
cv.Optional(CONF_OVERSAMPLING, default="4096X"): cv.enum(
OVERSAMPLING_OPTIONS, upper=True
),
}
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS, unit_of_measurement=UNIT_CELSIUS,
@@ -58,5 +76,6 @@ async def to_code(config):
if pressure_config := config.get(CONF_PRESSURE): if pressure_config := config.get(CONF_PRESSURE):
sens = await sensor.new_sensor(pressure_config) sens = await sensor.new_sensor(pressure_config)
cg.add(var.set_pressure_sensor(sens)) cg.add(var.set_pressure_sensor(sens))
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
cg.add(var.set_k_value(config[CONF_K_VALUE])) cg.add(var.set_k_value(config[CONF_K_VALUE]))

View File

@@ -16,16 +16,49 @@ static const uint8_t SYSCONFIG_ADDRESS = 0xA5;
static const uint8_t PCONFIG_ADDRESS = 0xA6; static const uint8_t PCONFIG_ADDRESS = 0xA6;
static const uint8_t READ_COMMAND = 0x0A; static const uint8_t READ_COMMAND = 0x0A;
[[maybe_unused]] static const char *oversampling_to_str(XGZP68XXOversampling oversampling) {
switch (oversampling) {
case XGZP68XX_OVERSAMPLING_256X:
return "256x";
case XGZP68XX_OVERSAMPLING_512X:
return "512x";
case XGZP68XX_OVERSAMPLING_1024X:
return "1024x";
case XGZP68XX_OVERSAMPLING_2048X:
return "2048x";
case XGZP68XX_OVERSAMPLING_4096X:
return "4096x";
case XGZP68XX_OVERSAMPLING_8192X:
return "8192x";
case XGZP68XX_OVERSAMPLING_16384X:
return "16384x";
case XGZP68XX_OVERSAMPLING_32768X:
return "32768x";
default:
return "UNKNOWN";
}
}
void XGZP68XXComponent::update() { void XGZP68XXComponent::update() {
// Do we need to change oversampling?
if (this->last_pressure_oversampling_ != this->pressure_oversampling_) {
uint8_t oldconfig = 0;
this->read_register(PCONFIG_ADDRESS, &oldconfig, 1);
uint8_t newconfig = (oldconfig & 0xf8) | (this->pressure_oversampling_ & 0x7);
this->write_register(PCONFIG_ADDRESS, &newconfig, 1);
ESP_LOGD(TAG, "oversampling to %s: oldconfig = 0x%x newconfig = 0x%x",
oversampling_to_str(this->pressure_oversampling_), oldconfig, newconfig);
this->last_pressure_oversampling_ = this->pressure_oversampling_;
}
// Request temp + pressure acquisition // Request temp + pressure acquisition
this->write_register(0x30, &READ_COMMAND, 1); this->write_register(0x30, &READ_COMMAND, 1);
// Wait 20mS per datasheet // Wait 20mS per datasheet
this->set_timeout("measurement", 20, [this]() { this->set_timeout("measurement", 20, [this]() {
uint8_t data[5]; uint8_t data[5] = {};
uint32_t pressure_raw; uint32_t pressure_raw = 0;
uint16_t temperature_raw; uint16_t temperature_raw = 0;
float pressure_in_pa, temperature;
int success; int success;
// Read the sensor data // Read the sensor data
@@ -42,23 +75,11 @@ void XGZP68XXComponent::update() {
ESP_LOGV(TAG, "Got raw pressure=%" PRIu32 ", raw temperature=%u", pressure_raw, temperature_raw); ESP_LOGV(TAG, "Got raw pressure=%" PRIu32 ", raw temperature=%u", pressure_raw, temperature_raw);
ESP_LOGV(TAG, "K value is %u", this->k_value_); ESP_LOGV(TAG, "K value is %u", this->k_value_);
// The most significant bit of both pressure and temperature will be 1 to indicate a negative value. // Sign extend the pressure
// This is directly from the datasheet, and the calculations below will handle this. float pressure_in_pa = (float) (((int32_t) pressure_raw << 8) >> 8);
if (pressure_raw > pow(2, 23)) { pressure_in_pa /= (float) (this->k_value_);
// Negative pressure
pressure_in_pa = (pressure_raw - pow(2, 24)) / (float) (this->k_value_);
} else {
// Positive pressure
pressure_in_pa = pressure_raw / (float) (this->k_value_);
}
if (temperature_raw > pow(2, 15)) { float temperature = ((float) (int16_t) temperature_raw) / 256.0f;
// Negative temperature
temperature = (float) (temperature_raw - pow(2, 16)) / 256.0f;
} else {
// Positive temperature
temperature = (float) temperature_raw / 256.0f;
}
if (this->pressure_sensor_ != nullptr) if (this->pressure_sensor_ != nullptr)
this->pressure_sensor_->publish_state(pressure_in_pa); this->pressure_sensor_->publish_state(pressure_in_pa);
@@ -69,20 +90,27 @@ void XGZP68XXComponent::update() {
} }
void XGZP68XXComponent::setup() { void XGZP68XXComponent::setup() {
uint8_t config; uint8_t config1 = 0, config2 = 0;
// Display some sample bits to confirm we are talking to the sensor // Display some sample bits to confirm we are talking to the sensor
this->read_register(SYSCONFIG_ADDRESS, &config, 1); if (i2c::ErrorCode::ERROR_OK != this->read_register(SYSCONFIG_ADDRESS, &config1, 1)) {
ESP_LOGCONFIG(TAG, this->mark_failed();
"Gain value is %d\n" return;
"XGZP68xx started!", }
(config >> 3) & 0b111); if (i2c::ErrorCode::ERROR_OK != this->read_register(PCONFIG_ADDRESS, &config2, 1)) {
this->mark_failed();
return;
}
ESP_LOGD(TAG, "sys_config 0x%x, p_config 0x%x", config1, config2);
} }
void XGZP68XXComponent::dump_config() { void XGZP68XXComponent::dump_config() {
ESP_LOGCONFIG(TAG, "XGZP68xx:"); ESP_LOGCONFIG(TAG, "XGZP68xx:");
LOG_SENSOR(" ", "Temperature: ", this->temperature_sensor_); LOG_SENSOR(" ", "Temperature: ", this->temperature_sensor_);
LOG_SENSOR(" ", "Pressure: ", this->pressure_sensor_); LOG_SENSOR(" ", "Pressure: ", this->pressure_sensor_);
if (this->pressure_sensor_ != nullptr) {
ESP_LOGCONFIG(TAG, " Oversampling: %s", oversampling_to_str(this->pressure_oversampling_));
}
LOG_I2C_DEVICE(this); LOG_I2C_DEVICE(this);
if (this->is_failed()) { if (this->is_failed()) {
ESP_LOGE(TAG, " Connection failed"); ESP_LOGE(TAG, " Connection failed");

View File

@@ -7,11 +7,29 @@
namespace esphome { namespace esphome {
namespace xgzp68xx { namespace xgzp68xx {
/// Enum listing all oversampling options for the XGZP68XX.
enum XGZP68XXOversampling : uint8_t {
XGZP68XX_OVERSAMPLING_256X = 0b100,
XGZP68XX_OVERSAMPLING_512X = 0b101,
XGZP68XX_OVERSAMPLING_1024X = 0b000,
XGZP68XX_OVERSAMPLING_2048X = 0b001,
XGZP68XX_OVERSAMPLING_4096X = 0b010,
XGZP68XX_OVERSAMPLING_8192X = 0b011,
XGZP68XX_OVERSAMPLING_16384X = 0b110,
XGZP68XX_OVERSAMPLING_32768X = 0b111,
XGZP68XX_OVERSAMPLING_UNKNOWN = (uint8_t) -1,
};
class XGZP68XXComponent : public PollingComponent, public sensor::Sensor, public i2c::I2CDevice { class XGZP68XXComponent : public PollingComponent, public sensor::Sensor, public i2c::I2CDevice {
public: public:
SUB_SENSOR(temperature) SUB_SENSOR(temperature)
SUB_SENSOR(pressure) SUB_SENSOR(pressure)
void set_k_value(uint16_t k_value) { this->k_value_ = k_value; } void set_k_value(uint16_t k_value) { this->k_value_ = k_value; }
/// Set the pressure oversampling value. Defaults to 4096X.
void set_pressure_oversampling(XGZP68XXOversampling pressure_oversampling) {
this->pressure_oversampling_ = pressure_oversampling;
}
void update() override; void update() override;
void setup() override; void setup() override;
@@ -21,6 +39,8 @@ class XGZP68XXComponent : public PollingComponent, public sensor::Sensor, public
/// Internal method to read the pressure from the component after it has been scheduled. /// Internal method to read the pressure from the component after it has been scheduled.
void read_pressure_(); void read_pressure_();
uint16_t k_value_; uint16_t k_value_;
XGZP68XXOversampling pressure_oversampling_{XGZP68XX_OVERSAMPLING_4096X};
XGZP68XXOversampling last_pressure_oversampling_{XGZP68XX_OVERSAMPLING_UNKNOWN};
}; };
} // namespace xgzp68xx } // namespace xgzp68xx

View File

@@ -228,12 +228,19 @@ def copy_files():
"name": "esphome nrf52", "name": "esphome nrf52",
"upload": { "upload": {
"maximum_ram_size": 248832, "maximum_ram_size": 248832,
"maximum_size": 815104 "maximum_size": 815104,
"speed": 115200
}, },
"url": "https://esphome.io/", "url": "https://esphome.io/",
"vendor": "esphome" "vendor": "esphome",
"build": {
"softdevice": {
"sd_fwid": "0x00B6"
}
}
} }
""" """
write_file_if_changed( write_file_if_changed(
CORE.relative_build_path(f"boards/{zephyr_data()[KEY_BOARD]}.json"), CORE.relative_build_path(f"boards/{zephyr_data()[KEY_BOARD]}.json"),
fake_board_manifest, fake_board_manifest,

View File

@@ -696,6 +696,7 @@ CONF_OPEN_DRAIN = "open_drain"
CONF_OPEN_DRAIN_INTERRUPT = "open_drain_interrupt" CONF_OPEN_DRAIN_INTERRUPT = "open_drain_interrupt"
CONF_OPEN_DURATION = "open_duration" CONF_OPEN_DURATION = "open_duration"
CONF_OPEN_ENDSTOP = "open_endstop" CONF_OPEN_ENDSTOP = "open_endstop"
CONF_OPENTHREAD = "openthread"
CONF_OPERATION = "operation" CONF_OPERATION = "operation"
CONF_OPTIMISTIC = "optimistic" CONF_OPTIMISTIC = "optimistic"
CONF_OPTION = "option" CONF_OPTION = "option"
@@ -1299,6 +1300,7 @@ DEVICE_CLASS_SULPHUR_DIOXIDE = "sulphur_dioxide"
DEVICE_CLASS_SWITCH = "switch" DEVICE_CLASS_SWITCH = "switch"
DEVICE_CLASS_TAMPER = "tamper" DEVICE_CLASS_TAMPER = "tamper"
DEVICE_CLASS_TEMPERATURE = "temperature" DEVICE_CLASS_TEMPERATURE = "temperature"
DEVICE_CLASS_TEMPERATURE_DELTA = "temperature_delta"
DEVICE_CLASS_TIMESTAMP = "timestamp" DEVICE_CLASS_TIMESTAMP = "timestamp"
DEVICE_CLASS_UPDATE = "update" DEVICE_CLASS_UPDATE = "update"
DEVICE_CLASS_VIBRATION = "vibration" DEVICE_CLASS_VIBRATION = "vibration"

View File

@@ -10,6 +10,10 @@ from esphome.helpers import get_bool_env
from .util.password import password_hash from .util.password import password_hash
# Sentinel file name used for CORE.config_path when dashboard initializes.
# This ensures .parent returns the config directory instead of root.
_DASHBOARD_SENTINEL_FILE = "___DASHBOARD_SENTINEL___.yaml"
class DashboardSettings: class DashboardSettings:
"""Settings for the dashboard.""" """Settings for the dashboard."""
@@ -48,7 +52,12 @@ class DashboardSettings:
self.config_dir = Path(args.configuration) self.config_dir = Path(args.configuration)
self.absolute_config_dir = self.config_dir.resolve() self.absolute_config_dir = self.config_dir.resolve()
self.verbose = args.verbose self.verbose = args.verbose
CORE.config_path = self.config_dir / "." # Set to a sentinel file so .parent gives us the config directory.
# Previously this was `os.path.join(self.config_dir, ".")` which worked because
# os.path.dirname("/config/.") returns "/config", but Path("/config/.").parent
# normalizes to Path("/config") first, then .parent returns Path("/"), breaking
# secret resolution. Using a sentinel file ensures .parent gives the correct directory.
CORE.config_path = self.config_dir / _DASHBOARD_SENTINEL_FILE
@property @property
def relative_url(self) -> str: def relative_url(self) -> str:

View File

@@ -1,6 +1,6 @@
pylint==4.0.1 pylint==4.0.1
flake8==7.3.0 # also change in .pre-commit-config.yaml when updating flake8==7.3.0 # also change in .pre-commit-config.yaml when updating
ruff==0.14.0 # also change in .pre-commit-config.yaml when updating ruff==0.14.1 # also change in .pre-commit-config.yaml when updating
pyupgrade==3.21.0 # also change in .pre-commit-config.yaml when updating pyupgrade==3.21.0 # also change in .pre-commit-config.yaml when updating
pre-commit pre-commit

View File

@@ -50,7 +50,14 @@ PACKAGE_DEPENDENCIES = {
# Bus types that can be defined directly in config files # Bus types that can be defined directly in config files
# Components defining these directly cannot be grouped (they create unique bus IDs) # Components defining these directly cannot be grouped (they create unique bus IDs)
DIRECT_BUS_TYPES = ("i2c", "spi", "uart", "modbus") DIRECT_BUS_TYPES = (
"i2c",
"spi",
"uart",
"modbus",
"remote_transmitter",
"remote_receiver",
)
# Signature for components with no bus requirements # Signature for components with no bus requirements
# These components can be merged with any other group # These components can be merged with any other group
@@ -68,6 +75,8 @@ BASE_BUS_COMPONENTS = {
"uart", "uart",
"modbus", "modbus",
"canbus", "canbus",
"remote_transmitter",
"remote_receiver",
} }
# Components that must be tested in isolation (not grouped or batched with others) # Components that must be tested in isolation (not grouped or batched with others)
@@ -83,8 +92,6 @@ ISOLATED_COMPONENTS = {
"openthread": "Conflicts with wifi: used by most components", "openthread": "Conflicts with wifi: used by most components",
"openthread_info": "Conflicts with wifi: used by most components", "openthread_info": "Conflicts with wifi: used by most components",
"matrix_keypad": "Needs isolation due to keypad", "matrix_keypad": "Needs isolation due to keypad",
"mcp4725": "no YAML config to specify i2c bus id",
"mcp47a1": "no YAML config to specify i2c bus id",
"modbus_controller": "Defines multiple modbus buses for testing client/server functionality - conflicts with package modbus bus", "modbus_controller": "Defines multiple modbus buses for testing client/server functionality - conflicts with package modbus bus",
"neopixelbus": "RMT type conflict with ESP32 Arduino/ESP-IDF headers (enum vs struct rmt_channel_t)", "neopixelbus": "RMT type conflict with ESP32 Arduino/ESP-IDF headers (enum vs struct rmt_channel_t)",
"packages": "cannot merge packages", "packages": "cannot merge packages",

View File

@@ -99,7 +99,8 @@ def find_component_tests(
if not comp_dir.is_dir(): if not comp_dir.is_dir():
continue continue
for test_file in comp_dir.glob("test.*.yaml"): # Find test files matching test.*.yaml or test-*.yaml patterns
for test_file in comp_dir.glob("test[.-]*.yaml"):
component_tests[comp_dir.name].append(test_file) component_tests[comp_dir.name].append(test_file)
return dict(component_tests) return dict(component_tests)

View File

@@ -1,7 +1,3 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: heatpumpir - platform: heatpumpir
protocol: ballu protocol: ballu
@@ -10,3 +6,4 @@ climate:
name: HeatpumpIR Climate name: HeatpumpIR Climate
min_temperature: 18 min_temperature: 18
max_temperature: 30 max_temperature: 30
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -0,0 +1,6 @@
sensor:
- platform: bh1900nux
i2c_id: i2c_bus
name: Temperature Living Room
address: 0x48
update_interval: 30s

View File

@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp32-c3-idf.yaml
<<: !include common.yaml

View File

@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp32-idf.yaml
<<: !include common.yaml

View File

@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
<<: !include common.yaml

View File

@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/rp2040-ard.yaml
<<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: climate_ir_lg - platform: climate_ir_lg
name: LG Climate name: LG Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: coolix - platform: coolix
name: Coolix Climate name: Coolix Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,3 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: heatpumpir - platform: heatpumpir
protocol: daikin protocol: daikin
@@ -10,3 +6,4 @@ climate:
name: HeatpumpIR Climate name: HeatpumpIR Climate
min_temperature: 18 min_temperature: 18
max_temperature: 30 max_temperature: 30
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,18 +1,3 @@
remote_transmitter:
pin: ${tx_pin}
carrier_duty_percent: 50%
id: tsvr
remote_receiver:
id: rcvr
pin:
number: ${rx_pin}
inverted: true
mode:
input: true
pullup: true
tolerance: 40%
climate: climate:
- platform: daikin_arc - platform: daikin_arc
name: Daikin AC name: Daikin AC

View File

@@ -1,5 +1,5 @@
substitutions: packages:
tx_pin: GPIO0 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
rx_pin: GPIO2 remote_receiver: !include ../../test_build_components/common/remote_receiver/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: daikin_brc - platform: daikin_brc
name: Daikin_brc Climate name: Daikin_brc Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: delonghi - platform: delonghi
name: Delonghi Climate name: Delonghi Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,14 +1,5 @@
remote_transmitter:
id: tx
pin: ${remote_transmitter_pin}
carrier_duty_percent: 100%
remote_receiver:
id: rcvr
pin: ${remote_receiver_pin}
climate: climate:
- platform: emmeti - platform: emmeti
name: Emmeti name: Emmeti
receiver_id: rcvr receiver_id: rcvr
transmitter_id: tx transmitter_id: xmitr

View File

@@ -1,5 +1,5 @@
substitutions: packages:
remote_transmitter_pin: GPIO33 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
remote_receiver_pin: GPIO32 remote_receiver: !include ../../test_build_components/common/remote_receiver/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,5 +1,5 @@
substitutions: packages:
remote_transmitter_pin: GPIO0 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
remote_receiver_pin: GPIO2 remote_receiver: !include ../../test_build_components/common/remote_receiver/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: fujitsu_general - platform: fujitsu_general
name: Fujitsu General Climate name: Fujitsu General Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,8 +1,5 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: gree - platform: gree
name: GREE name: GREE
model: generic model: generic
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,3 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: heatpumpir - platform: heatpumpir
protocol: mitsubishi_heavy_zm protocol: mitsubishi_heavy_zm
@@ -10,6 +6,7 @@ climate:
name: HeatpumpIR Climate Mitsubishi name: HeatpumpIR Climate Mitsubishi
min_temperature: 18 min_temperature: 18
max_temperature: 30 max_temperature: 30
transmitter_id: xmitr
- platform: heatpumpir - platform: heatpumpir
protocol: daikin protocol: daikin
horizontal_default: mleft horizontal_default: mleft
@@ -17,6 +14,7 @@ climate:
name: HeatpumpIR Climate Daikin name: HeatpumpIR Climate Daikin
min_temperature: 18 min_temperature: 18
max_temperature: 30 max_temperature: 30
transmitter_id: xmitr
- platform: heatpumpir - platform: heatpumpir
protocol: panasonic_altdke protocol: panasonic_altdke
horizontal_default: mright horizontal_default: mright
@@ -24,3 +22,4 @@ climate:
name: HeatpumpIR Climate Panasonic name: HeatpumpIR Climate Panasonic
min_temperature: 18 min_temperature: 18
max_temperature: 30 max_temperature: 30
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO6 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/bk72xx-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: hitachi_ac344 - platform: hitachi_ac344
name: Hitachi Climate name: Hitachi Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO6 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/bk72xx-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: hitachi_ac424 - platform: hitachi_ac424
name: Hitachi Climate name: Hitachi Climate
transmitter_id: xmitr

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO6 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/bk72xx-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO2 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,4 +1,4 @@
substitutions: packages:
pin: GPIO5 remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -7,6 +7,7 @@ sensor:
max_current: 40 A max_current: 40 A
adc_range: 1 adc_range: 1
temperature_coefficient: 50 temperature_coefficient: 50
reset_on_boot: true
shunt_voltage: shunt_voltage:
id: ina2xx_i2c_shunt_voltage id: ina2xx_i2c_shunt_voltage
name: "INA2xx Shunt Voltage" name: "INA2xx Shunt Voltage"

View File

@@ -1,3 +1,4 @@
output: output:
- platform: mcp4725 - platform: mcp4725
id: mcp4725_dac_output id: mcp4725_dac_output
i2c_id: i2c_bus

View File

@@ -1,3 +1,4 @@
output: output:
- platform: mcp47a1 - platform: mcp47a1
id: output_mcp47a1 id: output_mcp47a1
i2c_id: i2c_bus

View File

@@ -2,10 +2,6 @@ wifi:
ssid: MySSID ssid: MySSID
password: password1 password: password1
remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
climate: climate:
- platform: midea - platform: midea
id: midea_unit id: midea_unit
@@ -16,7 +12,7 @@ climate:
x.set_mode(CLIMATE_MODE_FAN_ONLY); x.set_mode(CLIMATE_MODE_FAN_ONLY);
on_state: on_state:
- logger.log: State changed! - logger.log: State changed!
transmitter_id: transmitter_id: xmitr
period: 1s period: 1s
num_attempts: 5 num_attempts: 5
timeout: 2s timeout: 2s

View File

@@ -1,7 +1,5 @@
substitutions:
pin: GPIO2
packages: packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-ard.yaml
uart: !include ../../test_build_components/common/uart/esp32-ard.yaml uart: !include ../../test_build_components/common/uart/esp32-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,5 @@
substitutions:
pin: GPIO15
packages: packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,8 +1,5 @@
remote_transmitter:
pin: 4
carrier_duty_percent: 50%
climate: climate:
- platform: midea_ir - platform: midea_ir
name: Midea IR name: Midea IR
use_fahrenheit: true use_fahrenheit: true
transmitter_id: xmitr

View File

@@ -1 +1,4 @@
packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1 +1,4 @@
packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1 +1,4 @@
packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1,7 +1,4 @@
remote_transmitter:
pin: 4
carrier_duty_percent: 50%
climate: climate:
- platform: mitsubishi - platform: mitsubishi
name: Mitsubishi name: Mitsubishi
transmitter_id: xmitr

View File

@@ -1 +1,4 @@
packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1 +1,4 @@
packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml
<<: !include common.yaml <<: !include common.yaml

View File

@@ -1 +1,4 @@
packages:
remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml
<<: !include common.yaml <<: !include common.yaml

Some files were not shown because too many files have changed in this diff Show More