Added all the changes necessary to run chlorine pump again
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/gpio/output/gpio_binary_output.h"
|
||||
#include "esphome/components/analog_orp/analog_orp.h"
|
||||
|
||||
static const char *const TAG = "chlorine_pump";
|
||||
|
||||
@@ -12,7 +11,7 @@ namespace chlorine_pump {
|
||||
class ChlorinePump : public Component {
|
||||
protected:
|
||||
|
||||
analog_orp::ChlorineSensor *sensor_;
|
||||
sensor::Sensor *sensor_;
|
||||
gpio::GPIOBinaryOutput *pump_out;
|
||||
int cycle_time;
|
||||
int prop_band;
|
||||
@@ -24,6 +23,7 @@ class ChlorinePump : public Component {
|
||||
int tOn = 0;
|
||||
int tOff = 0;
|
||||
float target_ = 700.0f;
|
||||
float tOn_divider_;
|
||||
|
||||
public:
|
||||
|
||||
@@ -35,9 +35,12 @@ class ChlorinePump : public Component {
|
||||
void disable_clock(bool disable_clock){
|
||||
this->disable_clock_ = disable_clock;
|
||||
}
|
||||
void set_sensor(analog_orp::ChlorineSensor *sensor){
|
||||
void set_sensor(sensor::Sensor *sensor){
|
||||
this->sensor_ = sensor;
|
||||
}
|
||||
void set_pump_time_divivder(float pump_time_divider){
|
||||
this->tOn_divider_ = pump_time_divider;
|
||||
}
|
||||
void set_pump_out(gpio::GPIOBinaryOutput *pump_out){
|
||||
this->pump_out = pump_out;
|
||||
}
|
||||
@@ -54,10 +57,7 @@ class ChlorinePump : public Component {
|
||||
void setup() override {
|
||||
last_action = millis();
|
||||
if(disable_clock_ && sensor_ != nullptr){
|
||||
if(!sensor_->has_averager()) sensor_->add_on_state_callback([=](float val) -> void {
|
||||
this->tick_time(val);
|
||||
});
|
||||
if(sensor_->has_averager()) sensor_->add_average_change_callback([=](float val) -> void {
|
||||
sensor_->add_on_state_callback([=](float val) -> void {
|
||||
this->tick_time(val);
|
||||
});
|
||||
}
|
||||
@@ -119,14 +119,13 @@ class ChlorinePump : public Component {
|
||||
if(tOn == 0 && tOff == 0 && state){
|
||||
int seconds = calculatePumpTimeSeconds(last_mesurement);
|
||||
|
||||
tOn = seconds;
|
||||
tOff = cycle_time - tOn;
|
||||
|
||||
if(seconds == 0){
|
||||
tOn = 0;
|
||||
tOff = 30;
|
||||
tOff = 360;
|
||||
}
|
||||
|
||||
tOn = seconds;
|
||||
tOff = cycle_time - tOn;
|
||||
|
||||
ESP_LOGD(TAG, "Time => tOn: %d, tOff: %d", tOn, tOff);
|
||||
|
||||
this->callback_cycle_.call(tOn, tOff);
|
||||
@@ -149,7 +148,8 @@ class ChlorinePump : public Component {
|
||||
|
||||
if(millis() - last_action > 1000){
|
||||
|
||||
tick_time(sensor_->get_state());
|
||||
if(sensor_->has_state())
|
||||
tick_time(sensor_->get_state());
|
||||
|
||||
setMillisPrecies(1000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user