Skip to content

Commit

Permalink
Merge pull request #193 from omerfaruk-aran/fix/horizontal-swing-control
Browse files Browse the repository at this point in the history
Fix: Resolve issues #152, #187, #188 and #192 - Handle both true/false values for swing control and update preset configuration flexibility
  • Loading branch information
lanwin authored Oct 21, 2024
2 parents 24e3a31 + 35d01d2 commit ea9e4f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
25 changes: 17 additions & 8 deletions components/samsung_ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,28 +283,37 @@ async def to_code(config):
# setup capabilities
capabilities = device.get(CONF_CAPABILITIES, config.get(CONF_CAPABILITIES, {}))

if capabilities.get(CONF_CAPABILITIES_VERTICAL_SWING):
cg.add(var_dev.set_supports_vertical_swing(True))
if CONF_CAPABILITIES_VERTICAL_SWING in capabilities:
cg.add(var_dev.set_supports_vertical_swing(capabilities[CONF_CAPABILITIES_VERTICAL_SWING]))

if capabilities.get(CONF_CAPABILITIES_HORIZONTAL_SWING):
cg.add(var_dev.set_supports_horizontal_swing(True))
if CONF_CAPABILITIES_HORIZONTAL_SWING in capabilities:
cg.add(var_dev.set_supports_horizontal_swing(capabilities[CONF_CAPABILITIES_HORIZONTAL_SWING]))

none_added = False
presets = capabilities.get(CONF_PRESETS, {})

for preset, preset_info in PRESETS.items():
preset_conf = presets.get(preset, None)
preset_dict = isinstance(preset_conf, dict)
if preset_conf == True or (preset_dict and preset_conf.get(CONF_PRESET_ENABLED, False)):

if isinstance(preset_conf, bool) and preset_conf:
if not none_added:
none_added = True
cg.add(var_dev.add_alt_mode("None", 0))

cg.add(var_dev.add_alt_mode(
preset_conf.get(CONF_PRESET_NAME, preset_info["displayName"]),
preset_conf.get(CONF_PRESET_VALUE, preset_info["value"])
preset_info["displayName"],
preset_info["value"]
))
elif isinstance(preset_conf, dict) and preset_conf.get(CONF_PRESET_ENABLED, False):
if not none_added:
none_added = True
cg.add(var_dev.add_alt_mode("None", 0))

cg.add(var_dev.add_alt_mode(
preset_conf.get(CONF_PRESET_NAME, preset_info["displayName"]), # Kullanıcı tarafından sağlanan adı kullan
preset_conf.get(CONF_PRESET_VALUE, preset_info["value"]) # Kullanıcı tarafından sağlanan değeri kullan
))

# if CONF_CAPABILITIES in device and CONF_ALT_MODES in device[CONF_CAPABILITIES]:
# cg.add(var_dev.add_alt_mode("None", 0))
# for alt in device[CONF_CAPABILITIES][CONF_ALT_MODES]:
Expand Down
4 changes: 2 additions & 2 deletions components/samsung_ac/samsung_ac_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ namespace esphome
}

protected:
bool supports_horizontal_swing_{true};
bool supports_vertical_swing_{true};
bool supports_horizontal_swing_{false};
bool supports_vertical_swing_{false};
std::vector<AltModeDesc> alt_modes;

Protocol *protocol{nullptr};
Expand Down
16 changes: 8 additions & 8 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ samsung_ac:
# 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.
debug_log_messages: false

# Capabilities configure the features alle devices of your AC system have (all parts of this section are optional).
# Capabilities configure the features that all 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.
# You can override or configure them also on a per devices basis (look below for that).
# You can override or configure them also on a per-device basis (look below for that).
capabilities:
vertical_swing: true
horizontal_swing: true
# Presets define special AC modes like Windfree and so on.
# The following modes are available: sleep, quiet, fast, longreach, windfree, eco
# Presets define special AC modes like Windfree, Eco, and so on.
# The following modes are available: sleep, quiet, fast, longreach, windfree, eco.
presets:
# short version
# Short version - a quick and simple way to enable presets.
quiet: true
# long version - allows to locilize names
quiet:
name: "Makes no sound"
# Long version - allows customization, including localized names and control over enabling the presets.
fast:
name: "Fast cooling"
enabled: true

devices:
Expand Down

0 comments on commit ea9e4f7

Please sign in to comment.