From 9269ae69a7389bf7c9c47af6d65539ea42d38eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sat, 19 Oct 2024 14:45:42 +0300 Subject: [PATCH 1/4] Fix: Handle both true and false values for horizontal and vertical swing control --- components/samsung_ac/__init__.py | 8 ++++---- components/samsung_ac/samsung_ac_device.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index d0238013..d39f7f89 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -283,11 +283,11 @@ 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, {}) diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index f18894c5..ec487e72 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -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 alt_modes; Protocol *protocol{nullptr}; From f6ac302546a9034b8729ea439e95686797b20fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sat, 19 Oct 2024 17:09:04 +0300 Subject: [PATCH 2/4] Support both short and long forms for presets in yaml --- components/samsung_ac/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index d39f7f89..89a7d1b4 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -294,17 +294,26 @@ async def to_code(config): 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]: From e9baae302b7a302bfcf7f82b0e33560984ad7666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sat, 19 Oct 2024 17:17:20 +0300 Subject: [PATCH 3/4] Updated example.yaml to include both short and long form preset configurations --- example.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/example.yaml b/example.yaml index 41d5ba4d..563a95b2 100644 --- a/example.yaml +++ b/example.yaml @@ -62,21 +62,26 @@ 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 + fast: true + + # Long version - allows customization, including localized names and control over enabling the presets. quiet: name: "Makes no sound" enabled: true + fast: + name: "Fast cooling" + enabled: true devices: # Skip everything below on the first run! Wait a minute, watch your ESPHome logs until you see the "Discovered devices:" section and you see some addresses: From 35d01d2ea51558285a811166e1927a5ee6b6d9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sat, 19 Oct 2024 17:29:29 +0300 Subject: [PATCH 4/4] Updated example.yaml to include both short and long form preset configurations --- example.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/example.yaml b/example.yaml index 563a95b2..0d0c32a0 100644 --- a/example.yaml +++ b/example.yaml @@ -73,12 +73,7 @@ samsung_ac: presets: # Short version - a quick and simple way to enable presets. quiet: true - fast: true - # Long version - allows customization, including localized names and control over enabling the presets. - quiet: - name: "Makes no sound" - enabled: true fast: name: "Fast cooling" enabled: true