From 53870617e8a0192b580b74c8a332d42456207653 Mon Sep 17 00:00:00 2001
From: Austin Mroczek <austin@mroczek.org>
Date: Fri, 19 Jul 2024 00:35:54 -0700
Subject: [PATCH] Add binary sensors to TotalConnect (#121888)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
---
 .../components/totalconnect/binary_sensor.py  |  15 ++
 .../components/totalconnect/icons.json        |  10 ++
 .../components/totalconnect/strings.json      |   9 ++
 .../snapshots/test_binary_sensor.ambr         | 143 ++++++++++++++++++
 4 files changed, 177 insertions(+)

diff --git a/homeassistant/components/totalconnect/binary_sensor.py b/homeassistant/components/totalconnect/binary_sensor.py
index 62f84b3b69a..3126efff88a 100644
--- a/homeassistant/components/totalconnect/binary_sensor.py
+++ b/homeassistant/components/totalconnect/binary_sensor.py
@@ -101,6 +101,21 @@ LOCATION_BINARY_SENSORS: tuple[TotalConnectAlarmBinarySensorEntityDescription, .
         entity_category=EntityCategory.DIAGNOSTIC,
         is_on_fn=lambda location: location.is_ac_loss(),
     ),
+    TotalConnectAlarmBinarySensorEntityDescription(
+        key="smoke",
+        device_class=BinarySensorDeviceClass.SMOKE,
+        is_on_fn=lambda location: location.arming_state.is_triggered_fire(),
+    ),
+    TotalConnectAlarmBinarySensorEntityDescription(
+        key="carbon_monoxide",
+        device_class=BinarySensorDeviceClass.CO,
+        is_on_fn=lambda location: location.arming_state.is_triggered_gas(),
+    ),
+    TotalConnectAlarmBinarySensorEntityDescription(
+        key="police",
+        translation_key="police",
+        is_on_fn=lambda location: location.arming_state.is_triggered_police(),
+    ),
 )
 
 
diff --git a/homeassistant/components/totalconnect/icons.json b/homeassistant/components/totalconnect/icons.json
index 356ce0a929b..cb62a79c7bb 100644
--- a/homeassistant/components/totalconnect/icons.json
+++ b/homeassistant/components/totalconnect/icons.json
@@ -1,4 +1,14 @@
 {
+  "entity": {
+    "binary_sensor": {
+      "police": {
+        "default": "mdi:police-badge-outline",
+        "state": {
+          "on": "mdi:police-badge"
+        }
+      }
+    }
+  },
   "services": {
     "arm_away_instant": "mdi:shield-lock",
     "arm_home_instant": "mdi:shield-home"
diff --git a/homeassistant/components/totalconnect/strings.json b/homeassistant/components/totalconnect/strings.json
index e2e5ed7c490..faa136137db 100644
--- a/homeassistant/components/totalconnect/strings.json
+++ b/homeassistant/components/totalconnect/strings.json
@@ -56,6 +56,15 @@
         "name": "Partition {partition_id}"
       }
     },
+    "binary_sensor": {
+      "police": {
+        "name": "Police emergency",
+        "state": {
+          "off": "No emergency",
+          "on": "Police emergency"
+        }
+      }
+    },
     "button": {
       "clear_bypass": {
         "name": "Clear bypass"
diff --git a/tests/components/totalconnect/snapshots/test_binary_sensor.ambr b/tests/components/totalconnect/snapshots/test_binary_sensor.ambr
index 54089c6f192..81cfecbc530 100644
--- a/tests/components/totalconnect/snapshots/test_binary_sensor.ambr
+++ b/tests/components/totalconnect/snapshots/test_binary_sensor.ambr
@@ -847,6 +847,101 @@
     'state': 'off',
   })
 # ---
+# name: test_entity_registry[binary_sensor.test_carbon_monoxide-entry]
+  EntityRegistryEntrySnapshot({
+    'aliases': set({
+    }),
+    'area_id': None,
+    'capabilities': None,
+    'config_entry_id': <ANY>,
+    'device_class': None,
+    'device_id': <ANY>,
+    'disabled_by': None,
+    'domain': 'binary_sensor',
+    'entity_category': None,
+    'entity_id': 'binary_sensor.test_carbon_monoxide',
+    'has_entity_name': True,
+    'hidden_by': None,
+    'icon': None,
+    'id': <ANY>,
+    'labels': set({
+    }),
+    'name': None,
+    'options': dict({
+    }),
+    'original_device_class': <BinarySensorDeviceClass.CO: 'carbon_monoxide'>,
+    'original_icon': None,
+    'original_name': 'Carbon monoxide',
+    'platform': 'totalconnect',
+    'previous_unique_id': None,
+    'supported_features': 0,
+    'translation_key': None,
+    'unique_id': '123456_carbon_monoxide',
+    'unit_of_measurement': None,
+  })
+# ---
+# name: test_entity_registry[binary_sensor.test_carbon_monoxide-state]
+  StateSnapshot({
+    'attributes': ReadOnlyDict({
+      'device_class': 'carbon_monoxide',
+      'friendly_name': 'test Carbon monoxide',
+      'location_id': '123456',
+    }),
+    'context': <ANY>,
+    'entity_id': 'binary_sensor.test_carbon_monoxide',
+    'last_changed': <ANY>,
+    'last_reported': <ANY>,
+    'last_updated': <ANY>,
+    'state': 'off',
+  })
+# ---
+# name: test_entity_registry[binary_sensor.test_police_emergency-entry]
+  EntityRegistryEntrySnapshot({
+    'aliases': set({
+    }),
+    'area_id': None,
+    'capabilities': None,
+    'config_entry_id': <ANY>,
+    'device_class': None,
+    'device_id': <ANY>,
+    'disabled_by': None,
+    'domain': 'binary_sensor',
+    'entity_category': None,
+    'entity_id': 'binary_sensor.test_police_emergency',
+    'has_entity_name': True,
+    'hidden_by': None,
+    'icon': None,
+    'id': <ANY>,
+    'labels': set({
+    }),
+    'name': None,
+    'options': dict({
+    }),
+    'original_device_class': None,
+    'original_icon': None,
+    'original_name': 'Police emergency',
+    'platform': 'totalconnect',
+    'previous_unique_id': None,
+    'supported_features': 0,
+    'translation_key': 'police',
+    'unique_id': '123456_police',
+    'unit_of_measurement': None,
+  })
+# ---
+# name: test_entity_registry[binary_sensor.test_police_emergency-state]
+  StateSnapshot({
+    'attributes': ReadOnlyDict({
+      'friendly_name': 'test Police emergency',
+      'location_id': '123456',
+    }),
+    'context': <ANY>,
+    'entity_id': 'binary_sensor.test_police_emergency',
+    'last_changed': <ANY>,
+    'last_reported': <ANY>,
+    'last_updated': <ANY>,
+    'state': 'off',
+  })
+# ---
 # name: test_entity_registry[binary_sensor.test_power-entry]
   EntityRegistryEntrySnapshot({
     'aliases': set({
@@ -895,6 +990,54 @@
     'state': 'off',
   })
 # ---
+# name: test_entity_registry[binary_sensor.test_smoke-entry]
+  EntityRegistryEntrySnapshot({
+    'aliases': set({
+    }),
+    'area_id': None,
+    'capabilities': None,
+    'config_entry_id': <ANY>,
+    'device_class': None,
+    'device_id': <ANY>,
+    'disabled_by': None,
+    'domain': 'binary_sensor',
+    'entity_category': None,
+    'entity_id': 'binary_sensor.test_smoke',
+    'has_entity_name': True,
+    'hidden_by': None,
+    'icon': None,
+    'id': <ANY>,
+    'labels': set({
+    }),
+    'name': None,
+    'options': dict({
+    }),
+    'original_device_class': <BinarySensorDeviceClass.SMOKE: 'smoke'>,
+    'original_icon': None,
+    'original_name': 'Smoke',
+    'platform': 'totalconnect',
+    'previous_unique_id': None,
+    'supported_features': 0,
+    'translation_key': None,
+    'unique_id': '123456_smoke',
+    'unit_of_measurement': None,
+  })
+# ---
+# name: test_entity_registry[binary_sensor.test_smoke-state]
+  StateSnapshot({
+    'attributes': ReadOnlyDict({
+      'device_class': 'smoke',
+      'friendly_name': 'test Smoke',
+      'location_id': '123456',
+    }),
+    'context': <ANY>,
+    'entity_id': 'binary_sensor.test_smoke',
+    'last_changed': <ANY>,
+    'last_reported': <ANY>,
+    'last_updated': <ANY>,
+    'state': 'off',
+  })
+# ---
 # name: test_entity_registry[binary_sensor.test_tamper-entry]
   EntityRegistryEntrySnapshot({
     'aliases': set({
-- 
GitLab