mirror of
https://github.com/esphome/esphome.git
synced 2025-09-24 22:22:22 +01:00
Remove last_reset_type and convert all those sensors to TOTAL_INCREASING (#2233)
This commit is contained in:
@@ -19,7 +19,6 @@ from esphome.const import (
|
||||
CONF_ICON,
|
||||
CONF_ID,
|
||||
CONF_INVERTED,
|
||||
CONF_LAST_RESET_TYPE,
|
||||
CONF_MAX_VALUE,
|
||||
CONF_MIN_VALUE,
|
||||
CONF_NAME,
|
||||
@@ -40,8 +39,8 @@ from esphome.const import (
|
||||
ICON_BLUR,
|
||||
ICON_EMPTY,
|
||||
ICON_THERMOMETER,
|
||||
LAST_RESET_TYPE_AUTO,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_EMPTY,
|
||||
UNIT_PERCENT,
|
||||
@@ -336,8 +335,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
CONF_UNIT_OF_MEASUREMENT: UNIT_WATT_HOURS,
|
||||
CONF_ACCURACY_DECIMALS: 0,
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
|
||||
CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
CONF_LAST_RESET_TYPE: LAST_RESET_TYPE_AUTO,
|
||||
CONF_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
|
||||
},
|
||||
],
|
||||
): [
|
||||
|
@@ -11,8 +11,8 @@ class DemoSensor : public sensor::Sensor, public PollingComponent {
|
||||
public:
|
||||
void update() override {
|
||||
float val = random_float();
|
||||
bool is_auto = this->last_reset_type == sensor::LAST_RESET_TYPE_AUTO;
|
||||
if (is_auto) {
|
||||
bool increasing = this->state_class == sensor::STATE_CLASS_TOTAL_INCREASING;
|
||||
if (increasing) {
|
||||
float base = isnan(this->state) ? 0.0f : this->state;
|
||||
this->publish_state(base + val * 10);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user