From b264c6caaca2ec80b2e343721e286a10807f077f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 7 Nov 2025 18:16:22 -0600 Subject: [PATCH 1/6] cleanup defines --- .../components/alarm_control_panel/alarm_control_panel.cpp | 7 ++++--- esphome/components/cover/cover.cpp | 4 +++- esphome/components/light/light_state.cpp | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/esphome/components/alarm_control_panel/alarm_control_panel.cpp b/esphome/components/alarm_control_panel/alarm_control_panel.cpp index febd00f2c5..c29e02c8ef 100644 --- a/esphome/components/alarm_control_panel/alarm_control_panel.cpp +++ b/esphome/components/alarm_control_panel/alarm_control_panel.cpp @@ -1,8 +1,9 @@ -#include -#include "esphome/core/defines.h" - #include "alarm_control_panel.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" + +#include + #include "esphome/core/application.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" diff --git a/esphome/components/cover/cover.cpp b/esphome/components/cover/cover.cpp index ab800a8749..3062dba28a 100644 --- a/esphome/components/cover/cover.cpp +++ b/esphome/components/cover/cover.cpp @@ -1,7 +1,9 @@ #include "cover.h" #include "esphome/core/defines.h" -#include #include "esphome/core/controller_registry.h" + +#include + #include "esphome/core/log.h" namespace esphome { diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index 5bb9087c5b..4c253ec5a8 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -1,9 +1,8 @@ +#include "light_state.h" #include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" - #include "light_output.h" -#include "light_state.h" #include "transformers.h" namespace esphome { From 7e96f10a79b3cd573ffcf7a4790c634eed7af582 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 8 Nov 2025 08:39:23 -0600 Subject: [PATCH 2/6] dry --- esphome/core/controller_registry.cpp | 120 +++++++-------------------- 1 file changed, 30 insertions(+), 90 deletions(-) diff --git a/esphome/core/controller_registry.cpp b/esphome/core/controller_registry.cpp index b22ec487d5..993a0dc241 100644 --- a/esphome/core/controller_registry.cpp +++ b/esphome/core/controller_registry.cpp @@ -10,151 +10,88 @@ StaticVector ControllerRegistry::controll void ControllerRegistry::register_controller(Controller *controller) { controllers.push_back(controller); } -#ifdef USE_BINARY_SENSOR -void ControllerRegistry::notify_binary_sensor_update(binary_sensor::BinarySensor *obj) { - for (auto *controller : controllers) { - controller->on_binary_sensor_update(obj); +// Macro for registry notification dispatch - iterates registered controllers and calls their handler +#define CONTROLLER_REGISTRY_NOTIFY(entity_type, entity_name) \ + void ControllerRegistry::notify_##entity_name##_update(entity_type *obj) { /* NOLINT(bugprone-macro-parentheses) */ \ + for (auto *controller : controllers) { \ + controller->on_##entity_name##_update(obj); \ + } \ } -} + +#ifdef USE_BINARY_SENSOR +CONTROLLER_REGISTRY_NOTIFY(binary_sensor::BinarySensor, binary_sensor) #endif #ifdef USE_FAN -void ControllerRegistry::notify_fan_update(fan::Fan *obj) { - for (auto *controller : controllers) { - controller->on_fan_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(fan::Fan, fan) #endif #ifdef USE_LIGHT -void ControllerRegistry::notify_light_update(light::LightState *obj) { - for (auto *controller : controllers) { - controller->on_light_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(light::LightState, light) #endif #ifdef USE_SENSOR -void ControllerRegistry::notify_sensor_update(sensor::Sensor *obj) { - for (auto *controller : controllers) { - controller->on_sensor_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(sensor::Sensor, sensor) #endif #ifdef USE_SWITCH -void ControllerRegistry::notify_switch_update(switch_::Switch *obj) { - for (auto *controller : controllers) { - controller->on_switch_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(switch_::Switch, switch) #endif #ifdef USE_COVER -void ControllerRegistry::notify_cover_update(cover::Cover *obj) { - for (auto *controller : controllers) { - controller->on_cover_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(cover::Cover, cover) #endif #ifdef USE_TEXT_SENSOR -void ControllerRegistry::notify_text_sensor_update(text_sensor::TextSensor *obj) { - for (auto *controller : controllers) { - controller->on_text_sensor_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(text_sensor::TextSensor, text_sensor) #endif #ifdef USE_CLIMATE -void ControllerRegistry::notify_climate_update(climate::Climate *obj) { - for (auto *controller : controllers) { - controller->on_climate_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(climate::Climate, climate) #endif #ifdef USE_NUMBER -void ControllerRegistry::notify_number_update(number::Number *obj) { - for (auto *controller : controllers) { - controller->on_number_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(number::Number, number) #endif #ifdef USE_DATETIME_DATE -void ControllerRegistry::notify_date_update(datetime::DateEntity *obj) { - for (auto *controller : controllers) { - controller->on_date_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(datetime::DateEntity, date) #endif #ifdef USE_DATETIME_TIME -void ControllerRegistry::notify_time_update(datetime::TimeEntity *obj) { - for (auto *controller : controllers) { - controller->on_time_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(datetime::TimeEntity, time) #endif #ifdef USE_DATETIME_DATETIME -void ControllerRegistry::notify_datetime_update(datetime::DateTimeEntity *obj) { - for (auto *controller : controllers) { - controller->on_datetime_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(datetime::DateTimeEntity, datetime) #endif #ifdef USE_TEXT -void ControllerRegistry::notify_text_update(text::Text *obj) { - for (auto *controller : controllers) { - controller->on_text_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(text::Text, text) #endif #ifdef USE_SELECT -void ControllerRegistry::notify_select_update(select::Select *obj) { - for (auto *controller : controllers) { - controller->on_select_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(select::Select, select) #endif #ifdef USE_LOCK -void ControllerRegistry::notify_lock_update(lock::Lock *obj) { - for (auto *controller : controllers) { - controller->on_lock_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(lock::Lock, lock) #endif #ifdef USE_VALVE -void ControllerRegistry::notify_valve_update(valve::Valve *obj) { - for (auto *controller : controllers) { - controller->on_valve_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(valve::Valve, valve) #endif #ifdef USE_MEDIA_PLAYER -void ControllerRegistry::notify_media_player_update(media_player::MediaPlayer *obj) { - for (auto *controller : controllers) { - controller->on_media_player_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(media_player::MediaPlayer, media_player) #endif #ifdef USE_ALARM_CONTROL_PANEL -void ControllerRegistry::notify_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj) { - for (auto *controller : controllers) { - controller->on_alarm_control_panel_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY(alarm_control_panel::AlarmControlPanel, alarm_control_panel) #endif #ifdef USE_EVENT +// Event is a special case - notify_event() calls on_event() (no "_update" suffix) void ControllerRegistry::notify_event(event::Event *obj) { for (auto *controller : controllers) { controller->on_event(obj); @@ -163,6 +100,7 @@ void ControllerRegistry::notify_event(event::Event *obj) { #endif #ifdef USE_UPDATE +// Update is a special case - notify_update() calls on_update() (no "_update" suffix) void ControllerRegistry::notify_update(update::UpdateEntity *obj) { for (auto *controller : controllers) { controller->on_update(obj); @@ -170,6 +108,8 @@ void ControllerRegistry::notify_update(update::UpdateEntity *obj) { } #endif +#undef CONTROLLER_REGISTRY_NOTIFY + } // namespace esphome #endif // USE_CONTROLLER_REGISTRY From 62f43d3353ee2b399023e205b360310a281e215e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 8 Nov 2025 08:41:46 -0600 Subject: [PATCH 3/6] dry --- esphome/core/controller_registry.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/esphome/core/controller_registry.cpp b/esphome/core/controller_registry.cpp index 993a0dc241..0a84bb0d0d 100644 --- a/esphome/core/controller_registry.cpp +++ b/esphome/core/controller_registry.cpp @@ -10,7 +10,7 @@ StaticVector ControllerRegistry::controll void ControllerRegistry::register_controller(Controller *controller) { controllers.push_back(controller); } -// Macro for registry notification dispatch - iterates registered controllers and calls their handler +// Macro for standard registry notification dispatch - calls on__update() #define CONTROLLER_REGISTRY_NOTIFY(entity_type, entity_name) \ void ControllerRegistry::notify_##entity_name##_update(entity_type *obj) { /* NOLINT(bugprone-macro-parentheses) */ \ for (auto *controller : controllers) { \ @@ -18,6 +18,14 @@ void ControllerRegistry::register_controller(Controller *controller) { controlle } \ } +// Macro for entities where controller method has no "_update" suffix (Event, Update) +#define CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(entity_type, entity_name) \ + void ControllerRegistry::notify_##entity_name(entity_type *obj) { /* NOLINT(bugprone-macro-parentheses) */ \ + for (auto *controller : controllers) { \ + controller->on_##entity_name(obj); \ + } \ + } + #ifdef USE_BINARY_SENSOR CONTROLLER_REGISTRY_NOTIFY(binary_sensor::BinarySensor, binary_sensor) #endif @@ -91,24 +99,15 @@ CONTROLLER_REGISTRY_NOTIFY(alarm_control_panel::AlarmControlPanel, alarm_control #endif #ifdef USE_EVENT -// Event is a special case - notify_event() calls on_event() (no "_update" suffix) -void ControllerRegistry::notify_event(event::Event *obj) { - for (auto *controller : controllers) { - controller->on_event(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(event::Event, event) #endif #ifdef USE_UPDATE -// Update is a special case - notify_update() calls on_update() (no "_update" suffix) -void ControllerRegistry::notify_update(update::UpdateEntity *obj) { - for (auto *controller : controllers) { - controller->on_update(obj); - } -} +CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(update::UpdateEntity, update) #endif #undef CONTROLLER_REGISTRY_NOTIFY +#undef CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX } // namespace esphome From f55c87218075a63bdf39629a38aa34cab3443e40 Mon Sep 17 00:00:00 2001 From: optimusprimespace <62800678+optimusprimespace@users.noreply.github.com> Date: Sat, 8 Nov 2025 22:56:51 +0200 Subject: [PATCH 4/6] Updated AQI calculation for HM3301 to the new standard (#9442) Co-authored-by: J. Nick Koston --- esphome/components/hm3301/aqi_calculator.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/esphome/components/hm3301/aqi_calculator.h b/esphome/components/hm3301/aqi_calculator.h index c1b47826a2..aa01060d2c 100644 --- a/esphome/components/hm3301/aqi_calculator.h +++ b/esphome/components/hm3301/aqi_calculator.h @@ -1,7 +1,7 @@ #pragma once - +#include #include "abstract_aqi_calculator.h" -// https://www.airnow.gov/sites/default/files/2020-05/aqi-technical-assistance-document-sept2018.pdf +// https://document.airnow.gov/technical-assistance-document-for-the-reporting-of-daily-air-quailty.pdf namespace esphome { namespace hm3301 { @@ -16,16 +16,15 @@ class AQICalculator : public AbstractAQICalculator { } protected: - static const int AMOUNT_OF_LEVELS = 7; + static const int AMOUNT_OF_LEVELS = 6; - int index_grid_[AMOUNT_OF_LEVELS][2] = {{0, 50}, {51, 100}, {101, 150}, {151, 200}, - {201, 300}, {301, 400}, {401, 500}}; + int index_grid_[AMOUNT_OF_LEVELS][2] = {{0, 50}, {51, 100}, {101, 150}, {151, 200}, {201, 300}, {301, 500}}; - int pm2_5_calculation_grid_[AMOUNT_OF_LEVELS][2] = {{0, 12}, {13, 35}, {36, 55}, {56, 150}, - {151, 250}, {251, 350}, {351, 500}}; + int pm2_5_calculation_grid_[AMOUNT_OF_LEVELS][2] = {{0, 9}, {10, 35}, {36, 55}, + {56, 125}, {126, 225}, {226, INT_MAX}}; - int pm10_0_calculation_grid_[AMOUNT_OF_LEVELS][2] = {{0, 54}, {55, 154}, {155, 254}, {255, 354}, - {355, 424}, {425, 504}, {505, 604}}; + int pm10_0_calculation_grid_[AMOUNT_OF_LEVELS][2] = {{0, 54}, {55, 154}, {155, 254}, + {255, 354}, {355, 424}, {425, INT_MAX}}; int calculate_index_(uint16_t value, int array[AMOUNT_OF_LEVELS][2]) { int grid_index = get_grid_index_(value, array); From b61027607f53f9344b924a5827f34e1513e44257 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Nov 2025 15:22:40 -0600 Subject: [PATCH 5/6] Bump aioesphomeapi from 42.6.0 to 42.7.0 (#11771) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 33fa2b64eb..40802422f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile esptool==5.1.0 click==8.1.7 esphome-dashboard==20251013.0 -aioesphomeapi==42.6.0 +aioesphomeapi==42.7.0 zeroconf==0.148.0 puremagic==1.30 ruamel.yaml==0.18.16 # dashboard_import From e7e091b48cecf5d68c7489f4e7294ecbb131a0b1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 8 Nov 2025 19:18:40 -0600 Subject: [PATCH 6/6] [core] Remove deprecated EntityBase::hash_base() method --- esphome/core/entity_base.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index 1486ff5360..2b52d66f76 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -129,9 +129,6 @@ class EntityBase { // Returns empty StringRef if object_id is dynamic (needs allocation) StringRef get_object_id_ref_for_api_() const; - /// The hash_base() function has been deprecated. It is kept in this - /// class for now, to prevent external components from not compiling. - virtual uint32_t hash_base() { return 0L; } void calc_object_id_(); /// Check if the object_id is dynamic (changes with MAC suffix)