Просмотр исходного кода

Fix non-complexity related SonarCloud warnings

- Don't shadow builtin range with local variable names
- Don't create unused device (just call the function for side effect).
Jason Rumney 4 лет назад
Родитель
Сommit
04794b349e

+ 1 - 1
custom_components/tuya_local/__init__.py

@@ -67,7 +67,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
     _LOGGER.debug(f"Setting up entry for device: {entry.data[CONF_DEVICE_ID]}")
     config = {**entry.data, **entry.options, "name": entry.title}
-    device = setup_device(hass, config)
+    setup_device(hass, config)
 
     if config.get(CONF_CLIMATE, False) is True:
         hass.async_create_task(

+ 8 - 8
custom_components/tuya_local/generic/climate.py

@@ -191,16 +191,16 @@ class TuyaLocalClimate(ClimateEntity):
         """Return the minimum supported target temperature."""
         if self._temperature_dps is None:
             return None
-        range = self._temperature_dps.range(self._device)
-        return DEFAULT_MIN_TEMP if range is None else range["min"]
+        r = self._temperature_dps.range(self._device)
+        return DEFAULT_MIN_TEMP if r is None else r["min"]
 
     @property
     def max_temp(self):
         """Return the maximum supported target temperature."""
         if self._temperature_dps is None:
             return None
-        range = self._temperature_dps.range(self._device)
-        return DEFAULT_MAX_TEMP if range is None else range["max"]
+        r = self._temperature_dps.range(self._device)
+        return DEFAULT_MAX_TEMP if r is None else r["max"]
 
     async def async_set_temperature(self, **kwargs):
         """Set new target temperature."""
@@ -248,16 +248,16 @@ class TuyaLocalClimate(ClimateEntity):
         """Return the minimum supported target humidity."""
         if self._humidity_dps is None:
             return None
-        range = self._humidity_dps.range(self._device)
-        return DEFAULT_MIN_HUMIDITY if range is None else range["min"]
+        r = self._humidity_dps.range(self._device)
+        return DEFAULT_MIN_HUMIDITY if r is None else r["min"]
 
     @property
     def max_humidity(self):
         """Return the maximum supported target humidity."""
         if self._humidity_dps is None:
             return None
-        range = self._humidity_dps.range(self._device)
-        return DEFAULT_MAX_HUMIDITY if range is None else range["max"]
+        r = self._humidity_dps.range(self._device)
+        return DEFAULT_MAX_HUMIDITY if r is None else r["max"]
 
     async def async_set_humidity(self, target_humidity):
         if self._humidity_dps is None:

+ 4 - 4
custom_components/tuya_local/generic/humidifier.py

@@ -126,16 +126,16 @@ class TuyaLocalHumidifier(HumidifierEntity):
         """Return the minimum supported target humidity."""
         if self._humidity_dps is None:
             return None
-        range = self._humidity_dps.range(self._device)
-        return DEFAULT_MIN_HUMIDITY if range is None else range["min"]
+        r = self._humidity_dps.range(self._device)
+        return DEFAULT_MIN_HUMIDITY if r is None else r["min"]
 
     @property
     def max_humidity(self):
         """Return the maximum supported target humidity."""
         if self._humidity_dps is None:
             return None
-        range = self._humidity_dps.range(self._device)
-        return DEFAULT_MAX_HUMIDITY if range is None else range["max"]
+        r = self._humidity_dps.range(self._device)
+        return DEFAULT_MAX_HUMIDITY if r is None else r["max"]
 
     async def async_set_humidity(self, humidity):
         if self._humidity_dps is None:

+ 14 - 14
custom_components/tuya_local/helpers/device_config.py

@@ -253,17 +253,17 @@ class TuyaDpsConfig:
             if cond is not None:
                 constraint = mapping.get("constraint")
                 _LOGGER.debug(f"Considering condition on {constraint}")
-            range = None if cond is None else cond.get("range")
-            if range is not None and "min" in range and "max" in range:
+            r = None if cond is None else cond.get("range")
+            if r is not None and "min" in r and "max" in r:
                 _LOGGER.info(f"Conditional range returned for {self.name}")
-                return range
-            range = mapping.get("range")
-            if range is not None and "min" in range and "max" in range:
+                return r
+            r = mapping.get("range")
+            if r is not None and "min" in r and "max" in r:
                 _LOGGER.info(f"Mapped range returned for {self.name}")
-                return range
-        range = self._config.get("range")
-        if range is not None and "min" in range and "max" in range:
-            return range
+                return r
+        r = self._config.get("range")
+        if r is not None and "min" in r and "max" in r:
+            return r
         else:
             return None
 
@@ -445,13 +445,13 @@ class TuyaDpsConfig:
                     value,
                 )
 
-        range = self.range(device)
-        if range is not None:
-            minimum = range["min"]
-            maximum = range["max"]
+        r = self.range(device)
+        if r is not None:
+            minimum = r["min"]
+            maximum = r["max"]
             if result < minimum or result > maximum:
                 raise ValueError(
-                    f"{self.name} ({value}) must be between " f"{minimum} and {maximum}"
+                    f"{self.name} ({value}) must be between {minimum} and {maximum}"
                 )
 
         if self.type is int: