Skip to content

Commit

Permalink
Resolved conflicts, fixed indentation, renamed log parameters, implem…
Browse files Browse the repository at this point in the history
…ented debug_log_messages functionality, and corrected repository source address in the YAML file.
  • Loading branch information
omerfaruk-aran committed Aug 14, 2024
1 parent 988eeba commit 74fb700
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 182 deletions.
13 changes: 4 additions & 9 deletions components/samsung_ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ def humidity_sensor_schema(message: int):

CONF_NON_NASA_KEEPALIVE = "non_nasa_keepalive"

CONF_LOG_UNDEFINED_MESSAGES = "log_undefined_messages"
CONF_DEBUG_LOG_UNDEFINED_MESSAGES = "debug_log_undefined_messages"

CONF_LOG_MESSAGES = "log_messages"

CONFIG_SCHEMA = (
cv.Schema(
Expand All @@ -244,8 +243,7 @@ def humidity_sensor_schema(message: int):
cv.Optional(CONF_DEBUG_LOG_MESSAGES, default=False): cv.boolean,
cv.Optional(CONF_DEBUG_LOG_MESSAGES_RAW, default=False): cv.boolean,
cv.Optional(CONF_NON_NASA_KEEPALIVE, default=False): cv.boolean,
cv.Optional(CONF_LOG_UNDEFINED_MESSAGES, default=False): cv.boolean,
cv.Optional(CONF_LOG_MESSAGES, default=False): cv.boolean,
cv.Optional(CONF_DEBUG_LOG_UNDEFINED_MESSAGES, default=False): cv.boolean,
cv.Optional(CONF_CAPABILITIES): CAPABILITIES_SCHEMA,
cv.Required(CONF_DEVICES): cv.ensure_list(DEVICE_SCHEMA),
}
Expand Down Expand Up @@ -425,11 +423,8 @@ async def to_code(config):
if (CONF_NON_NASA_KEEPALIVE in config):
cg.add(var.set_non_nasa_keepalive(config[CONF_NON_NASA_KEEPALIVE]))

if (CONF_LOG_UNDEFINED_MESSAGES in config):
cg.add(var.set_log_undefined_messages(config[CONF_LOG_UNDEFINED_MESSAGES]))

if (CONF_LOG_MESSAGES in config):
cg.add(var.set_log_messages(config[CONF_LOG_MESSAGES]))
if (CONF_DEBUG_LOG_UNDEFINED_MESSAGES in config):
cg.add(var.set_debug_log_undefined_messages(config[CONF_DEBUG_LOG_UNDEFINED_MESSAGES]))

await cg.register_component(var, config)
await uart.register_uart_device(var, config)
2 changes: 1 addition & 1 deletion components/samsung_ac/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace esphome
}
}

optional<climate::ClimatePreset> altmodename_to_preset(const AltModeName& name)
optional<climate::ClimatePreset> altmodename_to_preset(const AltModeName &name)
{
if (str_equals_case_insensitive(name, "ECO"))
return optional<climate::ClimatePreset>(climate::CLIMATE_PRESET_ECO);
Expand Down
2 changes: 1 addition & 1 deletion components/samsung_ac/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace esphome
FanMode customfanmode_to_fanmode(const std::string &value);

AltModeName preset_to_altmodename(climate::ClimatePreset preset);
optional<climate::ClimatePreset> altmodename_to_preset(const AltModeName& name);
optional<climate::ClimatePreset> altmodename_to_preset(const AltModeName &name);

climate::ClimateSwingMode swingmode_to_climateswingmode(SwingMode swingMode);
SwingMode climateswingmode_to_swingmode(climate::ClimateSwingMode swingMode);
Expand Down
3 changes: 1 addition & 2 deletions components/samsung_ac/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace esphome
bool debug_log_packets = false;
bool debug_log_raw_bytes = false;
bool non_nasa_keepalive = false;
bool log_undefined_messages = false;
bool log_messages = false;
bool debug_log_undefined_messages = false;
ProtocolProcessing protocol_processing = ProtocolProcessing::Auto;

// This functions is designed to run after a new value was added
Expand Down
3 changes: 1 addition & 2 deletions components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace esphome
extern bool debug_log_packets;
extern bool debug_log_raw_bytes;
extern bool non_nasa_keepalive;
extern bool log_undefined_messages;
extern bool log_messages;
extern bool debug_log_undefined_messages;

enum class DecodeResult
{
Expand Down
311 changes: 188 additions & 123 deletions components/samsung_ac/protocol_nasa.cpp

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions components/samsung_ac/protocol_non_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,39 +554,39 @@ namespace esphome
item.request.fanspeed == nonpacket_.command20.fanspeed &&
item.request.mode == nonpacket_.command20.mode &&
item.request.power == nonpacket_.command20.power; });

// If a state update comes through after a control message has been sent, but before it
// has been acknowledged, it should be ignored. This prevents the UI status bouncing
// between states after a command has been issued.
bool pending_control_message = false;
for (auto& item : nonnasa_requests)
for (auto &item : nonnasa_requests)
{
if (item.time_sent > 0 && nonpacket_.src == item.request.dst)
{
pending_control_message = true;
break;
}
if (item.time_sent > 0 && nonpacket_.src == item.request.dst)
{
pending_control_message = true;
break;
}
}

if (!pending_control_message)
{
last_command20s_[nonpacket_.src] = nonpacket_.command20;
target->set_target_temperature(nonpacket_.src, nonpacket_.command20.target_temp);
// TODO
target->set_water_outlet_target(nonpacket_.src, false);
// TODO
target->set_target_water_temperature(nonpacket_.src, false);
target->set_room_temperature(nonpacket_.src, nonpacket_.command20.room_temp);
target->set_power(nonpacket_.src, nonpacket_.command20.power);
// TODO
target->set_water_heater_power(nonpacket_.src, false);
target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode));
target->set_fanmode(nonpacket_.src, nonnasa_fanspeed_to_fanmode(nonpacket_.command20.fanspeed));
// TODO
target->set_altmode(nonpacket_.src, 0);
// TODO
target->set_swing_horizontal(nonpacket_.src, false);
target->set_swing_vertical(nonpacket_.src, false);
last_command20s_[nonpacket_.src] = nonpacket_.command20;
target->set_target_temperature(nonpacket_.src, nonpacket_.command20.target_temp);
// TODO
target->set_water_outlet_target(nonpacket_.src, false);
// TODO
target->set_target_water_temperature(nonpacket_.src, false);
target->set_room_temperature(nonpacket_.src, nonpacket_.command20.room_temp);
target->set_power(nonpacket_.src, nonpacket_.command20.power);
// TODO
target->set_water_heater_power(nonpacket_.src, false);
target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode));
target->set_fanmode(nonpacket_.src, nonnasa_fanspeed_to_fanmode(nonpacket_.command20.fanspeed));
// TODO
target->set_altmode(nonpacket_.src, 0);
// TODO
target->set_swing_horizontal(nonpacket_.src, false);
target->set_swing_vertical(nonpacket_.src, false);
}
}
else if (nonpacket_.cmd == NonNasaCommand::CmdC6)
Expand Down
10 changes: 3 additions & 7 deletions components/samsung_ac/samsung_ac.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,9 @@ namespace esphome
{
non_nasa_keepalive = value;
}
void set_log_undefined_messages (bool value)
void set_debug_log_undefined_messages(bool value)
{
log_undefined_messages = value;
}
void set_log_messages (bool value)
{
log_messages = value;
debug_log_undefined_messages = value;
}
void register_device(Samsung_AC_Device *device);

Expand Down Expand Up @@ -107,7 +103,7 @@ void set_log_undefined_messages (bool value)
if (dev != nullptr)
dev->update_target_temperature(value);
}

void /*MessageTarget::*/ set_water_outlet_target(const std::string address, float value) override
{
Samsung_AC_Device *dev = find_device(address);
Expand Down
20 changes: 10 additions & 10 deletions components/samsung_ac/samsung_ac_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ namespace esphome
std::string address;
sensor::Sensor *room_temperature{nullptr};
sensor::Sensor *outdoor_temperature{nullptr};
sensor::Sensor *indoor_eva_in_temperature{nullptr};
sensor::Sensor *indoor_eva_out_temperature{nullptr};
sensor::Sensor *indoor_eva_in_temperature{nullptr};
sensor::Sensor *indoor_eva_out_temperature{nullptr};
Samsung_AC_Number *target_temperature{nullptr};
Samsung_AC_Number *water_outlet_target{nullptr};
Samsung_AC_Number *target_water_temperature{nullptr};
Expand All @@ -109,12 +109,12 @@ namespace esphome

void set_outdoor_temperature_sensor(sensor::Sensor *sensor)
{
outdoor_temperature = sensor;
outdoor_temperature = sensor;
}

void set_indoor_eva_in_temperature_sensor(sensor::Sensor *sensor)
{
indoor_eva_in_temperature = sensor;
indoor_eva_in_temperature = sensor;
}

void set_indoor_eva_out_temperature_sensor(sensor::Sensor *sensor)
Expand Down Expand Up @@ -148,8 +148,8 @@ namespace esphome
publish_request(request);
};
}
void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_)

void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_)
{
automatic_cleaning = switch_;
automatic_cleaning->write_state_ = [this](bool value)
Expand Down Expand Up @@ -192,7 +192,7 @@ void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_)
publish_request(request);
};
};

void set_water_outlet_target_number(Samsung_AC_Number *number)
{
water_outlet_target = number;
Expand Down Expand Up @@ -231,7 +231,7 @@ void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_)
climate->publish_state();
}
}

void update_water_outlet_target(float value)
{
if (water_outlet_target != nullptr)
Expand All @@ -257,8 +257,8 @@ void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_)
if (climate != nullptr)
calc_and_publish_mode();
}
void update_automatic_cleaning(bool value)

void update_automatic_cleaning(bool value)
{
_cur_automatic_cleaning = value;
if (automatic_cleaning != nullptr)
Expand Down
6 changes: 3 additions & 3 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ uart:

# Import custom component from GitHub
external_components:
- source: github://omerfaruk-aran/esphome_samsung_ac@new_test # use @main if you want the latest development (possibly unstable?)
- source: github://omerfaruk-aran/esphome_samsung_ac@main # use @main if you want the latest development (possibly unstable?)
components: [samsung_ac]

# Configuration of AC component
Expand All @@ -58,10 +58,10 @@ samsung_ac:
non_nasa_keepalive: true

#When enabled (set to true), this option will log the messages associated with undefined codes on the device. This is useful for debugging and identifying any unexpected or unknown codes that the device may receive during operation.
log_undefined_messages: false
debug_log_undefined_messages: false

#When enabled (set to true), this option logs messages associated with defined codes on the device. This helps in monitoring the behavior of the device by recording the activity related to known, expected codes.
log_messages: false
debug_log_messages: false

# Capabilities configure the features alle devices of your AC system have (all parts of this section are optional).
# All capabilities are off by default, you need to enable only those your devices have.
Expand Down

0 comments on commit 74fb700

Please sign in to comment.