diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 10d283c0..22504dfb 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -77,7 +77,7 @@ namespace esphome virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0; }; - class ProtocolRequest + struct ProtocolRequest { public: optional power; @@ -87,6 +87,7 @@ namespace esphome class Protocol { public: + virtual void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) = 0; virtual void publish_power_message(MessageTarget *target, const std::string &address, bool value) = 0; virtual void publish_target_temp_message(MessageTarget *target, const std::string &address, float value) = 0; virtual void publish_mode_message(MessageTarget *target, const std::string &address, Mode value) = 0; diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 4a24cb45..4a1bd906 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -439,6 +439,33 @@ namespace esphome target->publish_data(data); } + void NasaProtocol::publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) + { + Packet packet = Packet::createa_partial(Address::parse(address), DataType::Request); + + if (request.mode) + { + request.power = true; // ensure system turns on when mode is set + + MessageSet mode(MessageNumber::ENUM_in_operation_mode); + mode.value = (int)request.mode.value(); + packet.messages.push_back(mode); + } + + if (request.power) + { + MessageSet power(MessageNumber::ENUM_in_operation_power); + power.value = request.power.value() ? 1 : 0; + packet.messages.push_back(power); + } + + if (packet.messages.size() == 0) + return; + + auto data = packet.encode(); + target->publish_data(data); + } + Mode operation_mode_to_mode(int value) { switch (value) diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 17f4d53f..dc8f3d7b 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -167,6 +167,7 @@ namespace esphome public: NasaProtocol() = default; + void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; void publish_power_message(MessageTarget *target, const std::string &address, bool value) override; void publish_target_temp_message(MessageTarget *target, const std::string &address, float value) override; void publish_mode_message(MessageTarget *target, const std::string &address, Mode value) override; diff --git a/components/samsung_ac/protocol_non_nasa.cpp b/components/samsung_ac/protocol_non_nasa.cpp index d6408daa..cd286528 100644 --- a/components/samsung_ac/protocol_non_nasa.cpp +++ b/components/samsung_ac/protocol_non_nasa.cpp @@ -139,15 +139,15 @@ namespace esphome case NonNasaCommand::CmdF3: // power consumption { // Maximum frequency for Inverter (compressor-motor of outdoor-unit) in Hz - commandF3.inverter_max_frequency_hz = data[4]; + commandF3.inverter_max_frequency_hz = data[4]; // Sum of required heating/cooling capacity ordered by the indoor-units in kW - commandF3.inverter_total_capacity_requirement_kw = (float)data[5] / 10; + commandF3.inverter_total_capacity_requirement_kw = (float)data[5] / 10; // DC-current to the inverter of outdoor-unit in A - commandF3.inverter_current_a = (float)data[8] / 10; + commandF3.inverter_current_a = (float)data[8] / 10; // voltage of the DC-link to inverter in V - commandF3.inverter_voltage_v = (float)data[9] * 2; - //Power consumption of the outdoo unit inverter in W - commandF3.inverter_power_w = commandF3.inverter_current_a * commandF3.inverter_voltage_v; + commandF3.inverter_voltage_v = (float)data[9] * 2; + // Power consumption of the outdoo unit inverter in W + commandF3.inverter_power_w = commandF3.inverter_current_a * commandF3.inverter_voltage_v; return DecodeResult::Ok; } default: @@ -331,6 +331,11 @@ namespace esphome // TODO } + void NonNasaProtocol::publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) + { + // Todo + } + Mode nonnasa_mode_to_mode(NonNasaMode value) { switch (value) diff --git a/components/samsung_ac/protocol_non_nasa.h b/components/samsung_ac/protocol_non_nasa.h index 7177e73f..27a3e80e 100644 --- a/components/samsung_ac/protocol_non_nasa.h +++ b/components/samsung_ac/protocol_non_nasa.h @@ -73,7 +73,6 @@ namespace esphome std::string to_string(); }; - struct NonNasaCommandRaw { uint8_t length; @@ -142,6 +141,7 @@ namespace esphome public: NonNasaProtocol() = default; + void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; void publish_power_message(MessageTarget *target, const std::string &address, bool value) override; void publish_target_temp_message(MessageTarget *target, const std::string &address, float value) override; void publish_mode_message(MessageTarget *target, const std::string &address, Mode value) override;