Files
core/homeassistant/components/nextcloud/binary_sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.4 KiB
Python
Raw Normal View History

2020-03-24 06:11:35 -04:00
"""Summary binary data from Nextcoud."""
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
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2020-03-24 06:11:35 -04:00
from .coordinator import NextcloudConfigEntry
2023-03-14 12:14:29 +01:00
from .entity import NextcloudEntity
2023-03-14 09:51:03 +01:00
BINARY_SENSORS: Final[list[BinarySensorEntityDescription]] = [
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,
),
BinarySensorEntityDescription(
2023-08-27 18:51:31 +02:00
key="system_debug",
translation_key="nextcloud_system_debug",
entity_category=EntityCategory.DIAGNOSTIC,
),
BinarySensorEntityDescription(
2023-08-27 18:51:31 +02:00
key="system_enable_avatars",
translation_key="nextcloud_system_enable_avatars",
entity_category=EntityCategory.DIAGNOSTIC,
),
BinarySensorEntityDescription(
2023-08-27 18:51:31 +02:00
key="system_enable_previews",
translation_key="nextcloud_system_enable_previews",
entity_category=EntityCategory.DIAGNOSTIC,
),
BinarySensorEntityDescription(
2023-08-27 18:51:31 +02:00
key="system_filelocking.enabled",
translation_key="nextcloud_system_filelocking_enabled",
entity_category=EntityCategory.DIAGNOSTIC,
),
]
2020-03-24 06:11:35 -04:00
async def async_setup_entry(
hass: HomeAssistant,
entry: NextcloudConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the Nextcloud binary sensors."""
coordinator = entry.runtime_data
async_add_entities(
NextcloudBinarySensor(coordinator, entry, sensor)
for sensor in BINARY_SENSORS
if sensor.key in coordinator.data
)
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."""
val = self.coordinator.data.get(self.entity_description.key)
2023-08-27 18:51:31 +02:00
return val is True or val == "yes"