Sun support (#531)

* Sun

* Add sun support

* Lint

* Updates

* Fix elevation

* Lint

* Update mqtt_climate.cpp
This commit is contained in:
Otto Winter
2019-05-11 12:31:00 +02:00
committed by GitHub
parent f2540bae23
commit f1a0e5a313
22 changed files with 740 additions and 66 deletions
@@ -0,0 +1,41 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sun/sun.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace sun {
enum SensorType {
SUN_SENSOR_ELEVATION,
SUN_SENSOR_AZIMUTH,
};
class SunSensor : public sensor::Sensor, public PollingComponent {
public:
void set_parent(Sun *parent) { parent_ = parent; }
void set_type(SensorType type) { type_ = type; }
void dump_config() override;
void update() override {
double val;
switch (this->type_) {
case SUN_SENSOR_ELEVATION:
val = this->parent_->elevation();
break;
case SUN_SENSOR_AZIMUTH:
val = this->parent_->azimuth();
break;
default:
return;
}
this->publish_state(val);
}
protected:
sun::Sun *parent_;
SensorType type_;
};
} // namespace sun
} // namespace esphome