mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-05 20:38:27 +02:00
8e75980ebd
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/preferences.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
#include "esphome/components/time/real_time_clock.h"
|
|
|
|
namespace esphome {
|
|
namespace total_daily_energy {
|
|
|
|
class TotalDailyEnergy : public sensor::Sensor, public Component {
|
|
public:
|
|
void set_time(time::RealTimeClock *time) { time_ = time; }
|
|
void set_parent(Sensor *parent) { parent_ = parent; }
|
|
void setup() override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
|
std::string unit_of_measurement() override { return this->parent_->get_unit_of_measurement() + "h"; }
|
|
std::string icon() override { return this->parent_->get_icon(); }
|
|
int8_t accuracy_decimals() override { return this->parent_->get_accuracy_decimals() + 2; }
|
|
void loop() override;
|
|
|
|
void publish_state_and_save(float state);
|
|
|
|
protected:
|
|
void process_new_state_(float state);
|
|
|
|
ESPPreferenceObject pref_;
|
|
time::RealTimeClock *time_;
|
|
Sensor *parent_;
|
|
uint16_t last_day_of_year_{};
|
|
uint32_t last_update_{0};
|
|
float total_energy_{0.0f};
|
|
};
|
|
|
|
} // namespace total_daily_energy
|
|
} // namespace esphome
|