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

fix (weather_stations): avoid overriding HA translations where possible

Previously wind_direction was updated (from Wind bearing) without a proper migration
This time make sure to migrate the entities so they keep their long
term statistics.

Issue #1708, inspired by discussion #4668
Jason Rumney 4 дней назад
Родитель
Сommit
0212ed04c2

+ 30 - 0
custom_components/tuya_local/__init__.py

@@ -817,6 +817,36 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
 
         await async_migrate_entries(hass, entry.entry_id, update_unique_id13_16)
         hass.config_entries.async_update_entry(entry, minor_version=16)
+
+    if entry.version == 13 and entry.minor_version < 17:
+        # Migrate unique ids of existing entities to new id taking into
+        # account translation_key, and standardising naming
+        device_id = get_device_unique_id(entry)
+        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_17(entity_entry):
+            """Update the unique id of an entity entry."""
+            # Standardistion of entity naming to use translation_key
+            replacements = {
+                "sensor_light_intensity": "sensor_illuminance",
+                "sensor_rain": "sensor_precipitation",
+                "sensor_rainfall_rate": "sensor_precipitation_intensity",
+            }
+            return replace_unique_ids(entity_entry, device_id, conf_file, replacements)
+
+        await async_migrate_entries(hass, entry.entry_id, update_unique_id13_17)
+        hass.config_entries.async_update_entry(entry, minor_version=17)
+
     return True
 
 

+ 1 - 1
custom_components/tuya_local/config_flow.py

@@ -53,7 +53,7 @@ DEVICE_DETAILS_URL = (
 
 class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
     VERSION = 13
-    MINOR_VERSION = 16
+    MINOR_VERSION = 17
     CONNECTION_CLASS = CONN_CLASS_LOCAL_PUSH
     device = None
     data = {}

+ 4 - 8
custom_components/tuya_local/devices/bresser_weather_station.yaml

@@ -243,8 +243,7 @@ entities:
         unit: hPa
         class: measurement
   - entity: sensor
-    name: Wind speed
-    icon: mdi:weather-windy
+    class: wind_speed
     dps:
       - id: 56
         optional: true
@@ -257,14 +256,13 @@ entities:
           class: measurement
   - entity: sensor
     name: Wind gust
-    icon: mdi:weather-windy
+    class: wind_speed
     dps:
       - id: 57
         optional: true
         <<: *wind_speed
   - entity: sensor
-    name: Rain
-    icon: mdi:weather-rainy
+    class: precipitation
     dps:
       - id: 60
         <<: &rain
@@ -275,8 +273,7 @@ entities:
           class: measurement
         unit: mm
   - entity: sensor
-    name: Rainfall rate
-    icon: mdi:weather-pouring
+    class: precipitation_intensity
     dps:
       - id: 61
         optional: true
@@ -295,7 +292,6 @@ entities:
           - scale: 10
         class: measurement
   - entity: sensor
-    name: Light intensity
     class: illuminance
     dps:
       - id: 63

+ 0 - 10
custom_components/tuya_local/devices/holman_helios_weatherstation.yaml

@@ -8,7 +8,6 @@ entities:
   - entity: sensor
     class: temperature
     name: Indoor temperature
-    category: diagnostic
     dps:
       - id: 101
         name: sensor
@@ -112,7 +111,6 @@ entities:
         class: measurement
   - entity: sensor
     class: illuminance
-    category: diagnostic
     dps:
       - id: 116
         type: integer
@@ -124,7 +122,6 @@ entities:
   - entity: sensor
     name: Dewpoint
     class: temperature
-    category: diagnostic
     dps:
       - id: 117
         type: integer
@@ -136,7 +133,6 @@ entities:
   - entity: sensor
     name: Feels like
     class: temperature
-    category: diagnostic
     dps:
       - id: 123
         type: integer
@@ -148,7 +144,6 @@ entities:
   - entity: sensor
     name: Heat index
     class: temperature
-    category: diagnostic
     dps:
       - id: 124
         type: integer
@@ -160,7 +155,6 @@ entities:
   - entity: sensor
     name: Windchill
     class: temperature
-    category: diagnostic
     dps:
       - id: 125
         type: integer
@@ -170,9 +164,7 @@ entities:
           - scale: 10
         class: measurement
   - entity: sensor
-    name: Rain
     class: precipitation
-    category: diagnostic
     dps:
       - id: 134
         type: integer
@@ -184,7 +176,6 @@ entities:
   - entity: sensor
     name: Tablet battery
     icon: mdi:battery
-    category: diagnostic
     dps:
       - id: 140
         type: string
@@ -192,7 +183,6 @@ entities:
   - entity: sensor
     name: Outdoor battery
     icon: mdi:battery
-    category: diagnostic
     dps:
       - id: 141
         type: string