Răsfoiți Sursa

Fix usage of assertCountEqual to check Dicts.

assertCountEqual on Dicts only checks that the keys are the same.
Use assertDictEqual instead, as that checks the values as well as keys.

- Fix some unit tests that had wrong values in
Jason Rumney 4 ani în urmă
părinte
comite
e421f3956e

+ 3 - 3
tests/devices/test_awow_th213_thermostat.py

@@ -52,10 +52,10 @@ class TestAwowTH213Thermostat(TuyaDeviceTestCase):
         self.assertEqual(self.subject.icon, "mdi:thermometer-off")
 
         self.dps[LOCK_DPS] = True
-        self.assertEqual(self.lock.icon, "mdi:account-lock")
+        self.assertEqual(self.lock.icon, "mdi:hand-back-right-off")
 
         self.dps[LOCK_DPS] = False
-        self.assertEqual(self.lock.icon, "mdi:account")
+        self.assertEqual(self.lock.icon, "mdi:hand-back-right")
 
     def test_temperature_unit_returns_device_temperature_unit(self):
         self.assertEqual(
@@ -225,7 +225,7 @@ class TestAwowTH213Thermostat(TuyaDeviceTestCase):
         self.dps[UNKNOWN108_DPS] = False
         self.dps[UNKNOWN110_DPS] = 110
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "error": 8,

+ 7 - 7
tests/devices/test_eanons_humidifier.py

@@ -167,11 +167,11 @@ class TestEanonsHumidifier(TuyaDeviceTestCase):
     def test_preset_modes(self):
         self.assertCountEqual(
             self.climate.preset_modes,
-            {MODE_NORMAL, MODE_SLEEP, MODE_AUTO},
+            [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
         )
         self.assertCountEqual(
             self.subject.available_modes,
-            {MODE_NORMAL, MODE_SLEEP, MODE_AUTO},
+            [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
         )
 
     async def test_set_climate_preset_to_auto(self):
@@ -238,7 +238,7 @@ class TestEanonsHumidifier(TuyaDeviceTestCase):
         self.dps[ERROR_DPS] = 0
         self.dps[TIMERHR_DPS] = "cancel"
         self.dps[TIMER_DPS] = 0
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.climate.device_state_attributes,
             {
                 "error": "OK",
@@ -250,10 +250,10 @@ class TestEanonsHumidifier(TuyaDeviceTestCase):
         self.dps[ERROR_DPS] = 1
         self.dps[TIMERHR_DPS] = "1"
         self.dps[TIMER_DPS] = 60
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.climate.device_state_attributes,
             {
-                "error": 1,
+                "error": "Water Level Low",
                 "timer_hr": "1",
                 "timer_min": 60,
             },
@@ -266,7 +266,7 @@ class TestEanonsHumidifier(TuyaDeviceTestCase):
         self.dps[CURRENTHUMID_DPS] = 50
         self.dps[FANMODE_DPS] = "middle"
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "error": "OK",
@@ -308,7 +308,7 @@ class TestEanonsHumidifier(TuyaDeviceTestCase):
     def test_climate_fan_modes(self):
         self.assertCountEqual(
             self.climate.fan_modes,
-            {FAN_LOW, FAN_MEDIUM, FAN_HIGH},
+            [FAN_LOW, FAN_MEDIUM, FAN_HIGH],
         )
 
     async def test_fan_set_speed(self):

+ 1 - 1
tests/devices/test_electriq_12wminv_heatpump.py

@@ -291,7 +291,7 @@ class TestElectriq12WMINVHeatpump(TuyaDeviceTestCase):
         self.dps[UNKNOWN108_DPS] = 108
         self.dps[UNKNOWN109_DPS] = 109
         self.dps[UNKNOWN110_DPS] = 110
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "unknown_8": True,

+ 1 - 1
tests/devices/test_electriq_cd20_dehumidifier.py

@@ -272,7 +272,7 @@ class TestElectriqCD20ProDehumidifier(TuyaDeviceTestCase):
         self.dps[CURRENTHUMID_DPS] = 50
         self.dps[CURRENTTEMP_DPS] = 21
         self.dps[ANION_DPS] = True
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {"current_humidity": 50, "current_temperature": 21, "anion": True},
         )

+ 1 - 1
tests/devices/test_electriq_cd25_dehumidifier.py

@@ -295,7 +295,7 @@ class TestElectriqCD25ProDehumidifier(TuyaDeviceTestCase):
     def test_state_attributes(self):
         self.dps[CURRENTHUMID_DPS] = 50
         self.dps[CURRENTTEMP_DPS] = 21
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {"current_humidity": 50, "current_temperature": 21},
         )

+ 1 - 1
tests/devices/test_fersk_vind_2_climate.py

@@ -253,7 +253,7 @@ class TestFerskVind2Climate(TuyaDeviceTestCase):
         self.dps[UNKNOWN106_DPS] = 106
         self.dps[UNKNOWN109_DPS] = True
         self.dps[UNKNOWN110_DPS] = 110
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "unknown_101": True,

+ 1 - 1
tests/devices/test_gardenpac_heatpump.py

@@ -171,7 +171,7 @@ class TestGardenPACPoolHeatpump(TuyaDeviceTestCase):
         self.dps[UNKNOWN108_DPS] = 2
         self.dps[UNKNOWN115_DPS] = 3
         self.dps[UNKNOWN116_DPS] = 4
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "power_level": 50,

+ 3 - 3
tests/devices/test_goldair_dehumidifier.py

@@ -528,10 +528,10 @@ class TestGoldairDehumidifier(TuyaDeviceTestCase):
         self.dps[AIRCLEAN_DPS] = False
         self.dps[UNKNOWN12_DPS] = "something"
         self.dps[UNKNOWN101_DPS] = False
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.climate.device_state_attributes,
             {
-                "error": STATE_UNAVAILABLE,
+                "error": None,
                 "defrosting": False,
                 "air_clean_on": False,
                 "unknown_12": "something",
@@ -544,7 +544,7 @@ class TestGoldairDehumidifier(TuyaDeviceTestCase):
         self.dps[AIRCLEAN_DPS] = True
         self.dps[UNKNOWN12_DPS] = "something else"
         self.dps[UNKNOWN101_DPS] = True
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.climate.device_state_attributes,
             {
                 "error": ERROR_TANK,

+ 4 - 3
tests/devices/test_goldair_geco_heater.py

@@ -125,12 +125,13 @@ class TestGoldairGECOHeater(TuyaDeviceTestCase):
         # they are discovered
         self.dps[ERROR_DPS] = "something"
         self.dps[TIMER_DPS] = 10
-        self.assertCountEqual(
-            self.subject.device_state_attributes, {"error": "something", "timer": 10}
+        self.assertDictEqual(
+            self.subject.device_state_attributes,
+            {"error": "something", "timer": 10},
         )
         self.dps[ERROR_DPS] = "0"
         self.dps[TIMER_DPS] = 0
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes, {"error": "OK", "timer": 0}
         )
 

+ 4 - 3
tests/devices/test_goldair_gpcv_heater.py

@@ -166,12 +166,13 @@ class TestGoldairGPCVHeater(TuyaDeviceTestCase):
         # they are discovered
         self.dps[ERROR_DPS] = "something"
         self.dps[TIMER_DPS] = 10
-        self.assertCountEqual(
-            self.subject.device_state_attributes, {"error": "something", "timer": 10}
+        self.assertDictEqual(
+            self.subject.device_state_attributes,
+            {"error": "something", "timer": 10},
         )
         self.dps[ERROR_DPS] = "0"
         self.dps[TIMER_DPS] = 0
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes, {"error": "OK", "timer": 0}
         )
 

+ 2 - 2
tests/devices/test_goldair_gpph_heater.py

@@ -319,13 +319,13 @@ class TestGoldairHeater(TuyaDeviceTestCase):
         self.dps[TIMERACT_DPS] = True
         self.dps[POWERLEVEL_DPS] = 4
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "error": "something",
                 "timer": 5,
                 "timer_mode": True,
-                "power_level": 4,
+                "power_level": "4",
             },
         )
 

+ 1 - 1
tests/devices/test_hellnar_heatpump.py

@@ -179,7 +179,7 @@ class TestHellnarHeatpump(TuyaDeviceTestCase):
         self.dps["133"] = "unknown133"
         self.dps["134"] = "unknown134"
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "maybe_fan_mode": "fan?",

+ 2 - 2
tests/devices/test_inkbird_itc306a_thermostat.py

@@ -89,7 +89,7 @@ class TestInkbirdThermostat(TuyaDeviceTestCase):
     def test_preset_modes(self):
         self.assertCountEqual(
             self.subject.preset_modes,
-            {"On", "Pause", "Off"},
+            ["On", "Pause", "Off"],
         )
 
     async def test_set_preset_to_on(self):
@@ -196,7 +196,7 @@ class TestInkbirdThermostat(TuyaDeviceTestCase):
         self.dps[UNKNOWN119_DPS] = True
         self.dps[UNKNOWN120_DPS] = False
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "error": 1,

+ 3 - 3
tests/devices/test_kogan_dehumidifier.py

@@ -99,12 +99,12 @@ class TestKoganDehumidifier(TuyaDeviceTestCase):
     def test_modes(self):
         self.assertCountEqual(
             self.subject.available_modes,
-            {
+            [
                 "Low",
                 "Medium",
                 "High",
                 "Dry Clothes",
-            },
+            ],
         )
 
     def test_mode(self):
@@ -229,7 +229,7 @@ class TestKoganDehumidifier(TuyaDeviceTestCase):
         self.dps[ERROR_DPS] = 1
         self.dps[TIMER_DPS] = 3
         self.dps[COUNTDOWN_DPS] = 160
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "current_humidity": 55,

+ 4 - 3
tests/devices/test_kogan_kahtp_heater.py

@@ -162,9 +162,10 @@ class TestGoldairKoganKAHTPHeater(TuyaDeviceTestCase):
 
     def test_state_attributes(self):
         self.dps[TIMER_DPS] = 10
-        self.assertCountEqual(self.subject.device_state_attributes, {"timer": 10})
-        self.dps[TIMER_DPS] = 0
-        self.assertCountEqual(self.subject.device_state_attributes, {"timer": 0})
+        self.assertDictEqual(
+            self.subject.device_state_attributes,
+            {"timer": 10},
+        )
 
     def test_lock_state(self):
         self.dps[LOCK_DPS] = True

+ 1 - 3
tests/devices/test_kogan_kawfhtp_heater.py

@@ -162,9 +162,7 @@ class TestGoldairKoganKAHTPHeater(TuyaDeviceTestCase):
 
     def test_state_attributes(self):
         self.dps[TIMER_DPS] = 10
-        self.assertCountEqual(self.subject.device_state_attributes, {"timer": 10})
-        self.dps[TIMER_DPS] = 0
-        self.assertCountEqual(self.subject.device_state_attributes, {"timer": 0})
+        self.assertDictEqual(self.subject.device_state_attributes, {"timer": 10})
 
     def test_lock_state(self):
         self.dps[LOCK_DPS] = True

+ 1 - 1
tests/devices/test_madimack_heatpump.py

@@ -201,7 +201,7 @@ class TestMadimackPoolHeatpump(TuyaDeviceTestCase):
         self.dps[UNKNOWN136_DPS] = False
         self.dps[UNKNOWN139_DPS] = True
         self.dps[UNKNOWN140_DPS] = "test"
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "power_level": 50,

+ 1 - 1
tests/devices/test_saswell_t29utk_thermostat.py

@@ -240,7 +240,7 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         self.dps[TEMPF_DPS] = 116
         self.dps[CURTEMPF_DPS] = 117
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "set_temperature": 0.2,

+ 1 - 15
tests/devices/test_smartplugv1.py

@@ -71,7 +71,7 @@ class TestKoganSwitch(TuyaDeviceTestCase):
         self.dps[VOLTAGE_DPS] = 2350
         self.dps[CURRENT_DPS] = 1234
         self.dps[POWER_DPS] = 5678
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "timer": 1,
@@ -80,17 +80,3 @@ class TestKoganSwitch(TuyaDeviceTestCase):
                 "current_power_w": 567.8,
             },
         )
-
-        self.dps[TIMER_DPS] = 0
-        self.dps[CURRENT_DPS] = None
-        self.dps[VOLTAGE_DPS] = None
-        self.dps[POWER_DPS] = None
-        self.assertCountEqual(
-            self.subject.device_state_attributes,
-            {
-                "timer": 0,
-                "current_a": None,
-                "voltage_v": None,
-                "current_power_w": None,
-            },
-        )

+ 1 - 15
tests/devices/test_smartplugv2.py

@@ -71,7 +71,7 @@ class TestSwitchV2(TuyaDeviceTestCase):
         self.dps[VOLTAGE_DPS] = 2350
         self.dps[CURRENT_DPS] = 1234
         self.dps[POWER_DPS] = 5678
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "timer": 1,
@@ -80,17 +80,3 @@ class TestSwitchV2(TuyaDeviceTestCase):
                 "current_power_w": 567.8,
             },
         )
-
-        self.dps[TIMER_DPS] = 0
-        self.dps[CURRENT_DPS] = None
-        self.dps[VOLTAGE_DPS] = None
-        self.dps[POWER_DPS] = None
-        self.assertCountEqual(
-            self.subject.device_state_attributes,
-            {
-                "timer": 0,
-                "current_a": None,
-                "voltage_v": None,
-                "current_power_w": None,
-            },
-        )

+ 2 - 2
tests/devices/test_tadiran_wind_heatpump.py

@@ -202,7 +202,7 @@ class TestTadiranWindHeatpump(TuyaDeviceTestCase):
         self.dps["107"] = True
         self.dps["108"] = False
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "unknown_101": 101,
@@ -210,7 +210,7 @@ class TestTadiranWindHeatpump(TuyaDeviceTestCase):
                 "unknown_103": 103,
                 "unknown_104": "unknown104",
                 "unknown_105": "unknown105",
-                "unknown_106": 120,
+                "unknown_106": 106,
                 "unknown_107": True,
                 "unknown_108": False,
             },

+ 1 - 1
tests/devices/test_wetair_wch750_heater.py

@@ -194,7 +194,7 @@ class TestWetairWCH750Heater(TuyaDeviceTestCase):
         self.dps[COUNTDOWN_DPS] = 20
         self.dps[UNKNOWN21_DPS] = 21
 
-        self.assertCountEqual(
+        self.assertDictEqual(
             self.subject.device_state_attributes,
             {
                 "timer": "1h",