Skip to content

Commit

Permalink
Sepparate climate from main component
Browse files Browse the repository at this point in the history
  • Loading branch information
netmindz committed Oct 18, 2023
1 parent 84b7248 commit 4dadf6f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#include "esphome/core/log.h"
#include "esp_log.h"

#include "BalboaGLSelect.h"
#include "BalboaGLSwitch.h"
#include "ESPBalboaGL.h"

static const char* TAG = "BalboaGL"; // Logging tag

// // Perform measurements or read nameplate values on your tub to define the power [kW]
Expand All @@ -33,11 +29,8 @@ const uint32_t POLL_INTERVAL_DEFAULT = 10000;

using namespace esphome;

class BalboaGL : public PollingComponent, public climate::Climate {
class BalboaGLClimate : public PollingComponent, public climate::Climate {
public:
BalboaGL(
HardwareSerial* hw_serial
);

// print the current configuration
void dump_config() override;
Expand Down Expand Up @@ -70,47 +63,11 @@ class BalboaGL : public PollingComponent, public climate::Climate {
// // set_remote_temp(0) to switch back to the internal sensor.
// void set_remote_temperature(float);

void set_rx_pin(int pin);

void set_tx_pin(int pin);

void set_rts_pin(int pin);

void set_panel_select_pin(int pin);

float get_setup_priority() const override { return esphome::setup_priority::AFTER_WIFI; }

protected:
// The ClimateTraits supported by this HeatPump.
climate::ClimateTraits traits_;

//Accessor method for the HardwareSerial pointer
HardwareSerial* get_hw_serial_() {
return this->hw_serial_;
}

//Print a warning message if we're using the sole hardware UART on an
//ESP8266 or UART0 on ESP32
void check_logger_conflict_();

esphome::balboa_select::BalboaGLPump1Select* pump1;
esphome::balboa_select::BalboaGLPump2Select* pump2;

esphome::balboa_switch::BalboaGLLightSwitch* lightSwitch;

esphome::text_sensor::TextSensor* stateSensor;
esphome::text_sensor::TextSensor* rawSensor;
// esphome::text_sensor::TextSensor* lcdSensor;

int rx_pin = -1;
int tx_pin = -1;
int rts_pin = -1;
int panel_select_pin = -1;

private:
// Retrieve the HardwareSerial pointer from friend and subclasses.
HardwareSerial *hw_serial_;

balboaGL* spa;
};
#endif
88 changes: 6 additions & 82 deletions components/BalboaGL/climate/ESPBalboaGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,8 @@
#include "ESPBalboaGL.h"
using namespace esphome;

void telnetSend(String msg) {
ESP_LOGI(TAG, msg.c_str());
}
/**
* Create a new BalboaGL object
*
* Args:
* hw_serial: pointer to an Arduino HardwareSerial instance
* poll_interval: polling interval in milliseconds
*/
BalboaGL::BalboaGL(
HardwareSerial* hw_serial
) :
hw_serial_{hw_serial}
{
this->traits_.set_supports_action(false);
this->traits_.set_supports_current_temperature(true);
this->traits_.set_supports_two_point_target_temperature(false);
this->traits_.set_visual_min_temperature(26);
this->traits_.set_visual_max_temperature(40);
this->traits_.set_visual_temperature_step(0.5);

this->rawSensor = new text_sensor::TextSensor();
this->stateSensor = new text_sensor::TextSensor();

this->lightSwitch = new balboa_switch::BalboaGLLightSwitch();

// this->pump1 = new balboa_select::BalboaGLPump1Select();
// this->pump2 = new balboa_select::BalboaGLPump12elect();
}

void BalboaGL::check_logger_conflict_() {
#ifdef USE_LOGGER
if (this->get_hw_serial_() == logger::global_logger->get_hw_serial()) {
ESP_LOGW(TAG, " You're using the same serial port for logging"
" and the BalboaGL component. Please disable"
" logging over the serial port by setting"
" logger:baud_rate to 0.");
}
#endif
}

void BalboaGL::update() {
void BalboaGLClimate::update() {
// This will be called every "update_interval" milliseconds.
ESP_LOGV(TAG, "Update called.");
size_t len = this->spa->readSerial();
Expand Down Expand Up @@ -132,7 +91,7 @@ climate::ClimateTraits& BalboaGL::config_traits() {
*
* Maps HomeAssistant/ESPHome modes to Mitsubishi modes.
*/
void BalboaGL::control(const climate::ClimateCall &call) {
void BalboaGLClimate::control(const climate::ClimateCall &call) {
ESP_LOGV(TAG, "Control called.");

bool updated = false;
Expand Down Expand Up @@ -385,35 +344,18 @@ void BalboaGL::control(const climate::ClimateCall &call) {
// this->hp->setRemoteTemperature(temp);
// }

void BalboaGL::setup() {
void BalboaGLClimate::setup() {
// This will be called by App.setup()
// this->banner();
ESP_LOGCONFIG(TAG, "Setting up UART...");
if (!this->get_hw_serial_()) {
ESP_LOGCONFIG(
TAG,
"No HardwareSerial was provided. "
"Software serial ports are unsupported by this component."
);
this->mark_failed();
return;
}
this->check_logger_conflict_();

ESP_LOGCONFIG(TAG, "Initialize new balboaGLCliamte object.");

ESP_LOGCONFIG(TAG, "Initialize new balboaGL object.");

ESP_LOGI(TAG, "Serial begin rx,tx = %u,%u", this->rx_pin, this->tx_pin);
hw_serial_->begin(115200, SERIAL_8N1, rx_pin, tx_pin);
this->spa = new balboaGL(hw_serial_, rts_pin, panel_select_pin);
this->current_temperature = NAN;
this->target_temperature = NAN;
this->fan_mode = climate::CLIMATE_FAN_OFF;
this->swing_mode = climate::CLIMATE_SWING_OFF;
this->action = climate::CLIMATE_ACTION_FAN;

this->lightSwitch->setSpa(spa);


// ESP_LOGCONFIG(
// TAG,
// "hw_serial(%p) is &Serial(%p)? %s",
Expand Down Expand Up @@ -468,11 +410,8 @@ void BalboaGL::setup() {
// return ESPMHP_MIN_TEMPERATURE + (steps * ESPMHP_TEMPERATURE_STEP);
// }

void BalboaGL::dump_config() {
void BalboaGLClimate::dump_config() {
// this->banner();
ESP_LOGI(TAG, " rx,tx = %u,%u", this->rx_pin, this->tx_pin);
ESP_LOGI(TAG, " rts_pin = %u", this->rts_pin);
ESP_LOGI(TAG, " panel_select_pin = %u", this->panel_select_pin);
// ESP_LOGI(TAG, " Supports HEAT: %s", YESNO(true));
// ESP_LOGI(TAG, " Supports COOL: %s", YESNO(true));
// ESP_LOGI(TAG, " Supports AWAY mode: %s", YESNO(false));
Expand All @@ -485,18 +424,3 @@ void BalboaGL::dump_config() {
// LOG_CLIMATE("", "BalboaGL Climate", this);
// ESP_LOGI(TAG, "HELLO");
// }

void BalboaGL::set_rx_pin(int pin) {
this->rx_pin = pin;
}

void BalboaGL::set_tx_pin(int pin) {
this->tx_pin = pin;
}
void BalboaGL::set_rts_pin(int pin) {
this->rts_pin = pin;
}

void BalboaGL::set_panel_select_pin(int pin) {
this->panel_select_pin = pin;
}
20 changes: 2 additions & 18 deletions components/ESPBalboaGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "esphome/core/preferences.h"
// #include "esphome/components/sensor/sensor.h"
#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/components/climate/climate.h"
#include "esphome/core/log.h"
#include "esp_log.h"

Expand Down Expand Up @@ -33,7 +32,7 @@ const uint32_t POLL_INTERVAL_DEFAULT = 10000;

using namespace esphome;

class BalboaGL : public PollingComponent, public climate::Climate {
class BalboaGL : public PollingComponent {
public:
BalboaGL(
HardwareSerial* hw_serial
Expand All @@ -54,22 +53,9 @@ class BalboaGL : public PollingComponent, public climate::Climate {
// This is called every poll_interval.
void update() override;

// Configure the climate object with traits that we support.
climate::ClimateTraits traits() override;

// Get a mutable reference to the traits that we support.
climate::ClimateTraits& config_traits();

// Debugging function to print the object's state.
// void dump_state();

// Handle a request from the user to change settings.
void control(const climate::ClimateCall &call) override;

// // Use the temperature from an external sensor. Use
// // set_remote_temp(0) to switch back to the internal sensor.
// void set_remote_temperature(float);

void set_rx_pin(int pin);

void set_tx_pin(int pin);
Expand All @@ -81,9 +67,7 @@ class BalboaGL : public PollingComponent, public climate::Climate {
float get_setup_priority() const override { return esphome::setup_priority::AFTER_WIFI; }

protected:
// The ClimateTraits supported by this HeatPump.
climate::ClimateTraits traits_;


//Accessor method for the HardwareSerial pointer
HardwareSerial* get_hw_serial_() {
return this->hw_serial_;
Expand Down

0 comments on commit 4dadf6f

Please sign in to comment.