From c9e130e19744794c442bca8113d1fab730eb03d3 Mon Sep 17 00:00:00 2001
From: Johnny Willemsen <jwillemsen@remedy.nl>
Date: Thu, 28 Nov 2024 10:34:44 +0100
Subject: [PATCH] Test duplicate setting

    * custom_components/daikin_onecta/climate.py:
    * tests/test_init.py:
---
 custom_components/daikin_onecta/climate.py |  2 ++
 tests/test_init.py                         | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/custom_components/daikin_onecta/climate.py b/custom_components/daikin_onecta/climate.py
index 56e58e8..9ea3743 100644
--- a/custom_components/daikin_onecta/climate.py
+++ b/custom_components/daikin_onecta/climate.py
@@ -649,6 +649,7 @@ async def __set_swing(self, direction, swing_mode):
         return res
 
     async def async_set_swing_mode(self, swing_mode):
+        res = True
         if self.swing_mode != swing_mode:
             res = await self.__set_swing("vertical", swing_mode)
 
@@ -665,6 +666,7 @@ async def async_set_swing_mode(self, swing_mode):
         return res
 
     async def async_set_swing_horizontal_mode(self, swing_mode):
+        res = True
         if self.swing_horizontal_mode != swing_mode:
             res = await self.__set_swing("horizontal", swing_mode)
 
diff --git a/tests/test_init.py b/tests/test_init.py
index 4225742..e287649 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -836,6 +836,26 @@ async def test_climate(
         assert hass.states.get("climate.werkkamer_room_temperature").attributes["swing_horizontal_mode"] == "swing"
         assert hass.states.get("climate.werkkamer_room_temperature").attributes["swing_mode"] == "swing"
 
+        # Set the horizontal swing mode another time to swing, should not result in a call
+        await hass.services.async_call(
+            CLIMATE_DOMAIN,
+            SERVICE_SET_SWING_HORIZONTAL_MODE,
+            {ATTR_ENTITY_ID: "climate.werkkamer_room_temperature", ATTR_SWING_HORIZONTAL_MODE: "swing"},
+            blocking=True,
+        )
+        await hass.async_block_till_done()
+
+        # Set the vertical swing mode another time to swing, should not result in a call
+        await hass.services.async_call(
+            CLIMATE_DOMAIN,
+            SERVICE_SET_SWING_MODE,
+            {ATTR_ENTITY_ID: "climate.werkkamer_room_temperature", ATTR_SWING_MODE: "swing"},
+            blocking=True,
+        )
+        await hass.async_block_till_done()
+
+        assert len(responses.calls) == 15
+
         # Set the preset mode boost
         await hass.services.async_call(
             CLIMATE_DOMAIN,