Kaynağa Gözat

Improve warning log message traceability

Generic messages are difficult to tie back to individual devices.
Log the config file name and the entity to help trace the cause.

Issue #1013
Jason Rumney 2 yıl önce
ebeveyn
işleme
376a97e695

+ 3 - 1
custom_components/tuya_local/binary_sensor.py

@@ -53,7 +53,9 @@ class TuyaLocalBinarySensor(TuyaLocalEntity, BinarySensorEntity):
         except ValueError:
             if dclass:
                 _LOGGER.warning(
-                    "Unrecognised binary_sensor device class of %s ignored",
+                    "%s/%s: Unrecognised binary_sensor device class of %s ignored",
+                    self._config._device.config,
+                    self.name or "binary_sensor",
                     dclass,
                 )
             return None

+ 3 - 1
custom_components/tuya_local/button.py

@@ -48,7 +48,9 @@ class TuyaLocalButton(TuyaLocalEntity, ButtonEntity):
         except ValueError:
             if dclass:
                 _LOGGER.warning(
-                    "Unrecognized button device class of %s ignored",
+                    "%s/%s: Unrecognized button device class of %s ignored",
+                    self._config._device.config,
+                    self.name or "button",
                     dclass,
                 )
 

+ 12 - 2
custom_components/tuya_local/climate.py

@@ -300,7 +300,12 @@ class TuyaLocalClimate(TuyaLocalEntity, ClimateEntity):
         try:
             return HVACAction(action) if action else None
         except ValueError:
-            _LOGGER.warning("Unrecognised HVAC Action %s ignored", action)
+            _LOGGER.warning(
+                "%s/%s: Unrecognised HVAC Action %s ignored",
+                self._config._device.config,
+                self.name or "climate",
+                action,
+            )
             return None
 
     @property
@@ -312,7 +317,12 @@ class TuyaLocalClimate(TuyaLocalEntity, ClimateEntity):
         try:
             return HVACMode(hvac_mode) if hvac_mode else None
         except ValueError:
-            _LOGGER.warning("Unrecognised HVAC Mode of %s ignored", hvac_mode)
+            _LOGGER.warning(
+                "%s/%s: Unrecognised HVAC Mode of %s ignored",
+                self._config._device.config,
+                self.name or "climate",
+                hvac_mode,
+            )
             return None
 
     @property

+ 3 - 1
custom_components/tuya_local/cover.py

@@ -68,7 +68,9 @@ class TuyaLocalCover(TuyaLocalEntity, CoverEntity):
         except ValueError:
             if dclass:
                 _LOGGER.warning(
-                    "Unrecognised cover device class of %s ignored",
+                    "%s/%s: Unrecognised cover device class of %s ignored",
+                    self._config._device.config,
+                    self.name or "cover",
                     dclass,
                 )
             return None

+ 1 - 0
custom_components/tuya_local/device.py

@@ -48,6 +48,7 @@ class TuyaLocalDevice(object):
         Represents a Tuya-based device.
 
         Args:
+            name (str): The device name.
             dev_id (str): The device id.
             address (str): The network address.
             local_key (str): The encryption key.

+ 6 - 2
custom_components/tuya_local/light.py

@@ -80,7 +80,9 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
                     return [mode]
             except ValueError:
                 _LOGGER.warning(
-                    "Unrecognised color mode %s ignored",
+                    "%s/%s: Unrecognised color mode %s ignored",
+                    self._config._device.config,
+                    self.name or "light",
                     self.color_mode,
                 )
         return []
@@ -298,7 +300,9 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
                     val = round(rgbhsv[n] * scale)
                     if val < r["min"]:
                         _LOGGER.warning(
-                            "Color data %s=%d constrained to be above %d",
+                            "%s/%s: Color data %s=%d constrained to be above %d",
+                            self._config._device.config,
+                            self.name or "light",
                             n,
                             val,
                             r["min"],

+ 4 - 1
custom_components/tuya_local/number.py

@@ -60,7 +60,10 @@ class TuyaLocalNumber(TuyaLocalEntity, NumberEntity):
                 return NumberDeviceClass(dclass)
             except ValueError:
                 _LOGGER.warning(
-                    "Unrecognized number device class of %s ignored", dclass
+                    "%s/%s: Unrecognized number device class of %s ignored",
+                    self._config._device.config,
+                    self.name or "number",
+                    dclass,
                 )
 
     @property

+ 4 - 1
custom_components/tuya_local/sensor.py

@@ -56,7 +56,10 @@ class TuyaLocalSensor(TuyaLocalEntity, SensorEntity):
                 return SensorDeviceClass(dclass)
             except ValueError:
                 _LOGGER.warning(
-                    "Unrecognized sensor device class of %s ignored", dclass
+                    "%s/%s: Unrecognized sensor device class of %s ignored",
+                    self._config._device.config,
+                    self.name or "sensor",
+                    dclass,
                 )
 
     @property