// Auto generated code by esphome
// ========== AUTO GENERATED INCLUDE BLOCK BEGIN ===========
#include "esphome.h"
using namespace esphome;
using namespace time;
using namespace text_sensor;
logger::Logger *logger_logger;
web_server_base::WebServerBase *web_server_base_webserverbase;
captive_portal::CaptivePortal *captive_portal_captiveportal;
wifi::WiFiComponent *wifi_wificomponent;
ota::OTAComponent *ota_otacomponent;
api::APIServer *api_apiserver;
using namespace api;
web_server::WebServer *web_server_webserver;
using namespace json;
sntp::SNTPComponent *esptime;
sun::Sun *sun_sun;
version::VersionTextSensor *version_versiontextsensor;
text_sensor::TextSensorStateTrigger *text_sensor_textsensorstatetrigger;
Automation<std::string> *automation_3;
template_::TemplateTextSensor *template__templatetextsensor;
template_::TemplateTextSensor *template__templatetextsensor_2;
template_::TemplateTextSensor *template__templatetextsensor_3;
LambdaAction<std::string> *lambdaaction_3;
sun::SunTrigger *sun_suntrigger;
Automation<> *automation;
LambdaAction<> *lambdaaction;
sun::SunTrigger *sun_suntrigger_2;
Automation<> *automation_2;
LambdaAction<> *lambdaaction_2;
#include "MySunTextSensor.h"
// ========== AUTO GENERATED INCLUDE BLOCK END ==========="

void setup() {
  // ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
  // ========== AUTO GENERATED CODE BEGIN ===========
  // async_tcp:
  // esphome:
  //   name: livingroom
  //   platform: ESP8266
  //   board: esp01_1m
  //   includes:
  //   - MySunTextSensor.h
  //   arduino_version: espressif8266@2.6.2
  //   build_path: livingroom
  //   platformio_options: {}
  //   esp8266_restore_from_flash: false
  //   board_flash_mode: dout
  //   libraries: []
  App.pre_setup("livingroom", __DATE__ ", " __TIME__);
  // time:
  // text_sensor:
  // logger:
  //   id: logger_logger
  //   baud_rate: 115200
  //   tx_buffer_size: 512
  //   hardware_uart: UART0
  //   level: DEBUG
  //   logs: {}
  //   esp8266_store_log_strings_in_flash: true
  logger_logger = new logger::Logger(115200, 512, logger::UART_SELECTION_UART0);
  logger_logger->pre_setup();
  App.register_component(logger_logger);
  // web_server_base:
  //   id: web_server_base_webserverbase
  web_server_base_webserverbase = new web_server_base::WebServerBase();
  App.register_component(web_server_base_webserverbase);
  // captive_portal:
  //   id: captive_portal_captiveportal
  //   web_server_base_id: web_server_base_webserverbase
  captive_portal_captiveportal = new captive_portal::CaptivePortal(web_server_base_webserverbase);
  App.register_component(captive_portal_captiveportal);
  // wifi:
  //   ap:
  //     ssid: Livingroom Fallback Hotspot
  //     password: R8ZKoXbtquSv
  //     id: wifi_wifiap
  //     ap_timeout: 1min
  //   id: wifi_wificomponent
  //   domain: .local
  //   reboot_timeout: 15min
  //   power_save_mode: NONE
  //   fast_connect: false
  //   output_power: 20.0
  //   networks:
  //   - ssid: WLAN-LX
  //     password: SP-RAXX749x7
  //     id: wifi_wifiap_2
  //     priority: 0.0
  //   use_address: livingroom.local
  wifi_wificomponent = new wifi::WiFiComponent();
  wifi_wificomponent->set_use_address("livingroom.local");
  wifi::WiFiAP wifi_wifiap_2 = wifi::WiFiAP();
  wifi_wifiap_2.set_ssid("WLAN-LX");
  wifi_wifiap_2.set_password("SP-RAXX749x7");
  wifi_wifiap_2.set_priority(0.0f);
  wifi_wificomponent->add_sta(wifi_wifiap_2);
  wifi::WiFiAP wifi_wifiap = wifi::WiFiAP();
  wifi_wifiap.set_ssid("Livingroom Fallback Hotspot");
  wifi_wifiap.set_password("R8ZKoXbtquSv");
  wifi_wificomponent->set_ap(wifi_wifiap);
  wifi_wificomponent->set_ap_timeout(60000);
  wifi_wificomponent->set_reboot_timeout(900000);
  wifi_wificomponent->set_power_save_mode(wifi::WIFI_POWER_SAVE_NONE);
  wifi_wificomponent->set_fast_connect(false);
  wifi_wificomponent->set_output_power(20.0f);
  App.register_component(wifi_wificomponent);
  // ota:
  //   id: ota_otacomponent
  //   safe_mode: true
  //   port: 8266
  //   password: ''
  //   reboot_timeout: 5min
  //   num_attempts: 10
  ota_otacomponent = new ota::OTAComponent();
  ota_otacomponent->set_port(8266);
  ota_otacomponent->set_auth_password("");
  App.register_component(ota_otacomponent);
  if (ota_otacomponent->should_enter_safe_mode(10, 300000)) return;
  // api:
  //   id: api_apiserver
  //   port: 6053
  //   password: ''
  //   reboot_timeout: 15min
  api_apiserver = new api::APIServer();
  App.register_component(api_apiserver);
  // web_server:
  //   port: 80
  //   id: web_server_webserver
  //   css_url: https:esphome.io/_static/webserver-v1.min.css
  //   js_url: https:esphome.io/_static/webserver-v1.min.js
  //   web_server_base_id: web_server_base_webserverbase
  api_apiserver->set_port(6053);
  api_apiserver->set_password("");
  api_apiserver->set_reboot_timeout(900000);
  web_server_webserver = new web_server::WebServer(web_server_base_webserverbase);
  App.register_component(web_server_webserver);
  web_server_base_webserverbase->set_port(80);
  web_server_webserver->set_css_url("https://esphome.io/_static/webserver-v1.min.css");
  web_server_webserver->set_js_url("https://esphome.io/_static/webserver-v1.min.js");
  // json:
  // time.sntp:
  //   platform: sntp
  //   timezone: CET-1CEST-2,M3.4.0/2,M10.5.0/3
  //   id: esptime
  //   servers:
  //   - 192.168.1.1
  //   - 1.de.pool.ntp.org
  //   - 2.de.pool.ntp.org
  //   update_interval: 15min
  esptime = new sntp::SNTPComponent();
  esptime->set_servers("192.168.1.1", "1.de.pool.ntp.org", "2.de.pool.ntp.org");
  esptime->set_update_interval(900000);
  App.register_component(esptime);
  // sun:
  //   latitude: 48.764401694750994
  //   longitude: 8.342827325621384
  //   on_sunrise:
  //   - then:
  //     - logger.log:
  //         format: Good morning!
  //         args: []
  //         level: DEBUG
  //         tag: main
  //       type_id: lambdaaction
  //     automation_id: automation
  //     trigger_id: sun_suntrigger
  //     elevation: -0.883
  //   on_sunset:
  //   - then:
  //     - logger.log:
  //         format: Good evening!
  //         args: []
  //         level: DEBUG
  //         tag: main
  //       type_id: lambdaaction_2
  //     automation_id: automation_2
  //     trigger_id: sun_suntrigger_2
  //     elevation: -0.883
  //   id: sun_sun
  //   time_id: esptime
  sun_sun = new sun::Sun();
  // text_sensor.version:
  //   platform: version
  //   name: Platform
  //   on_value:
  //   - then:
  //     - lambda: !lambda "ESP_LOGD(\"main\", \"The current version is %s\", x.c_str()); "
  //       type_id: lambdaaction_3
  //     automation_id: automation_3
  //     trigger_id: text_sensor_textsensorstatetrigger
  //   id: version_versiontextsensor
  //   icon: mdi:new-box
  //   hide_timestamp: false
  version_versiontextsensor = new version::VersionTextSensor();
  App.register_text_sensor(version_versiontextsensor);
  version_versiontextsensor->set_name("Platform");
  version_versiontextsensor->set_icon("mdi:new-box");
  text_sensor_textsensorstatetrigger = new text_sensor::TextSensorStateTrigger(version_versiontextsensor);
  automation_3 = new Automation<std::string>(text_sensor_textsensorstatetrigger);
  // text_sensor.template:
  //   platform: template
  //   name: Local Time
  //   lambda: !lambda |-
  //     char str[17];
  //     time_t currTime = id(esptime).now().timestamp ;
  //     strftime(str, sizeof(str), "%Y-%m-%d %H:%M", localtime(&currTime));
  //     return {str};
  //   update_interval: 60s
  //   id: template__templatetextsensor
  template__templatetextsensor = new template_::TemplateTextSensor();
  template__templatetextsensor->set_update_interval(60000);
  App.register_component(template__templatetextsensor);
  // text_sensor.template:
  //   platform: template
  //   name: Sunrise
  //   lambda: !lambda |-
  //     int sunrise;
  //     auto sunSensor = new MySunTextSensor();
  //     App.register_component(sunSensor);
  //     auto sun_sensor = sunSensor->sun;
  //     auto time = id(esptime).now();
  //     sun_sensor->setPosition(48.764401694750994, 8.342827325621384, 1);
  //     sun_sensor->setCurrentDate(time.year, time.month, time.day_of_month);
  //     sunrise = static_cast<int>(sun_sensor->calcSunrise());
  //     char buffer[20];
  //     sprintf(buffer, "%.2d:%.2d", (sunrise/60), (sunrise%60));
  //     return {buffer};
  //   id: template__templatetextsensor_2
  //   update_interval: 60s
  template__templatetextsensor_2 = new template_::TemplateTextSensor();
  template__templatetextsensor_2->set_update_interval(60000);
  App.register_component(template__templatetextsensor_2);
  // text_sensor.template:
  //   platform: template
  //   name: Sunset
  //   lambda: !lambda |-
  //     int sunset;
  //     auto sunSensor = new MySunTextSensor();
  //     App.register_component(sunSensor);
  //     auto sun_sensor = sunSensor->sun;
  //     auto time = id(esptime).now();
  //     sun_sensor->setPosition(48.764401694750994, 8.342827325621384, 1);
  //     sun_sensor->setCurrentDate(time.year, time.month, time.day_of_month);
  //     sunset = static_cast<int>(sun_sensor->calcSunset());
  //     char buffer[20];
  //     sprintf(buffer, "%.2d:%.2d", (sunset/60), (sunset%60));
  //     return {buffer};
  //   id: template__templatetextsensor_3
  //   update_interval: 60s
  template__templatetextsensor_3 = new template_::TemplateTextSensor();
  template__templatetextsensor_3->set_update_interval(60000);
  App.register_component(template__templatetextsensor_3);
  esptime->set_timezone("CET-1CEST-2,M3.4.0/2,M10.5.0/3");
  lambdaaction_3 = new LambdaAction<std::string>([=](std::string x) -> void {
      ESP_LOGD("main", "The current version is %s", x.c_str()); 
  });
  App.register_text_sensor(template__templatetextsensor);
  template__templatetextsensor->set_name("Local Time");
  App.register_text_sensor(template__templatetextsensor_2);
  template__templatetextsensor_2->set_name("Sunrise");
  App.register_text_sensor(template__templatetextsensor_3);
  template__templatetextsensor_3->set_name("Sunset");
  sun_sun->set_time(esptime);
  sun_sun->set_latitude(48.764401694750994f);
  sun_sun->set_longitude(8.342827325621384f);
  sun_suntrigger = new sun::SunTrigger();
  App.register_component(sun_suntrigger);
  sun_suntrigger->set_parent(sun_sun);
  sun_suntrigger->set_sunrise(true);
  sun_suntrigger->set_elevation(-0.883f);
  automation = new Automation<>(sun_suntrigger);
  automation_3->add_actions({lambdaaction_3});
  template__templatetextsensor->set_template([=]() -> optional<std::string> {
      char str[17];
      time_t currTime = esptime->now().timestamp ;
      strftime(str, sizeof(str), "%Y-%m-%d %H:%M", localtime(&currTime));
      return {str};
  });
  template__templatetextsensor_2->set_template([=]() -> optional<std::string> {
      int sunrise;
      auto sunSensor = new MySunTextSensor();
      App.register_component(sunSensor);
      auto sun_sensor = sunSensor->sun;
      auto time = esptime->now();
      sun_sensor->setPosition(48.764401694750994, 8.342827325621384, 1);
      sun_sensor->setCurrentDate(time.year, time.month, time.day_of_month);
      sunrise = static_cast<int>(sun_sensor->calcSunrise());
      char buffer[20];
      sprintf(buffer, "%.2d:%.2d", (sunrise/60), (sunrise%60));
      return {buffer};
  });
  template__templatetextsensor_3->set_template([=]() -> optional<std::string> {
      int sunset;
      auto sunSensor = new MySunTextSensor();
      App.register_component(sunSensor);
      auto sun_sensor = sunSensor->sun;
      auto time = esptime->now();
      sun_sensor->setPosition(48.764401694750994, 8.342827325621384, 1);
      sun_sensor->setCurrentDate(time.year, time.month, time.day_of_month);
      sunset = static_cast<int>(sun_sensor->calcSunset());
      char buffer[20];
      sprintf(buffer, "%.2d:%.2d", (sunset/60), (sunset%60));
      return {buffer};
  });
  lambdaaction = new LambdaAction<>([=]() -> void {
      ESP_LOGD("main", "Good morning!");
  });
  App.register_component(version_versiontextsensor);
  automation->add_actions({lambdaaction});
  version_versiontextsensor->set_hide_timestamp(false);
  sun_suntrigger_2 = new sun::SunTrigger();
  App.register_component(sun_suntrigger_2);
  sun_suntrigger_2->set_parent(sun_sun);
  sun_suntrigger_2->set_sunrise(false);
  sun_suntrigger_2->set_elevation(-0.883f);
  automation_2 = new Automation<>(sun_suntrigger_2);
  lambdaaction_2 = new LambdaAction<>([=]() -> void {
      ESP_LOGD("main", "Good evening!");
  });
  automation_2->add_actions({lambdaaction_2});
  // =========== AUTO GENERATED CODE END ============
  // ========= YOU CAN EDIT AFTER THIS LINE =========
  App.setup();
}

void loop() {
  App.loop();
}
