|
3 | 3 | from dataclasses import dataclass |
4 | 4 | from typing import cast |
5 | 5 |
|
6 | | -from aiohomeconnect.model import StatusKey |
| 6 | +from aiohomeconnect.model import EventKey, StatusKey |
7 | 7 |
|
8 | 8 | from homeassistant.components.automation import automations_with_entity |
9 | 9 | from homeassistant.components.binary_sensor import ( |
|
12 | 12 | BinarySensorEntityDescription, |
13 | 13 | ) |
14 | 14 | from homeassistant.components.script import scripts_with_entity |
| 15 | +from homeassistant.const import EntityCategory |
15 | 16 | from homeassistant.core import HomeAssistant |
16 | 17 | from homeassistant.helpers import entity_registry as er |
17 | 18 | from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback |
@@ -131,13 +132,22 @@ class HomeConnectBinarySensorEntityDescription(BinarySensorEntityDescription): |
131 | 132 | ), |
132 | 133 | ) |
133 | 134 |
|
| 135 | +CONNECTED_BINARY_ENTITY_DESCRIPTION = BinarySensorEntityDescription( |
| 136 | + key=EventKey.BSH_COMMON_APPLIANCE_CONNECTED, |
| 137 | + device_class=BinarySensorDeviceClass.CONNECTIVITY, |
| 138 | +) |
| 139 | + |
134 | 140 |
|
135 | 141 | def _get_entities_for_appliance( |
136 | 142 | entry: HomeConnectConfigEntry, |
137 | 143 | appliance: HomeConnectApplianceData, |
138 | 144 | ) -> list[HomeConnectEntity]: |
139 | 145 | """Get a list of entities.""" |
140 | | - entities: list[HomeConnectEntity] = [] |
| 146 | + entities: list[HomeConnectEntity] = [ |
| 147 | + HomeConnectConnectivityBinarySensor( |
| 148 | + entry.runtime_data, appliance, CONNECTED_BINARY_ENTITY_DESCRIPTION |
| 149 | + ) |
| 150 | + ] |
141 | 151 | entities.extend( |
142 | 152 | HomeConnectBinarySensor(entry.runtime_data, appliance, description) |
143 | 153 | for description in BINARY_SENSORS |
@@ -177,6 +187,21 @@ def update_native_value(self) -> None: |
177 | 187 | self._attr_is_on = None |
178 | 188 |
|
179 | 189 |
|
| 190 | +class HomeConnectConnectivityBinarySensor(HomeConnectEntity, BinarySensorEntity): |
| 191 | + """Binary sensor for Home Connect appliance's connection status.""" |
| 192 | + |
| 193 | + _attr_entity_category = EntityCategory.DIAGNOSTIC |
| 194 | + |
| 195 | + def update_native_value(self) -> None: |
| 196 | + """Set the native value of the binary sensor.""" |
| 197 | + self._attr_is_on = self.appliance.info.connected |
| 198 | + |
| 199 | + @property |
| 200 | + def available(self) -> bool: |
| 201 | + """Return the availability.""" |
| 202 | + return self.coordinator.last_update_success |
| 203 | + |
| 204 | + |
180 | 205 | class HomeConnectDoorBinarySensor(HomeConnectBinarySensor): |
181 | 206 | """Binary sensor for Home Connect Generic Door.""" |
182 | 207 |
|
|
0 commit comments