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

BLE YL01 water tester: remove duplicate config

The config was previously renamed, but a subsequent change brought it
back accidentally. Since that got released, we need a migration to
ensure users are using the correct file in their device config.

Issue #2056
Jason Rumney 1 год назад
Родитель
Сommit
64b4eac7a9

+ 14 - 0
custom_components/tuya_local/__init__.py

@@ -493,6 +493,20 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
 
         await async_migrate_entries(hass, entry.entry_id, update_unique_id13_3)
         hass.config_entries.async_update_entry(entry, minor_version=3)
+
+    if entry.version == 13 and entry.minor_version < 4:
+        conf = entry.data | entry.options
+        conf_type = conf[CONF_TYPE]
+        # Duolicate config removal - make sure the correct one is used
+        if conf_type == "ble-yl01_waterquality_tester":
+            conf_type = "ble_yl01_watertester"
+
+        hass.config_entries.async_update_entry(
+            entry,
+            data={**entry.data, CONF_TYPE: conf_type},
+            options={**entry.options},
+            minor_version=4,
+        )
     return True
 
 

+ 1 - 1
custom_components/tuya_local/config_flow.py

@@ -73,7 +73,7 @@ HUB_CATEGORIES = [
 
 class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
     VERSION = 13
-    MINOR_VERSION = 3
+    MINOR_VERSION = 4
     CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
     device = None
     data = {}

+ 0 - 241
custom_components/tuya_local/devices/ble-yl01_waterquality_tester.yaml

@@ -1,241 +0,0 @@
-name: Water quality monitor
-products:
-  - id: v1jqz5cy
-    name: BLE-YL01 Waterquality tester
-primary_entity:
-  entity: sensor
-  icon: "mdi:pool-thermometer"
-  class: temperature
-  dps:
-    - id: 2
-      type: integer
-      name: sensor
-      unit: "°C"
-      class: measurement
-      mapping:
-        - scale: 10
-secondary_entities:
-  - entity: sensor
-    name: TDS
-    dps:
-      - id: 1
-        type: integer
-        name: sensor
-        class: measurement
-        unit: "ppm"
-  - entity: sensor
-    class: battery
-    category: diagnostic
-    dps:
-      - id: 7
-        type: integer
-        name: sensor
-        unit: "%"
-  - entity: sensor
-    class: ph
-    dps:
-      - id: 10
-        type: integer
-        name: sensor
-        class: measurement
-        mapping:
-          - scale: 10
-  - entity: sensor
-    name: EC
-    icon: "mdi:omega"
-    dps:
-      - id: 11
-        type: integer
-        name: sensor
-        unit: uS/cm
-        class: measurement
-  - entity: sensor
-    name: ORP
-    dps:
-      - id: 101
-        type: integer
-        name: sensor
-        unit: mV
-        class: measurement
-  - entity: sensor
-    name: CL
-    dps:
-      - id: 102
-        type: integer
-        name: sensor
-        unit: mg/L
-        class: measurement
-  - entity: select
-    name: pH buffer standard
-    icon: "mdi:ph"
-    category: config
-    dps:
-      - id: 103
-        type: string
-        name: option
-        mapping:
-          - dps_val: AsiaStandard
-            value: Asia
-          - dps_val: EUStandard
-            value: EU
-  - entity: light
-    translation_key: backlight
-    category: config
-    dps:
-      - id: 104
-        type: boolean
-        name: switch
-      - id: 105
-        type: integer
-        name: backlight_value
-        # may be brightness, but only log we have has 0 value and range
-        # is unusally high - up to 16M
-  - entity: number
-    name: Maximum pH
-    class: ph
-    category: config
-    dps:
-      - id: 106
-        type: integer
-        name: value
-        range:
-          min: 0
-          max: 140
-        mapping:
-          - scale: 10
-  - entity: number
-    name: Minimum pH
-    category: config
-    class: ph
-    dps:
-      - id: 107
-        type: integer
-        name: value
-        range:
-          min: 0
-          max: 140
-        mapping:
-          - scale: 10
-  - entity: number
-    name: Maximum EC
-    category: config
-    icon: "mdi:omega"
-    dps:
-      - id: 108
-        type: integer
-        name: value
-        unit: "uS/cm"
-        range:
-          min: 0
-          max: 20000
-  - entity: number
-    name: Minimum EC
-    category: config
-    icon: "mdi:omega"
-    dps:
-      - id: 109
-        type: integer
-        name: value
-        unit: "uS/cm"
-        range:
-          min: 0
-          max: 20000
-  - entity: number
-    name: Maximum ORP
-    icon: "mdi:virus-off"
-    category: config
-    dps:
-      - id: 110
-        type: integer
-        name: value
-        unit: "mV"
-        range:
-          min: -1200
-          max: 1200
-  - entity: number
-    name: Minimum ORP
-    icon: "mdi:virus-off"
-    category: config
-    dps:
-      - id: 111
-        type: integer
-        name: value
-        unit: "mV"
-        range:
-          min: -1200
-          max: 1200
-  - entity: number
-    name: Maximum CL
-    category: config
-    dps:
-      - id: 112
-        type: integer
-        name: value
-        unit: "mg/L"
-        range:
-          min: 0
-          max: 40
-  - entity: number
-    name: Minimum CL
-    category: config
-    dps:
-      - id: 113
-        type: integer
-        name: value
-        unit: "mg/L"
-        range:
-          min: 0
-          max: 40
-  - entity: number
-    name: pH calibration
-    category: config
-    icon: "mdi:ph"
-    dps:
-      - id: 114
-        type: integer
-        name: value
-        range:
-          min: 0
-          max: 1400
-        mapping:
-          - scale: 100
-  - entity: number
-    name: EC calibration
-    category: config
-    icon: "mdi:omega"
-    dps:
-      - id: 115
-        type: integer
-        name: value
-        unit: uS/cm
-        range:
-          min: 0
-          max: 20000
-  - entity: number
-    name: ORP calibration
-    category: config
-    icon: "mdi:virus-off"
-    dps:
-      - id: 116
-        type: integer
-        name: value
-        unit: mV
-        range:
-          min: -1200
-          max: 1200
-  - entity: sensor
-    name: Salinity
-    dps:
-      - id: 117
-        type: integer
-        name: sensor
-        class: measurement
-        unit: "ppm"
-  - entity: button
-    name: pH reset
-    class: restart
-    category: config
-    dps:
-      - id: 118
-        type: boolean
-        name: button

+ 54 - 4
custom_components/tuya_local/devices/ble_yl01_watertester.yaml

@@ -85,6 +85,11 @@ secondary_entities:
       - id: 104
         type: boolean
         name: switch
+      - id: 105
+        type: integer
+        name: backlight_value
+        # may be brightness, but only log we have has 0 value and range
+        # is unusally high - up to 16M
   - entity: number
     name: Maximum pH
     class: ph
@@ -147,6 +152,18 @@ secondary_entities:
         range:
           min: -1200
           max: 1200
+  - entity: number
+    name: Minimum ORP
+    icon: "mdi:virus-off"
+    category: config
+    dps:
+      - id: 111
+        type: integer
+        name: value
+        unit: "mV"
+        range:
+          min: -1200
+          max: 1200
   - entity: number
     name: Maximum CL
     category: config
@@ -170,14 +187,39 @@ secondary_entities:
           min: 0
           max: 40
   - entity: number
-    name: Minimum ORP
-    icon: "mdi:virus-off"
+    name: pH calibration
     category: config
+    icon: "mdi:ph"
     dps:
-      - id: 111
+      - id: 114
         type: integer
         name: value
-        unit: "mV"
+        range:
+          min: 0
+          max: 1400
+        mapping:
+          - scale: 100
+  - entity: number
+    name: EC calibration
+    category: config
+    icon: "mdi:omega"
+    dps:
+      - id: 115
+        type: integer
+        name: value
+        unit: uS/cm
+        range:
+          min: 0
+          max: 20000
+  - entity: number
+    name: ORP calibration
+    category: config
+    icon: "mdi:virus-off"
+    dps:
+      - id: 116
+        type: integer
+        name: value
+        unit: mV
         range:
           min: -1200
           max: 1200
@@ -189,3 +231,11 @@ secondary_entities:
         name: sensor
         class: measurement
         unit: "ppm"
+  - entity: button
+    name: pH reset
+    class: restart
+    category: config
+    dps:
+      - id: 118
+        type: boolean
+        name: button