1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Add camera in use and pending reboot binary sensors to System Bridge (#104095)

* Add binary sensors

* Fix

* Fix

* Fix translations

* Add icons

* Fix attr

* Update string

* fix name

* Remove unnessasary check

* Remove unrelated changes

* Remove unrelated strings

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Update camera_in_use function and value_fn for binary sensors

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Aidan Timson 2024-03-18 15:21:52 +00:00 committed by GitHub
parent 7065625d28
commit 8918eb6922
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View File

@ -17,6 +17,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .coordinator import SystemBridgeDataUpdateCoordinator
from .data import SystemBridgeData
from .entity import SystemBridgeEntity
@ -24,14 +25,33 @@ from .entity import SystemBridgeEntity
class SystemBridgeBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Class describing System Bridge binary sensor entities."""
value: Callable = round
value_fn: Callable = round
def camera_in_use(data: SystemBridgeData) -> bool | None:
"""Return if any camera is in use."""
if data.system.camera_usage is not None:
return len(data.system.camera_usage) > 0
return None
BASE_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ...] = (
SystemBridgeBinarySensorEntityDescription(
key="camera_in_use",
translation_key="camera_in_use",
icon="mdi:webcam",
value_fn=camera_in_use,
),
SystemBridgeBinarySensorEntityDescription(
key="pending_reboot",
translation_key="pending_reboot",
icon="mdi:restart",
value_fn=lambda data: data.system.pending_reboot,
),
SystemBridgeBinarySensorEntityDescription(
key="version_available",
device_class=BinarySensorDeviceClass.UPDATE,
value=lambda data: data.system.version_newer_available,
value_fn=lambda data: data.system.version_newer_available,
),
)
@ -39,7 +59,7 @@ BATTERY_BINARY_SENSOR_TYPES: tuple[SystemBridgeBinarySensorEntityDescription, ..
SystemBridgeBinarySensorEntityDescription(
key="battery_is_charging",
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
value=lambda data: data.battery.is_charging,
value_fn=lambda data: data.battery.is_charging,
),
)
@ -90,4 +110,4 @@ class SystemBridgeBinarySensor(SystemBridgeEntity, BinarySensorEntity):
@property
def is_on(self) -> bool:
"""Return the boolean state of the binary sensor."""
return self.entity_description.value(self.coordinator.data)
return self.entity_description.value_fn(self.coordinator.data)

View File

@ -30,6 +30,14 @@
}
},
"entity": {
"binary_sensor": {
"camera_in_use": {
"name": "Camera in use"
},
"pending_reboot": {
"name": "Pending reboot"
}
},
"media_player": {
"media": {
"name": "Media"