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

Use device class for translation key where not explicitly overridden.

When translations were first added, it seemed that device class was
designed to be used by default.  But at least for name, this does not
seem automatic.

Use config_id rather than name in error messages, as name is more
frequently blank now.

Issue #871
Jason Rumney 2 лет назад
Родитель
Сommit
25fb43a984

+ 1 - 1
custom_components/tuya_local/alarm_control_panel.py

@@ -53,7 +53,7 @@ class TuyaLocalAlarmControlPanel(TuyaLocalEntity, AlarmControlPanelEntity):
 
         self._init_end(dps_map)
         if not self._alarm_state_dp:
-            raise AttributeError(f"{config.name} is missing an alarm_state dp")
+            raise AttributeError(f"{config.config_id} is missing an alarm_state dp")
 
         alarm_states = self._alarm_state_dp.values(device)
         if STATE_ALARM_ARMED_HOME in alarm_states:

+ 1 - 1
custom_components/tuya_local/binary_sensor.py

@@ -41,7 +41,7 @@ class TuyaLocalBinarySensor(TuyaLocalEntity, BinarySensorEntity):
         dps_map = self._init_begin(device, config)
         self._sensor_dps = dps_map.pop("sensor")
         if self._sensor_dps is None:
-            raise AttributeError(f"{config.name} is missing a sensor dps")
+            raise AttributeError(f"{config.config_id} is missing a sensor dps")
         self._init_end(dps_map)
 
     @property

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

@@ -231,7 +231,7 @@ class TuyaEntityConfig:
     @property
     def translation_key(self):
         """The translation key for this entity."""
-        return self._config.get("translation_key")
+        return self._config.get("translation_key", self.device_class)
 
     def unique_id(self, device_uid):
         """Return a suitable unique_id for this entity."""

+ 1 - 1
custom_components/tuya_local/number.py

@@ -45,7 +45,7 @@ class TuyaLocalNumber(TuyaLocalEntity, NumberEntity):
         dps_map = self._init_begin(device, config)
         self._value_dps = dps_map.pop("value")
         if self._value_dps is None:
-            raise AttributeError(f"{config.name} is missing a value dps")
+            raise AttributeError(f"{config.config_id} is missing a value dps")
         self._unit_dps = dps_map.pop("unit", None)
         self._min_dps = dps_map.pop("minimum", None)
         self._max_dps = dps_map.pop("maximum", None)

+ 2 - 2
custom_components/tuya_local/select.py

@@ -34,10 +34,10 @@ class TuyaLocalSelect(TuyaLocalEntity, SelectEntity):
         dps_map = self._init_begin(device, config)
         self._option_dps = dps_map.pop("option")
         if self._option_dps is None:
-            raise AttributeError(f"{config.name} is missing an option dps")
+            raise AttributeError(f"{config.config_id} is missing an option dps")
         if not self._option_dps.values(device):
             raise AttributeError(
-                f"{config.name} does not have a mapping to a list of options"
+                f"{config.config_id} does not have a mapping to a list of options"
             )
         self._init_end(dps_map)
 

+ 1 - 1
custom_components/tuya_local/sensor.py

@@ -42,7 +42,7 @@ class TuyaLocalSensor(TuyaLocalEntity, SensorEntity):
         dps_map = self._init_begin(device, config)
         self._sensor_dps = dps_map.pop("sensor", None)
         if self._sensor_dps is None:
-            raise AttributeError(f"{config.name} is missing a sensor dps")
+            raise AttributeError(f"{config.config_id} is missing a sensor dps")
         self._unit_dps = dps_map.pop("unit", None)
 
         self._init_end(dps_map)

+ 1 - 1
custom_components/tuya_local/vacuum.py

@@ -55,7 +55,7 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
         self._fan_dps = dps_map.pop("fan_speed", None)
 
         if self._status_dps is None:
-            raise AttributeError(f"{config.name} is missing a status dps")
+            raise AttributeError(f"{config.config_id} is missing a status dps")
         self._init_end(dps_map)
 
     @property