Skip to content

Commit

Permalink
Start impl it
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed Feb 7, 2024
1 parent b7d1678 commit d1edeef
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace esphome
virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0;
};

class ProtocolRequest
struct ProtocolRequest
{
public:
optional<bool> power;
Expand All @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions components/samsung_ac/protocol_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions components/samsung_ac/protocol_nasa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions components/samsung_ac/protocol_non_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion components/samsung_ac/protocol_non_nasa.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ namespace esphome
std::string to_string();
};


struct NonNasaCommandRaw
{
uint8_t length;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d1edeef

Please sign in to comment.