From c53241f4675122d7fd4b3c9b51b524296d2bc69f Mon Sep 17 00:00:00 2001 From: JC Connell Date: Sat, 18 Jan 2025 13:30:06 -1000 Subject: [PATCH 1/3] Add support for Gosund Dimmer SW2 --- .../devices/gosund_SW2_dimmer_switch.yaml | 27 +++++++++++ tests/const.py | 6 +++ .../devices/test_gosund_SW2_dimmer_switch.py | 46 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml create mode 100644 tests/devices/test_gosund_SW2_dimmer_switch.py diff --git a/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml b/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml new file mode 100644 index 0000000000..deb2df3a43 --- /dev/null +++ b/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml @@ -0,0 +1,27 @@ +name: Gosund SW2 Dimmer Switch +products: + - id: qcgkaqmaivuwfwz4 + manufacturer: Gosund + model: SW2-AR +entities: + - entity: light + dps: + - id: 1 + type: boolean + name: switch + optional: true + - id: 3 + type: integer + name: brightness + range: + min: 25 + max: 255 + - entity: binary_sensor + name: Temperature Alarm + icon: "mdi:thermometer-alert" + dps: + - id: 101 + type: boolean + name: sensor + readonly: true + optional: true \ No newline at end of file diff --git a/tests/const.py b/tests/const.py index 7ac9d4686d..15c6f183ad 100644 --- a/tests/const.py +++ b/tests/const.py @@ -683,6 +683,12 @@ "103": "off", } +GOSUND_DUMMER_SWITCH_PAYLOAD = { + "1": True, + "3": 23, + "101": False, +} + CARSON_CB_PAYLOAD = { "1": True, "2": 20, diff --git a/tests/devices/test_gosund_SW2_dimmer_switch.py b/tests/devices/test_gosund_SW2_dimmer_switch.py new file mode 100644 index 0000000000..7fc3f766db --- /dev/null +++ b/tests/devices/test_gosund_SW2_dimmer_switch.py @@ -0,0 +1,46 @@ +"""Tests for the switch entity.""" + +from homeassistant.components.binary_sensor import BinarySensorDeviceClass +from homeassistant.components.switch import SwitchDeviceClass + +from ..const import GOSUND_DUMMER_SWITCH_PAYLOAD +from ..mixins.binary_sensor import BasicBinarySensorTests +from ..mixins.switch import SwitchableTests +from .base_device_tests import TuyaDeviceTestCase + +SWITCH_DPS = "1" +BRIGHTNESS_DPS = "3" +TEMPERATURE_DPS = "101" + + +class TestGosundSwitch( + BasicBinarySensorTests, + SwitchableTests, + TuyaDeviceTestCase, +): + __test__ = True + + def setUp(self): + self.setUpForConfig("gosund_SW2_dimmer_switch.yaml", GOSUND_DUMMER_SWITCH_PAYLOAD) + self.subject = self.entities.get("light") + self.setUpSwitchable(SWITCH_DPS, self.subject) + self.setUpBasicBinarySensor( + TEMPERATURE_DPS, + self.entities.get("binary_sensor_temperature_alarm"), + device_class=BinarySensorDeviceClass.PROBLEM, + ) + + self.mark_secondary(["binary_sensor_temperature_alarm"]) + + def test_device_class_is_light(self): + self.assertEqual(self.subject.device_class, SwitchDeviceClass.LIGHT) + + def test_switch_is_on(self): + self.dps[SWITCH_DPS] = False + self.assertFalse(self.light.is_on) + self.dps[SWITCH_DPS] = True + self.assertTrue(self.light.is_on) + + def test_light_brightness(self): + self.dps[BRIGHTNESS_DPS] = 50 + self.assertAlmostEqual(self.light.brightness, 129, 0) From 844f6761588b59ccf4357b8e2658f943aca14797 Mon Sep 17 00:00:00 2001 From: JC Connell Date: Sat, 18 Jan 2025 13:41:57 -1000 Subject: [PATCH 2/3] change optionals, add details to binary sensor --- .../tuya_local/devices/gosund_SW2_dimmer_switch.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml b/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml index deb2df3a43..6c7dd9c1dc 100644 --- a/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml +++ b/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml @@ -9,7 +9,6 @@ entities: - id: 1 type: boolean name: switch - optional: true - id: 3 type: integer name: brightness @@ -18,10 +17,12 @@ entities: max: 255 - entity: binary_sensor name: Temperature Alarm + class: problem + category: diagnostic icon: "mdi:thermometer-alert" dps: - id: 101 type: boolean name: sensor readonly: true - optional: true \ No newline at end of file + optional: true From 59a0b33c60f3288912597521488903a2353d563c Mon Sep 17 00:00:00 2001 From: JC Connell Date: Sat, 18 Jan 2025 14:31:57 -1000 Subject: [PATCH 3/3] code review changes --- .../devices/gosund_SW2_dimmer_switch.yaml | 8 ++-- tests/const.py | 6 --- .../devices/test_gosund_SW2_dimmer_switch.py | 46 ------------------- 3 files changed, 3 insertions(+), 57 deletions(-) delete mode 100644 tests/devices/test_gosund_SW2_dimmer_switch.py diff --git a/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml b/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml index 6c7dd9c1dc..13479ce509 100644 --- a/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml +++ b/custom_components/tuya_local/devices/gosund_SW2_dimmer_switch.yaml @@ -1,4 +1,4 @@ -name: Gosund SW2 Dimmer Switch +name: Dimmer switch products: - id: qcgkaqmaivuwfwz4 manufacturer: Gosund @@ -16,13 +16,11 @@ entities: min: 25 max: 255 - entity: binary_sensor - name: Temperature Alarm - class: problem + name: Temperature alarm + class: heat category: diagnostic - icon: "mdi:thermometer-alert" dps: - id: 101 type: boolean name: sensor - readonly: true optional: true diff --git a/tests/const.py b/tests/const.py index 15c6f183ad..7ac9d4686d 100644 --- a/tests/const.py +++ b/tests/const.py @@ -683,12 +683,6 @@ "103": "off", } -GOSUND_DUMMER_SWITCH_PAYLOAD = { - "1": True, - "3": 23, - "101": False, -} - CARSON_CB_PAYLOAD = { "1": True, "2": 20, diff --git a/tests/devices/test_gosund_SW2_dimmer_switch.py b/tests/devices/test_gosund_SW2_dimmer_switch.py deleted file mode 100644 index 7fc3f766db..0000000000 --- a/tests/devices/test_gosund_SW2_dimmer_switch.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Tests for the switch entity.""" - -from homeassistant.components.binary_sensor import BinarySensorDeviceClass -from homeassistant.components.switch import SwitchDeviceClass - -from ..const import GOSUND_DUMMER_SWITCH_PAYLOAD -from ..mixins.binary_sensor import BasicBinarySensorTests -from ..mixins.switch import SwitchableTests -from .base_device_tests import TuyaDeviceTestCase - -SWITCH_DPS = "1" -BRIGHTNESS_DPS = "3" -TEMPERATURE_DPS = "101" - - -class TestGosundSwitch( - BasicBinarySensorTests, - SwitchableTests, - TuyaDeviceTestCase, -): - __test__ = True - - def setUp(self): - self.setUpForConfig("gosund_SW2_dimmer_switch.yaml", GOSUND_DUMMER_SWITCH_PAYLOAD) - self.subject = self.entities.get("light") - self.setUpSwitchable(SWITCH_DPS, self.subject) - self.setUpBasicBinarySensor( - TEMPERATURE_DPS, - self.entities.get("binary_sensor_temperature_alarm"), - device_class=BinarySensorDeviceClass.PROBLEM, - ) - - self.mark_secondary(["binary_sensor_temperature_alarm"]) - - def test_device_class_is_light(self): - self.assertEqual(self.subject.device_class, SwitchDeviceClass.LIGHT) - - def test_switch_is_on(self): - self.dps[SWITCH_DPS] = False - self.assertFalse(self.light.is_on) - self.dps[SWITCH_DPS] = True - self.assertTrue(self.light.is_on) - - def test_light_brightness(self): - self.dps[BRIGHTNESS_DPS] = 50 - self.assertAlmostEqual(self.light.brightness, 129, 0)