esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Unable to call dfrobot_sen0395.settings from within a number template set_action call #5649

Open bakerkj opened 5 months ago

bakerkj commented 5 months ago

The problem

I am trying to use the relatively new dfrobot_sen0395 component. When I try to call dfrobot_sen0395.setting from within a number template set_action code generation completes, but the compiler fails to compile the generated code.

The set_action attemps to set the sensitivity to 5 for simplicity.

Which version of ESPHome has the issue?

2024.3.1

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.3.3

What platform are you using?

ESP32

Board

not relevant

Component causing the issue

dfrobot_sen0395

Example YAML snippet

esphome:
  name: test

esp32:
  board: esp32dev

uart:
  id: uart_bus
  tx_pin: GPIO13
  rx_pin: GPIO14
  baud_rate: 115200

dfrobot_sen0395:
  - id: mmwave_one
    uart_id: uart_bus

number:
  - platform: template
    name: sensitivity
    min_value: 0
    max_value: 9
    initial_value: 7
    step: 1
    set_action:
      - dfrobot_sen0395.settings:
          id: mmwave_one
          sensitivity: 5

Anything in the logs that might be useful for us?

This is the error I get when building...

(venv):~/esphome$ esphome run test.yaml                                                                                      
INFO ESPHome 2024.3.1                                                                                                                                     
INFO Reading configuration test.yaml...                                                                                                                   
INFO Generating C++ source...                                           
INFO Compiling app...                                                       
Processing test (board: esp32dev; framework: arduino; platform: platformio/espressif32@5.4.0)                                                                                                                                                                                                                        
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash                                                                                                              
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5                                                                                                           
No dependencies                                                                                                                                           
Compiling .pioenvs/test/src/esphome/components/dfrobot_sen0395/commands.cpp.o                                                       
Compiling .pioenvs/test/src/esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp.o                                                                      
Compiling .pioenvs/test/src/esphome/components/esp32/core.cpp.o           
Compiling .pioenvs/test/src/esphome/components/esp32/gpio.cpp.o                                                                                                                                                                                                                                                      
Compiling .pioenvs/test/src/esphome/components/esp32/preferences.cpp.o      
Compiling .pioenvs/test/src/esphome/components/number/automation.cpp.o
Compiling .pioenvs/test/src/esphome/components/number/number.cpp.o                                                                                                                                                                                                                                                   
Compiling .pioenvs/test/src/esphome/components/number/number_call.cpp.o                                                                                   
Compiling .pioenvs/test/src/esphome/components/number/number_traits.cpp.o                                                                                 
Compiling .pioenvs/test/src/esphome/components/template/number/template_number.cpp.o                                                                      
Compiling .pioenvs/test/src/esphome/components/uart/uart.cpp.o                                                                                            
Compiling .pioenvs/test/src/esphome/components/uart/uart_component.cpp.o                                                                                  
Compiling .pioenvs/test/src/esphome/components/uart/uart_component_esp32_arduino.cpp.o                
Compiling .pioenvs/test/src/esphome/components/uart/uart_component_esp8266.cpp.o                                                                                                                                                                                                                                     
Compiling .pioenvs/test/src/esphome/components/uart/uart_component_esp_idf.cpp.o
Compiling .pioenvs/test/src/esphome/components/uart/uart_component_libretiny.cpp.o                                                                        
Compiling .pioenvs/test/src/esphome/components/uart/uart_component_rp2040.cpp.o                                                                           
Compiling .pioenvs/test/src/esphome/components/uart/uart_debugger.cpp.o                                                                                   
Compiling .pioenvs/test/src/esphome/core/application.cpp.o                                                                                                
Compiling .pioenvs/test/src/esphome/core/color.cpp.o                                                                                                      
Compiling .pioenvs/test/src/esphome/core/component.cpp.o                  
Compiling .pioenvs/test/src/esphome/core/component_iterator.cpp.o                                                                                                                                                                                                                                                    
Compiling .pioenvs/test/src/esphome/core/controller.cpp.o                   
Compiling .pioenvs/test/src/esphome/core/entity_base.cpp.o
Compiling .pioenvs/test/src/esphome/core/helpers.cpp.o
Compiling .pioenvs/test/src/esphome/core/log.cpp.o
Compiling .pioenvs/test/src/esphome/core/ring_buffer.cpp.o
Compiling .pioenvs/test/src/esphome/core/scheduler.cpp.o
Compiling .pioenvs/test/src/esphome/core/string_ref.cpp.o
Compiling .pioenvs/test/src/esphome/core/time.cpp.o
Compiling .pioenvs/test/src/esphome/core/util.cpp.o
Compiling .pioenvs/test/src/main.cpp.o
Building .pioenvs/test/bootloader.bin
Generating partitions .pioenvs/test/partitions.bin
Creating esp32 image...
Successfully created esp32 image.
Compiling .pioenvs/test/FrameworkArduino/Esp.cpp.o
Compiling .pioenvs/test/FrameworkArduino/FirmwareMSC.cpp.o
Compiling .pioenvs/test/FrameworkArduino/FunctionalInterrupt.cpp.o
Compiling .pioenvs/test/FrameworkArduino/HWCDC.cpp.o
Compiling .pioenvs/test/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pioenvs/test/FrameworkArduino/IPAddress.cpp.o
Compiling .pioenvs/test/FrameworkArduino/IPv6Address.cpp.o
Compiling .pioenvs/test/FrameworkArduino/MD5Builder.cpp.o
Compiling .pioenvs/test/FrameworkArduino/Print.cpp.o
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h: In instantiation of 'void esphome::dfrobot_sen0395::DfrobotSen0395SettingsAction<Ts>::play(Ts ...) [with Ts = {float}]':
src/esphome/components/dfrobot_sen0395/automation.h:36:8:   required from here
src/esphome/components/dfrobot_sen0395/automation.h:42:35: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value()'
       if (this->det_min1_.value() >= 0 && this->det_max1_.value() >= 0) {                                                                                                                                                                                                                                           
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,                                                                                                                                                                                                                                         
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:37:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value(X ...) [with T = float; X = {float}]'
   T value(X... x) {
     ^~~~~
src/esphome/core/automation.h:37:5: note:   candidate expects 1 argument, 0 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:42:67: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value()'
       if (this->det_min1_.value() >= 0 && this->det_max1_.value() >= 0) {
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:37:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value(X ...) [with T = float; X = {float}]'
   T value(X... x) {
     ^~~~~
src/esphome/core/automation.h:37:5: note:   candidate expects 1 argument, 0 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(                                                                                                                                                                                                                                                     
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiling .pioenvs/test/FrameworkArduino/Stream.cpp.o
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
In file included from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/components/dfrobot_sen0395/automation.h:43:63: error: no matching function for call to 'esphome::TemplatableValue<float, float>::value_or(int)'
         this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
             this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/esphome/components/dfrobot_sen0395/automation.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/automation.h:52:5: note: candidate: 'T esphome::TemplatableValue<T, X>::value_or(X ..., T) [with T = float; X = {float}]'
   T value_or(X... x, T default_value) {
     ^~~~~~~~
src/esphome/core/automation.h:52:5: note:   candidate expects 2 arguments, 1 provided
Compiling .pioenvs/test/FrameworkArduino/StreamString.cpp.o
*** [.pioenvs/test/src/main.cpp.o] Error 1
============================================================================================================================================ [FAILED] Took 6.47 seconds ============================================================================================================================================

This is an extract of the main.cpp code which is failing:
  template__templatenumber = new template_::TemplateNumber();
  template__templatenumber->set_update_interval(60000);
  template__templatenumber->set_component_source("template.number");
  App.register_component(template__templatenumber);
  App.register_number(template__templatenumber);
  template__templatenumber->set_name("sensitivity");
  template__templatenumber->set_object_id("sensitivity");
  template__templatenumber->set_disabled_by_default(false);
  template__templatenumber->traits.set_min_value(0.0f);
  template__templatenumber->traits.set_max_value(9.0f);
  template__templatenumber->traits.set_step(1.0f);
  template__templatenumber->traits.set_mode(number::NUMBER_MODE_AUTO);
  template__templatenumber->set_optimistic(false);
  template__templatenumber->set_initial_value(7.0f);
  automation = new Automation<float>(template__templatenumber->get_set_trigger());
  dfrobot_sen0395_dfrobotsen0395settingsaction = new dfrobot_sen0395::DfrobotSen0395SettingsAction<float>();
  dfrobot_sen0395_dfrobotsen0395settingsaction->set_parent(mmwave_one);
  dfrobot_sen0395_dfrobotsen0395settingsaction->set_sensitivity(5);
  automation->add_actions({dfrobot_sen0395_dfrobotsen0395settingsaction});

Additional information

No response

probot-esphome[bot] commented 5 months ago

Hey there @niklasweber, mind taking a look at this issue as it has been labeled with an integration (dfrobot_sen0395) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

bakerkj commented 4 months ago

@niklasweber is there a chance you could help me with this?

Thanks!

niklasweber commented 4 months ago

Hi @bakerkj, thank you for posting the issue. This seems strange. It seems to be related to the number component. When I use the yaml config you provided, I get the same error. But it works when I call the settings action from a button component:

button:
  - platform: template
    name: sensitivity
    on_press:
      - dfrobot_sen0395.settings:
          id: mmwave_one
          sensitivity: 5

I'm not too familiar with esphome templates. Somehow when using the number component, the template has two float values, which is not compatible with the action I defined in the component. @jesserockz do you have an idea why the settings action works for the button component, but not for the number component? Do I need to define another class in automation.h?

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.