ESPHome  2022.9.2
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:314
void set_type(SensorType type)
Definition: sun_sensor.h:18
void dump_config() override
Definition: sun_sensor.cpp:9
This class simplifies creating components that periodically check a state.
Definition: component.h:266
void update() override
Definition: sun_sensor.h:20
double elevation()
Definition: sun.cpp:313
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:72
uint8_t type
Definition: a4988.cpp:4
uint32_t val
Definition: datatypes.h:85
Base-class for all sensors.
Definition: sensor.h:48
void set_parent(Sun *parent)
Definition: sun_sensor.h:17