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

Add support for Neo Coolcam siren with temp and humidity triggers

Issue #673

- extended siren platform to allow a separate trigger dp rather than
expecting the siren to automatically sound when the tone is changed.
Jason Rumney 2 лет назад
Родитель
Сommit
3568eeea70

+ 1 - 0
ACKNOWLEDGEMENTS.md

@@ -298,3 +298,4 @@ Further device support has been made with the assistance of users.  Please consi
 - [NatMan3000](https://github.com/NatMan3000) for assisting with support for Arlec Ceiling fan/light remote control kits.
 - [TanYauRei](https://github.com/TanYauRei) for assisting with support for Daewoo Dhome air conditioners.
 - [eivindsor](https://github.com/eivindsor) for assisting with support for Lucking HS6 smart locks.
+- [epajfl00](https://github.com/epajfl00) for assisting with support for Neo Coolcam sirens.

+ 1 - 0
DEVICES.md

@@ -373,6 +373,7 @@ of device.
 ### Sirens
 
 - Orion Grid Connect outdoor siren
+- Neo Coolcam Siren with temperature and humidity alert (NAS-AB02W)
 
 ### Doorbells
 

+ 204 - 0
custom_components/tuya_local/devices/neo_coolcam_siren.yaml

@@ -0,0 +1,204 @@
+name: Neo Coolcam siren
+primary_entity:
+  entity: siren
+  dps:
+    - id: 104
+      type: boolean
+      name: switch
+    - id: 102
+      type: string
+      name: tone
+      mapping:
+        - dps_val: "0"
+          value: Doorbell
+        - dps_val: "1"
+          value: Für Elise
+        - dps_val: "2"
+          value: Big Ben
+        - dps_val: "3"
+          value: Ring ring
+        - dps_val: "4"
+          value: Lone Ranger
+        - dps_val: "5"
+          value: Turkish march
+        - dps_val: "6"
+          value: High pitched
+        - dps_val: "7"
+          value: Red alert
+        - dps_val: "8"
+          value: Crickets
+        - dps_val: "9"
+          value: Beep
+        - dps_val: "10"
+          value: Dog bark
+        - dps_val: "11"
+          value: Police siren
+        - dps_val: "12"
+          value: Grandfather clock
+        - dps_val: "13"
+          value: Phone ring
+        - dps_val: "14"
+          value: Fire truck
+        - dps_val: "15"
+          value: Clock chime
+        - dps_val: "16"
+          value: Alarm clock
+        - dps_val: "17"
+          value: School bell
+    - id: 103
+      type: integer
+      name: duration
+      unit: s
+      range:
+        min: 0
+        max: 300
+    - id: 116
+      type: string
+      name: volume_level
+      mapping:
+        - dps_val: "0"
+          value: 1.0
+        - dps_val: "1"
+          value: 0.7
+        - dps_val: "2"
+          value: 0.3
+secondary_entities:
+  - entity: sensor
+    name: Battery
+    class: battery
+    category: diagnostic
+    dps:
+      - id: 101
+        type: string
+        name: sensor
+        unit: "%"
+        mapping:
+          - dps_val: "1"
+            value: 80
+          - dps_val: "2"
+            value: 50
+          - dps_val: "3"
+            value: 20
+          - dps_val: "4"
+            value: 100
+  - entity: binary_sensor
+    name: Charging
+    class: battery_charging
+    category: diagnostic
+    dps:
+      - id: 101
+        type: string
+        name: sensor
+        mapping:
+          - dps_val: "4"
+            value: true
+          - value: false
+  - entity: sensor
+    name: Temperature
+    class: temperature
+    dps:
+      - id: 105
+        type: integer
+        name: sensor
+        unit: C
+        class: measurement
+        mapping:
+          - scale: 10
+  - entity: sensor
+    name: Humidity
+    class: humidity
+    dps:
+      - id: 106
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
+  - entity: number
+    name: Low temperature threshold
+    category: config
+    icon: "mdi:thermometer-chevron-down"
+    dps:
+      - id: 107
+        type: integer
+        name: value
+        unit: C
+        range:
+          min: -200
+          max: 500
+        mapping:
+          - scale: 10
+  - entity: number
+    name: High temperature threshold
+    category: config
+    icon: "mdi:thermometer-chevron-up"
+    dps:
+      - id: 108
+        type: integer
+        name: value
+        unit: C
+        range:
+          min: -200
+          max: 500
+        mapping:
+          - scale: 10
+  - entity: number
+    name: Low humidity threshold
+    category: config
+    icon: "mdi:water-percent-alert"
+    dps:
+      - id: 109
+        type: integer
+        name: value
+        unit: "%"
+        range:
+          min: 0
+          max: 100
+  - entity: number
+    name: High humidity threshold
+    category: config
+    icon: "mdi:water-percent-alert"
+    dps:
+      - id: 110
+        type: integer
+        name: value
+        unit: "%"
+        range:
+          min: 0
+          max: 100
+  - entity: select
+    name: Temperature display units
+    icon: "mdi:temperature-celsius"
+    category: config
+    dps:
+      - id: 112
+        type: boolean
+        name: option
+        mapping:
+          - dps_val: true
+            value: Celsius
+          - dps_val: false
+            value: Fahrenheit
+  - entity: switch
+    name: Temperature alarm
+    icon: "mdi:thermometer-alert"
+    category: config
+    dps:
+      - id: 113
+        type: boolean
+        name: switch
+  - entity: switch
+    name: Humidity alarm
+    icon: "mdi:water-percent-alert"
+    category: config
+    dps:
+      - id: 114
+        type: boolean
+        name: switch
+
+            
+
+
+
+
+
+

+ 14 - 2
custom_components/tuya_local/siren.py

@@ -38,6 +38,7 @@ class TuyaLocalSiren(TuyaLocalEntity, SirenEntity):
         self._tone_dp = dps_map.get("tone", None)
         self._volume_dp = dps_map.get("volume_level", None)
         self._duration_dp = dps_map.get("duration", None)
+        self._switch_dp = dps_map.get("switch", None)
         self._init_end(dps_map)
         # All control of features is through the turn_on service, so we need to
         # support that, even if the siren does not support direct control
@@ -62,6 +63,8 @@ class TuyaLocalSiren(TuyaLocalEntity, SirenEntity):
     @property
     def is_on(self):
         """Return whether the siren is on."""
+        if self._switch_dp:
+            return self._switch_dp.get_value(self._device)
         if self._tone_dp:
             return self._tone_dp.get_value(self._device) != "off"
 
@@ -69,10 +72,11 @@ class TuyaLocalSiren(TuyaLocalEntity, SirenEntity):
         tone = kwargs.get("tone", None)
         duration = kwargs.get("duration", None)
         volume = kwargs.get("volume", None)
+
         set_dps = {}
 
         if self._tone_dp:
-            if tone is None:
+            if tone is None and not self._switch_dp:
                 tone = self._tone_dp.get_value(self._device)
                 if tone == "off":
                     tone = self._default_tone
@@ -104,9 +108,17 @@ class TuyaLocalSiren(TuyaLocalEntity, SirenEntity):
                 **self._volume_dp.get_values_to_set(self._device, volume),
             }
 
+        if self._switch_dp and not self.is_on:
+            set_dps = {
+                **set_dps,
+                **self._switch_dp.get_values_to_set(self._device, True),
+            }
+
         await self._device.async_set_properties(set_dps)
 
     async def async_turn_off(self) -> None:
         """Turn off the siren"""
-        if self._tone_dp:
+        if self._switch_dp:
+            await self._switch_dp.async_set_value(self._device, False)
+        elif self._tone_dp:
             await self._tone_dp.async_set_value(self._device, "off")

+ 10 - 2
tests/test_device_config.py

@@ -23,7 +23,10 @@ from .const import (
 )
 
 KNOWN_DPS = {
-    "alarm_control_panel": {"required": ["alarm_state"], "optional": []},
+    "alarm_control_panel": {
+        "required": ["alarm_state"],
+        "optional": ["trigger"],
+    },
     "binary_sensor": {"required": ["sensor"], "optional": []},
     "button": {"required": ["button"], "optional": []},
     "camera": {
@@ -81,9 +84,11 @@ KNOWN_DPS = {
             "unlock_password",
             "unlock_temp_pwd",
             "unlock_dynamic_pwd",
+            "unlock_offline_pwd",
             "unlock_card",
             "unlock_app",
             "unlock_key",
+            "unlock_ble",
             "jammed",
         ],
     },
@@ -93,7 +98,10 @@ KNOWN_DPS = {
     },
     "select": {"required": ["option"], "optional": []},
     "sensor": {"required": ["sensor"], "optional": ["unit"]},
-    "siren": {"required": [], "optional": ["tone", "volume", "duration"]},
+    "siren": {
+        "required": [],
+        "optional": ["tone", "volume", "duration", "switch"],
+    },
     "switch": {"required": ["switch"], "optional": ["current_power_w"]},
     "vacuum": {
         "required": ["status"],