ESPHome  2024.4.0
sun_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace sun {
9 
10 enum SensorType {
13 };
14 
15 class SunSensor : public sensor::Sensor, public PollingComponent {
16  public:
17  void set_parent(Sun *parent) { parent_ = parent; }
19  void dump_config() override;
20  void update() override {
21  double val;
22  switch (this->type_) {
24  val = this->parent_->elevation();
25  break;
26  case SUN_SENSOR_AZIMUTH:
27  val = this->parent_->azimuth();
28  break;
29  default:
30  return;
31  }
32  this->publish_state(val);
33  }
34 
35  protected:
38 };
39 
40 } // namespace sun
41 } // namespace esphome
double azimuth()
Definition: sun.cpp:319
void set_type(SensorType type)
Definition: sun_sensor.h:18
void dump_config() override
Definition: sun_sensor.cpp:9
mopeka_std_values val[4]
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void update() override
Definition: sun_sensor.h:20
double elevation()
Definition: sun.cpp:318
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
uint8_t type
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
void set_parent(Sun *parent)
Definition: sun_sensor.h:17