Jelajahi Sumber

feat (translations): migrate "Disturb switch" to do_not_disturb

Variation on the now translated "Do not disturb" used by 3 vacuums.

Issue #1708
Jason Rumney 2 bulan lalu
induk
melakukan
0acce83204

+ 27 - 0
custom_components/tuya_local/__init__.py

@@ -631,6 +631,33 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
 
         await async_migrate_entries(hass, entry.entry_id, update_unique_id13_9)
         hass.config_entries.async_update_entry(entry, minor_version=9)
+
+    if entry.version == 13 and entry.minor_version < 10:
+        # Migrate unique ids of existing entities to new id taking into
+        # account translation_key, and standardising naming
+        device_id = entry.unique_id
+        conf_file = await hass.async_add_executor_job(
+            get_config,
+            entry.data[CONF_TYPE],
+        )
+        if conf_file is None:
+            _LOGGER.error(
+                NOT_FOUND,
+                entry.data[CONF_TYPE],
+            )
+            return False
+
+        @callback
+        def update_unique_id13_10(entity_entry):
+            """Update the unique id of an entity entry."""
+            # Standardistion of entity naming to use translation_key
+            replacements = {
+                "switch_disturb_switch": "switch_do_not_disturb",
+            }
+            return replace_unique_ids(entity_entry, device_id, conf_file, replacements)
+
+        await async_migrate_entries(hass, entry.entry_id, update_unique_id13_10)
+        hass.config_entries.async_update_entry(entry, minor_version=10)
     return True
 
 

+ 1 - 1
custom_components/tuya_local/config_flow.py

@@ -47,7 +47,7 @@ _LOGGER = logging.getLogger(__name__)
 
 class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
     VERSION = 13
-    MINOR_VERSION = 9
+    MINOR_VERSION = 10
     CONNECTION_CLASS = CONN_CLASS_LOCAL_PUSH
     device = None
     data = {}

+ 1 - 2
custom_components/tuya_local/devices/kogan_lx10_vacuum.yaml

@@ -176,9 +176,8 @@ entities:
           - dps_val: strong
             value: high
   - entity: switch
-    name: Disturb switch
+    translation_key: do_not_disturb
     category: config
-    icon: "mdi:bell-ring"
     dps:
       - id: 113
         name: switch

+ 1 - 2
custom_components/tuya_local/devices/kogan_lx8_vacuum.yaml

@@ -175,9 +175,8 @@ entities:
             value: high
         optional: true
   - entity: switch
-    name: Disturb switch
+    translation_key: do_not_disturb
     category: config
-    icon: "mdi:bell-ring"
     dps:
       - id: 113
         name: switch

+ 1 - 1
custom_components/tuya_local/devices/tefal_xplorer_vacuum.yaml

@@ -224,7 +224,7 @@ entities:
         type: integer
         unit: m2
   - entity: switch
-    name: Disturb switch
+    translation_key: do_not_disturb
     category: config
     icon: "mdi:bell-ring"
     dps: