Skip to content

Commit

Permalink
Add auto mode field to thermostat state packets
Browse files Browse the repository at this point in the history
  • Loading branch information
KazWolfe committed Jun 20, 2024
1 parent 3e7f81b commit 1bdc660
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ void MitsubishiUART::handle_thermostat_state_download_request(const GetRequestPa

auto response = ThermostatStateDownloadResponsePacket();

response.set_auto_mode((mode == climate::CLIMATE_MODE_HEAT_COOL || mode == climate::CLIMATE_MODE_AUTO));
response.set_heat_setpoint(this->mhk_state_.heat_setpoint_);
response.set_cool_setpoint(this->mhk_state_.cool_setpoint_);

Expand Down
10 changes: 10 additions & 0 deletions esphome/components/mitsubishi_itp/muart_packet-derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ std::string ThermostatStateUploadPacket::to_string() const {
result += " TS Time: " + timestamp.strftime("%Y-%m-%d %H:%M:%S");
}

if (flags & TSSF_AUTO_MODE) result += " AutoMode: " + std::to_string(get_auto_mode());
if (flags & TSSF_HEAT_SETPOINT) result += " HeatSetpoint: " + std::to_string(get_heat_setpoint());
if (flags & TSSF_COOL_SETPOINT) result += " CoolSetpoint: " + std::to_string(get_cool_setpoint());

Expand Down Expand Up @@ -304,6 +305,10 @@ int32_t ThermostatStateUploadPacket::get_thermostat_timestamp(esphome::ESPTime *
return outTimestamp->timestamp;
}

uint8_t ThermostatStateUploadPacket::get_auto_mode() const {
return pkt_.get_payload_byte(PLINDEX_AUTO_MODE);
}

float ThermostatStateUploadPacket::get_heat_setpoint() const {
uint8_t enhancedRawTemp = pkt_.get_payload_byte(PLINDEX_HEAT_SETPOINT);
return MUARTUtils::temp_scale_a_to_deg_c(enhancedRawTemp);
Expand All @@ -327,6 +332,11 @@ ThermostatStateDownloadResponsePacket &ThermostatStateDownloadResponsePacket::se
return *this;
}

ThermostatStateDownloadResponsePacket &ThermostatStateDownloadResponsePacket::set_auto_mode(bool is_auto) {
pkt_.set_payload_byte(PLINDEX_AUTO_MODE, is_auto ? 0x01 : 0x00);
return *this;
}

ThermostatStateDownloadResponsePacket &ThermostatStateDownloadResponsePacket::set_heat_setpoint(float highTemp) {
uint8_t temp_a = highTemp != NAN ? MUARTUtils::deg_c_to_temp_scale_a(highTemp) : 0x00;

Expand Down
5 changes: 5 additions & 0 deletions esphome/components/mitsubishi_itp/muart_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,13 @@ class ThermostatStateUploadPacket : public Packet {
// Packet 0x41 - AG 0xA8

static const uint8_t PLINDEX_THERMOSTAT_TIMESTAMP = 2;
static const uint8_t PLINDEX_AUTO_MODE = 7;
static const uint8_t PLINDEX_HEAT_SETPOINT = 8;
static const uint8_t PLINDEX_COOL_SETPOINT = 9;

enum TSStateSyncFlags : uint8_t {
TSSF_TIMESTAMP = 0x01,
TSSF_AUTO_MODE = 0x04,
TSSF_HEAT_SETPOINT = 0x08,
TSSF_COOL_SETPOINT = 0x10,
};
Expand All @@ -485,6 +487,7 @@ class ThermostatStateUploadPacket : public Packet {
}

int32_t get_thermostat_timestamp(ESPTime* outTimestamp) const;
uint8_t get_auto_mode() const;
float get_heat_setpoint() const;
float get_cool_setpoint() const;

Expand All @@ -493,6 +496,7 @@ class ThermostatStateUploadPacket : public Packet {

class ThermostatStateDownloadResponsePacket : public Packet {
static const uint8_t PLINDEX_ADAPTER_TIMESTAMP = 1;
static const uint8_t PLINDEX_AUTO_MODE = 6;
static const uint8_t PLINDEX_HEAT_SETPOINT = 7;
static const uint8_t PLINDEX_COOL_SETPOINT = 8;

Expand All @@ -504,6 +508,7 @@ class ThermostatStateDownloadResponsePacket : public Packet {
}

ThermostatStateDownloadResponsePacket &set_timestamp(ESPTime ts);
ThermostatStateDownloadResponsePacket &set_auto_mode(bool is_auto);
ThermostatStateDownloadResponsePacket &set_heat_setpoint(float highTemp);
ThermostatStateDownloadResponsePacket &set_cool_setpoint(float lowTemp);
};
Expand Down

0 comments on commit 1bdc660

Please sign in to comment.