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