@@ -2272,67 +2272,96 @@ void NSPanelLovelace::call_ha_service_(
22722272 const std::string &service,
22732273 const std::map<std::string, std::string> &data,
22742274 const std::map<std::string, std::string> &data_template) {
2275- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,10,0)
2276- api::HomeassistantActionRequest resp;
2277- #else
2278- api::HomeassistantServiceResponse resp;
2279- #endif
2280- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,8,0)
2281- resp.set_service (esphome::StringRef (service));
2282- #else
2283- resp.service = service;
2284- #endif
2275+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,10,0)
2276+ api::HomeassistantActionRequest resp;
2277+ #else
2278+ api::HomeassistantServiceResponse resp;
2279+ #endif
2280+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2281+ resp.service = esphome::StringRef (service);
2282+ #elif ESPHOME_VERSION_CODE >= VERSION_CODE(2025,8,0)
2283+ resp.set_service (esphome::StringRef (service));
2284+ #else
2285+ resp.service = service;
2286+ #endif
22852287
2286- #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
2287- auto it = data.find (to_string (ha_attr_type::entity_id));
2288- if (it == data.end ())
2289- ESP_LOGD (TAG, " Call HA: %s -> %s" , service.c_str (), it->second .c_str ());
2290- else
2291- ESP_LOGD (TAG, " Call HA: %s" , service.c_str ());
2292- #endif
2288+ #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
2289+ auto it = data.find (to_string (ha_attr_type::entity_id));
2290+ if (it == data.end ())
2291+ ESP_LOGD (TAG, " Call HA: %s -> %s" , service.c_str (), it->second .c_str ());
2292+ else
2293+ ESP_LOGD (TAG, " Call HA: %s" , service.c_str ());
2294+ #endif
22932295
2294- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,11,0)
2295- resp.data .init (data.size ());
2296- #endif
2296+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,11,0)
2297+ resp.data .init (data.size ());
2298+ #endif
22972299 for (auto &it : data) {
22982300 api::HomeassistantServiceMap kv;
2299- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,8,0)
2300- kv.set_key (esphome::StringRef (it.first ));
2301- #else
2302- kv.key = it.first ;
2303- #endif
2301+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2302+ kv.key = esphome::StringRef (it.first );
2303+ #elif ESPHOME_VERSION_CODE >= VERSION_CODE(2025,8,0)
2304+ kv.set_key (esphome::StringRef (it.first ));
2305+ #else
2306+ kv.key = it.first ;
2307+ #endif
2308+
2309+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2310+ kv.value = esphome::StringRef (it.second );
2311+ #else
23042312 kv.value = it.second ;
2313+ #endif
23052314 resp.data .push_back (kv);
23062315 }
23072316
2308- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,11,0)
2309- resp.data_template .init (data_template.size ());
2310- #endif
2317+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,11,0)
2318+ resp.data_template .init (data_template.size ());
2319+ #endif
23112320 for (auto &it : data_template) {
23122321 api::HomeassistantServiceMap kv;
2313- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,8,0)
2314- kv.set_key (esphome::StringRef (it.first ));
2315- #else
2316- kv.key = it.first ;
2317- #endif
2322+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2323+ kv.key = esphome::StringRef (it.first );
2324+ #elif ESPHOME_VERSION_CODE >= VERSION_CODE(2025,8,0)
2325+ kv.set_key (esphome::StringRef (it.first ));
2326+ #else
2327+ kv.key = it.first ;
2328+ #endif
2329+
2330+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2331+ kv.value = esphome::StringRef (it.second );
2332+ #else
23182333 kv.value = it.second ;
2334+ #endif
23192335 resp.data_template .push_back (kv);
23202336 }
23212337
2322- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,10,0)
2338+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025,10,0)
23232339 api::global_api_server->send_homeassistant_action (resp);
2324- #else
2340+ #else
23252341 api::global_api_server->send_homeassistant_service_call (resp);
2326- #endif
2342+ #endif
23272343}
23282344
2329- void NSPanelLovelace::on_entity_state_update_ (std::string entity_id, std::string state) {
2345+ void NSPanelLovelace::on_entity_state_update_ (
2346+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2347+ const std::string &entity_id, esphome::StringRef state
2348+ #else
2349+ std::string entity_id, std::string state
2350+ #endif
2351+ ) {
23302352 this ->on_entity_attribute_update_ (entity_id, to_string (ha_attr_type::state), state);
23312353}
2332- void NSPanelLovelace::on_entity_attribute_update_ (std::string entity_id, std::string attr, std::string attr_value) {
2354+
2355+ void NSPanelLovelace::on_entity_attribute_update_ (
2356+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2357+ const std::string &entity_id, const std::string &attr_name, esphome::StringRef attr_value
2358+ #else
2359+ std::string entity_id, std::string attr_name, std::string attr_value
2360+ #endif
2361+ ) {
23332362 auto entity = this ->get_entity_ (entity_id);
23342363 if (entity == nullptr ) return ;
2335- auto ha_attr = to_ha_attr (attr );
2364+ auto ha_attr = to_ha_attr (attr_name );
23362365 if (ha_attr == ha_attr_type::unknown) return ;
23372366
23382367 if (ha_attr == ha_attr_type::state) {
@@ -2342,7 +2371,7 @@ void NSPanelLovelace::on_entity_attribute_update_(std::string entity_id, std::st
23422371 }
23432372
23442373 ESP_LOGD (TAG, " HA update: %s %s='%s'" ,
2345- entity_id.c_str (), attr .c_str (),
2374+ entity_id.c_str (), attr_name .c_str (),
23462375 ha_attr == ha_attr_type::state
23472376 ? entity->get_state ().c_str ()
23482377 : entity->get_attribute (ha_attr).c_str ());
@@ -2352,7 +2381,7 @@ void NSPanelLovelace::on_entity_attribute_update_(std::string entity_id, std::st
23522381 // If there are lots of entity attributes that update within a short time
23532382 // then this will queue lots of commands unnecessarily.
23542383 // This re-schedules updates every time one happens within a 200ms period.
2355- this ->set_timeout (entity_id , 200 , [this , entity_id] () {
2384+ this ->set_timeout (entity-> get_entity_id (). c_str () , 200 , [this , entity_id] () {
23562385 if (this ->force_current_page_update_ ) return ;
23572386 auto page = this ->page_mgr_ .current_page ();
23582387 if (!page) return ;
@@ -2412,32 +2441,56 @@ void NSPanelLovelace::send_weather_update_command_() {
24122441 this ->send_buffered_command_ ();
24132442}
24142443
2415- void NSPanelLovelace::on_weather_state_update_ (std::string entity_id, std::string state) {
2444+ void NSPanelLovelace::on_weather_state_update_ (
2445+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2446+ const std::string &entity_id, esphome::StringRef state
2447+ #else
2448+ std::string entity_id, std::string state
2449+ #endif
2450+ ) {
24162451 if (this ->screensaver_ == nullptr ) return ;
24172452 auto item = this ->screensaver_ ->get_item <WeatherItem>(0 );
24182453 if (item == nullptr ) return ;
24192454 item->set_icon_by_weather_condition (state);
24202455 this ->send_weather_update_command_ ();
24212456}
24222457
2423- void NSPanelLovelace::on_weather_temperature_update_ (std::string entity_id, std::string temperature) {
2458+ void NSPanelLovelace::on_weather_temperature_update_ (
2459+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2460+ const std::string &entity_id, esphome::StringRef temperature
2461+ #else
2462+ std::string entity_id, std::string temperature
2463+ #endif
2464+ ) {
24242465 if (this ->screensaver_ == nullptr ) return ;
24252466 auto item = this ->screensaver_ ->get_item <WeatherItem>(0 );
24262467 if (item == nullptr ) return ;
2427- item->set_value (std::move ( temperature) );
2468+ item->set_value (temperature);
24282469 this ->send_weather_update_command_ ();
24292470}
24302471
2431- void NSPanelLovelace::on_weather_temperature_unit_update_ (std::string entity_id, std::string temperature_unit) {
2472+ void NSPanelLovelace::on_weather_temperature_unit_update_ (
2473+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2474+ const std::string &entity_id, esphome::StringRef temperature_unit
2475+ #else
2476+ std::string entity_id, std::string temperature_unit
2477+ #endif
2478+ ) {
24322479 if (this ->screensaver_ == nullptr ) return ;
2433- WeatherItem::temperature_unit = std::move ( temperature_unit) ;
2480+ WeatherItem::temperature_unit = temperature_unit;
24342481 this ->screensaver_ ->set_items_render_invalid ();
24352482 this ->send_weather_update_command_ ();
24362483}
24372484
2438- void NSPanelLovelace::on_weather_forecast_update_ (std::string entity_id, std::string forecast_json) {
2485+ void NSPanelLovelace::on_weather_forecast_update_ (
2486+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2026,1,0)
2487+ const std::string &entity_id, esphome::StringRef forecast_json
2488+ #else
2489+ std::string entity_id, std::string forecast_json
2490+ #endif
2491+ ) {
24392492 ESP_LOGV (TAG, " Weather forecast update (%u): %zu %s" ,
2440- this ->screensaver_ == nullptr , forecast_json.length (), forecast_json.c_str ());
2493+ this ->screensaver_ == nullptr , forecast_json.size (), forecast_json.c_str ());
24412494 if (this ->screensaver_ == nullptr ) return ;
24422495 // todo: check if we are on the screensaver otherwise don't update
24432496 // todo: implement color updates: "color~background~tTime~timeAMPM~tDate~tMainText~tForecast1~tForecast2~tForecast3~tForecast4~tForecast1Val~tForecast2Val~tForecast3Val~tForecast4Val~bar~tMainTextAlt2~tTimeAdd"
@@ -2465,12 +2518,12 @@ void NSPanelLovelace::on_weather_forecast_update_(std::string entity_id, std::st
24652518 BasicJsonDocument<SpiRamAllocator> doc (psram_available () ? 7680 : 6144 );
24662519#endif
24672520 ArduinoJson::DeserializationError error = ArduinoJson::deserializeJson (
2468- doc, forecast_json, DeserializationOption::Filter (filter));
2521+ doc, forecast_json. c_str () , DeserializationOption::Filter (filter));
24692522 App.feed_wdt ();
24702523
24712524 if (error || doc.overflowed ()) {
24722525 ESP_LOGW (TAG, " Weather unparsable: %s %zu '%s'" , error ? error.c_str () : " doc overflow" ,
2473- forecast_json.length (), forecast_json.c_str ());
2526+ forecast_json.size (), forecast_json.c_str ());
24742527 return ;
24752528 }
24762529
0 commit comments