mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 21:09:53 +02:00
471b82f727
* Renamed Nameable to EntityBase (cpp) * Renamed NAMEABLE_SCHEMA to ENTITY_BASE_SCHEMA (Python) * Renamed cg.Nameable to cg.EntityBase (Python) * Remove redundant use of CONF_NAME from esp32_touch * Remove redundant use of CONF_NAME from mcp3008 * Updated test * Moved EntityBase from Component.h and Component.cpp * Added icon property to EntityBase * Added CONF_ICON to ENTITY_BASE_SCHEMA and added setup_entity function to cpp_helpers * Added MQTT component getters for icon and disabled_by_default * Lint * Removed icon field from MQTT components * Code generation now uses setup_entity to setENTITY_BASE_SCHEMA fields * Removed unused import * Added cstdint include * Optimisation: don't set icon if it is empty * Remove icon from NumberTraits and SelectTraits * Removed unused import * Integration and Total Daily Energy sensors now inherit icons from their parents during code generation * Minor comment correction * Removed redundant icon-handling code from sensor, switch, and text_sensor * Update esphome/components/tsl2591/tsl2591.h Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> * Added icon property to binary sensor, climate, cover, and fan component tests * Added icons for Binary Sensor, Climate, Cover, Fan, and Light to API * Consolidated EntityBase fields in MQTT components Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/preferences.h"
|
|
#include "esphome/core/hal.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
#include "esphome/components/time/real_time_clock.h"
|
|
|
|
namespace esphome {
|
|
namespace total_daily_energy {
|
|
|
|
enum TotalDailyEnergyMethod {
|
|
TOTAL_DAILY_ENERGY_METHOD_TRAPEZOID = 0,
|
|
TOTAL_DAILY_ENERGY_METHOD_LEFT,
|
|
TOTAL_DAILY_ENERGY_METHOD_RIGHT,
|
|
};
|
|
|
|
class TotalDailyEnergy : public sensor::Sensor, public Component {
|
|
public:
|
|
void set_min_save_interval(uint32_t min_interval) { this->min_save_interval_ = min_interval; }
|
|
void set_time(time::RealTimeClock *time) { time_ = time; }
|
|
void set_parent(Sensor *parent) { parent_ = parent; }
|
|
void set_method(TotalDailyEnergyMethod method) { method_ = method; }
|
|
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"; }
|
|
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_;
|
|
TotalDailyEnergyMethod method_;
|
|
uint16_t last_day_of_year_{};
|
|
uint32_t last_update_{0};
|
|
uint32_t last_save_{0};
|
|
uint32_t min_save_interval_{0};
|
|
float total_energy_{0.0f};
|
|
float last_power_state_{0.0f};
|
|
};
|
|
|
|
} // namespace total_daily_energy
|
|
} // namespace esphome
|