2020-03-24 10:11:35 +00:00
|
|
|
"""Summary binary data from Nextcoud."""
|
2022-01-03 10:32:26 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-08-27 16:51:31 +00:00
|
|
|
from typing import Final
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorEntity,
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
)
|
2023-03-26 19:14:17 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2023-08-27 16:51:31 +00:00
|
|
|
from homeassistant.const import EntityCategory
|
2022-01-03 10:32:26 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-03-24 10:11:35 +00:00
|
|
|
|
2023-03-14 11:14:29 +00:00
|
|
|
from .const import DOMAIN
|
2023-03-22 08:18:09 +00:00
|
|
|
from .coordinator import NextcloudDataUpdateCoordinator
|
2023-03-14 11:14:29 +00:00
|
|
|
from .entity import NextcloudEntity
|
2023-03-14 08:51:03 +00:00
|
|
|
|
2023-08-27 18:18:55 +00:00
|
|
|
BINARY_SENSORS: Final[list[BinarySensorEntityDescription]] = [
|
|
|
|
BinarySensorEntityDescription(
|
2023-08-27 16:51:31 +00:00
|
|
|
key="system_debug",
|
|
|
|
translation_key="nextcloud_system_debug",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
),
|
2023-08-27 18:18:55 +00:00
|
|
|
BinarySensorEntityDescription(
|
2023-08-27 16:51:31 +00:00
|
|
|
key="system_enable_avatars",
|
|
|
|
translation_key="nextcloud_system_enable_avatars",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
),
|
2023-08-27 18:18:55 +00:00
|
|
|
BinarySensorEntityDescription(
|
2023-08-27 16:51:31 +00:00
|
|
|
key="system_enable_previews",
|
|
|
|
translation_key="nextcloud_system_enable_previews",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
),
|
2023-08-27 18:18:55 +00:00
|
|
|
BinarySensorEntityDescription(
|
2023-08-27 16:51:31 +00:00
|
|
|
key="system_filelocking.enabled",
|
|
|
|
translation_key="nextcloud_system_filelocking_enabled",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
),
|
2023-08-27 18:18:55 +00:00
|
|
|
]
|
2020-03-24 10:11:35 +00:00
|
|
|
|
|
|
|
|
2023-03-26 19:14:17 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
2022-01-03 10:32:26 +00:00
|
|
|
) -> None:
|
2023-03-26 19:14:17 +00:00
|
|
|
"""Set up the Nextcloud binary sensors."""
|
|
|
|
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
async_add_entities(
|
2023-03-22 08:18:09 +00:00
|
|
|
[
|
2023-08-27 18:18:55 +00:00
|
|
|
NextcloudBinarySensor(coordinator, entry, sensor)
|
|
|
|
for sensor in BINARY_SENSORS
|
|
|
|
if sensor.key in coordinator.data
|
2023-03-26 19:14:17 +00:00
|
|
|
]
|
2023-03-22 08:18:09 +00:00
|
|
|
)
|
2020-03-24 10:11:35 +00:00
|
|
|
|
|
|
|
|
2023-03-14 11:14:29 +00:00
|
|
|
class NextcloudBinarySensor(NextcloudEntity, BinarySensorEntity):
|
2020-03-24 10:11:35 +00:00
|
|
|
"""Represents a Nextcloud binary sensor."""
|
|
|
|
|
|
|
|
@property
|
2023-03-14 11:14:29 +00:00
|
|
|
def is_on(self) -> bool:
|
2020-03-24 10:11:35 +00:00
|
|
|
"""Return true if the binary sensor is on."""
|
2023-08-27 18:18:55 +00:00
|
|
|
val = self.coordinator.data.get(self.entity_description.key)
|
2023-08-27 16:51:31 +00:00
|
|
|
return val is True or val == "yes"
|