mirror of
https://github.com/geoffdavis/esphome-mitsubishiheatpump
synced 2024-08-30 18:12:13 +00:00
First working version
Various fixups to function definitions and namespacing to make the split header/cpp file configuration work.
This commit is contained in:
parent
92d9b5bb2f
commit
b9061043a5
86
espmhp.cpp
86
espmhp.cpp
@ -12,8 +12,8 @@
|
||||
* - ESPHome 1.5.0-dev or greater
|
||||
*/
|
||||
|
||||
|
||||
#include "espmhp.h"
|
||||
using namespace esphome;
|
||||
|
||||
/**
|
||||
* Create a new MitsubishiHeatPump object
|
||||
@ -22,33 +22,34 @@
|
||||
* hw_serial: pointer to an Arduino HardwareSerial instance
|
||||
* poll_interval: polling interval in milliseconds
|
||||
*/
|
||||
MitsubishiHeatPump(
|
||||
HardwareSerial * hw_serial,
|
||||
uint32_t poll_interval=ESPMHP_POLL_INTERVAL_DEFAULT
|
||||
) : PollingComponent(poll_interval) {
|
||||
this->hw_serial_ = hw_serial;
|
||||
}
|
||||
MitsubishiHeatPump::MitsubishiHeatPump(
|
||||
HardwareSerial* hw_serial,
|
||||
uint32_t poll_interval
|
||||
) :
|
||||
PollingComponent{poll_interval}, // member initializers list
|
||||
hw_serial_{hw_serial}
|
||||
{ }
|
||||
|
||||
void MitsubishiHeatPump::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 MitsubishiHeatPump component. Please disable"
|
||||
" logging over the serial port by setting"
|
||||
" logger:baud_rate to 0.");
|
||||
}
|
||||
#endif
|
||||
#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 MitsubishiHeatPump component. Please disable"
|
||||
" logging over the serial port by setting"
|
||||
" logger:baud_rate to 0.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MitsubishiHeatPump::update() {
|
||||
// This will be called every "update_interval" milliseconds.
|
||||
//this->dump_config();
|
||||
hp->sync();
|
||||
#ifndef USE_CALLBACKS
|
||||
this->hpSettingsChanged();
|
||||
heatpumpStatus currentStatus = hp->getStatus();
|
||||
this->hpStatusChanged(currentStatus);
|
||||
#endif
|
||||
this->hp->sync();
|
||||
#ifndef USE_CALLBACKS
|
||||
this->hpSettingsChanged();
|
||||
heatpumpStatus currentStatus = hp->getStatus();
|
||||
this->hpStatusChanged(currentStatus);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +60,7 @@ void MitsubishiHeatPump::update() {
|
||||
* ESPHome, particularly the Dry operation mode, and several of the fan modes.
|
||||
*
|
||||
* Returns:
|
||||
* This class' supported ESPHome climate::ClimateTraits.
|
||||
* This class' supported climate::ClimateTraits.
|
||||
*/
|
||||
climate::ClimateTraits MitsubishiHeatPump::traits() {
|
||||
auto traits = climate::ClimateTraits();
|
||||
@ -136,8 +137,10 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
|
||||
}
|
||||
|
||||
if (call.get_target_temperature().has_value()){
|
||||
ESP_LOGV("control", "Sending target temp: %.1f",
|
||||
*call.get_target_temperature())
|
||||
ESP_LOGV(
|
||||
"control", "Sending target temp: %.1f",
|
||||
*call.get_target_temperature()
|
||||
)
|
||||
hp->setTemperature(*call.get_target_temperature());
|
||||
updated = true;
|
||||
}
|
||||
@ -201,9 +204,6 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
|
||||
}
|
||||
ESP_LOGD(TAG, "control - Was HeatPump updated? %s", YESNO(updated));
|
||||
hp->update();
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void MitsubishiHeatPump::hpSettingsChanged() {
|
||||
@ -230,15 +230,15 @@ void MitsubishiHeatPump::hpSettingsChanged() {
|
||||
*/
|
||||
if (strcmp(currentSettings.power, "ON") == 0) {
|
||||
if (strcmp(currentSettings.mode, "HEAT") == 0) {
|
||||
this->mode = CLIMATE_MODE_HEAT;
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
} else if (strcmp(currentSettings.mode, "DRY") == 0) {
|
||||
this->mode = CLIMATE_MODE_DRY;
|
||||
this->mode = climate::CLIMATE_MODE_DRY;
|
||||
} else if (strcmp(currentSettings.mode, "COOL") == 0) {
|
||||
this->mode = CLIMATE_MODE_COOL;
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
} else if (strcmp(currentSettings.mode, "FAN") == 0) {
|
||||
this->mode = CLIMATE_MODE_FAN_ONLY;
|
||||
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
|
||||
} else if (strcmp(currentSettings.mode, "AUTO") == 0) {
|
||||
this->mode = CLIMATE_MODE_AUTO;
|
||||
this->mode = climate::CLIMATE_MODE_AUTO;
|
||||
} else {
|
||||
ESP_LOGW(
|
||||
TAG,
|
||||
@ -247,7 +247,7 @@ void MitsubishiHeatPump::hpSettingsChanged() {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this->mode = CLIMATE_MODE_OFF;
|
||||
this->mode = climate::CLIMATE_MODE_OFF;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Climate mode is: %i", this->mode);
|
||||
@ -258,17 +258,17 @@ void MitsubishiHeatPump::hpSettingsChanged() {
|
||||
* const char* FAN_MAP[6] = {"AUTO", "QUIET", "1", "2", "3", "4"};
|
||||
*/
|
||||
if (strcmp(currentSettings.fan, "QUIET") == 0) {
|
||||
this->fan_mode = CLIMATE_FAN_DIFFUSE;
|
||||
this->fan_mode = climate::CLIMATE_FAN_DIFFUSE;
|
||||
} else if (strcmp(currentSettings.fan, "1") == 0) {
|
||||
this->fan_mode = CLIMATE_FAN_LOW;
|
||||
this->fan_mode = climate::CLIMATE_FAN_LOW;
|
||||
} else if (strcmp(currentSettings.fan, "2") == 0) {
|
||||
this->fan_mode = CLIMATE_FAN_MEDIUM;
|
||||
this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
|
||||
} else if (strcmp(currentSettings.fan, "3") == 0) {
|
||||
this->fan_mode = CLIMATE_FAN_MIDDLE;
|
||||
this->fan_mode = climate::CLIMATE_FAN_MIDDLE;
|
||||
} else if (strcmp(currentSettings.fan, "4") == 0) {
|
||||
this->fan_mode = CLIMATE_FAN_HIGH;
|
||||
this->fan_mode = climate::CLIMATE_FAN_HIGH;
|
||||
} else { //case "AUTO" or default:
|
||||
this->fan_mode = CLIMATE_FAN_AUTO;
|
||||
this->fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||
}
|
||||
ESP_LOGI(TAG, "Fan mode is: %i", this->fan_mode);
|
||||
|
||||
@ -279,10 +279,10 @@ void MitsubishiHeatPump::hpSettingsChanged() {
|
||||
(strcmp(currentSettings.vane, "AUTO") == 0)
|
||||
|| (strcmp(currentSettings.vane, "SWING") == 0)
|
||||
) {
|
||||
this->swing_mode = CLIMATE_SWING_VERTICAL;
|
||||
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
|
||||
}
|
||||
else {
|
||||
this->swing_mode = CLIMATE_SWING_OFF;
|
||||
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
||||
}
|
||||
ESP_LOGI(TAG, "Swing mode is: %i", this->swing_mode);
|
||||
|
||||
@ -327,7 +327,7 @@ void MitsubishiHeatPump::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Intializing new HeatPump object.");
|
||||
this->hp = new HeatPump();
|
||||
|
||||
#ifdef USE_CALLBACKS
|
||||
#ifdef USE_CALLBACKS
|
||||
hp->setSettingsChangedCallback(
|
||||
[this]() {
|
||||
this->hpSettingsChanged();
|
||||
@ -339,7 +339,7 @@ void MitsubishiHeatPump::setup() {
|
||||
this->hpStatusChanged(currentStatus);
|
||||
}
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ESP_LOGCONFIG(
|
||||
TAG,
|
||||
|
28
espmhp.h
28
espmhp.h
@ -14,18 +14,17 @@
|
||||
|
||||
// Uncomment to use HeatPump callback functions (broken, causes boot failures)
|
||||
//#define USE_CALLBACKS
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#include "esphome/components/climate/climate_traits.h"
|
||||
#include "esphome/components/climate/climate_mode.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
#include "esphome.h"
|
||||
#include "HeatPump.h"
|
||||
using namespace esphome;
|
||||
|
||||
static const char *TAG = "MitsubishiHeatPump"; // Logging tag
|
||||
#ifndef ESPMHP_H
|
||||
#define ESPMHP_H
|
||||
|
||||
static const char *ESPMHP_VERSION = "1.0.0-dev";
|
||||
static const char* TAG = "MitsubishiHeatPump"; // Logging tag
|
||||
|
||||
static const char* ESPMHP_VERSION = "1.0.0-dev";
|
||||
|
||||
/* If polling interval is greater than 9 seconds, the HeatPump
|
||||
library reconnects, but doesn't then follow up with our data request.*/
|
||||
@ -38,11 +37,11 @@ static const uint8_t ESPMHP_MAX_TEMPERATURE = 31; // degrees C,
|
||||
static const uint8_t ESPMHP_TEMPERATURE_STEP = 0.5; // temperature setting step,
|
||||
// in degrees C
|
||||
|
||||
|
||||
class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Create a new MitsubishiHeatPump object
|
||||
*
|
||||
@ -51,14 +50,15 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
|
||||
* poll_interval: polling interval in milliseconds
|
||||
*/
|
||||
MitsubishiHeatPump(
|
||||
HardwareSerial * hw_serial,
|
||||
uint32_t poll_interval=ESPMHP_POLL_INTERVAL_DEFAULT
|
||||
) : PollingComponent(poll_interval);
|
||||
HardwareSerial* hw_serial,
|
||||
uint32_t poll_interval=ESPMHP_POLL_INTERVAL_DEFAULT
|
||||
);
|
||||
|
||||
// Print a banner with library information.
|
||||
void banner() {
|
||||
ESP_LOGI(TAG, "ESPHome MitsubishiHeatPump version %s",
|
||||
ESPMHP_VERSION);
|
||||
}
|
||||
|
||||
// print the current configuration
|
||||
void dump_config() override;
|
||||
@ -102,6 +102,8 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
|
||||
|
||||
private:
|
||||
// Retrieve the HardwareSerial pointer from friend and subclasses.
|
||||
HardwareSerial *hw_serial_{nullptr};
|
||||
HardwareSerial *hw_serial_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user