geoffdavis / esphome-mitsubishiheatpump

ESPHome Climate Component for Mitsubishi Heatpumps using direct serial connection
BSD 2-Clause "Simplified" License
498 stars 143 forks source link

ESPHome Compile Error: "'optional' in namespace 'std' does not name a template type" #117

Closed johndbritton closed 8 months ago

johndbritton commented 8 months ago

I've been using this external component and everything has been working great up until I updated Home Assistant and ESPHome recently.

Since the update, compiling any ESPHome configurations that included this external component has failed with multiple errors like the following:

Compiling .pioenvs/studio-heat-pump/src/esphome/components/ota/ota_backend_arduino_esp32.cpp.o
In file included from src/esphome.h:24,
                 from src/esphome/components/mitsubishi_heatpump/espmhp.h:20,
                 from src/esphome/components/mitsubishi_heatpump/espmhp.cpp:21:
src/esphome/components/mitsubishi_heatpump/espmhp.h:163:14: error: 'optional' in namespace 'std' does not name a template type
         std::optional<std::chrono::duration<long long, std::ratio<60>>> remote_operating_timeout_;
              ^~~~~~~~
src/esphome/components/mitsubishi_heatpump/espmhp.h:163:9: note: 'std::optional' is only available from C++17 onwards
         std::optional<std::chrono::duration<long long, std::ratio<60>>> remote_operating_timeout_;
         ^~~

Followed by a bunch of error: '<VARIABLE>' was not declared in this scope messages.

I'm not exactly sure what change caused this, but I was able to resolve it by switching to C++17. In my ESPHome configuration I added the following:

esphome:
  platformio_options:
    build_unflags:
      - "-std=gnu++11"
    build_flags:
      - "-std=gnu++17"

This disables the std=gnu++11 flag and enables the std=gnu++17 flag in PlatformIO.

johndbritton commented 8 months ago

Closing this as I've resolved my own problem, just posting here for folks who are searching for this answer.