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
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
2022-01-03 10:32:26 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2020-03-24 10:11:35 +00:00
|
|
|
|
2023-03-14 11:14:29 +00:00
|
|
|
from .const import DOMAIN
|
|
|
|
from .entity import NextcloudEntity
|
2023-03-14 08:51:03 +00:00
|
|
|
|
|
|
|
BINARY_SENSORS = (
|
|
|
|
"nextcloud_system_enable_avatars",
|
|
|
|
"nextcloud_system_enable_previews",
|
|
|
|
"nextcloud_system_filelocking.enabled",
|
|
|
|
"nextcloud_system_debug",
|
|
|
|
)
|
2020-03-24 10:11:35 +00:00
|
|
|
|
|
|
|
|
2022-01-03 10:32:26 +00:00
|
|
|
def setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2020-03-24 10:11:35 +00:00
|
|
|
"""Set up the Nextcloud sensors."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
binary_sensors = []
|
|
|
|
for name in hass.data[DOMAIN]:
|
|
|
|
if name in BINARY_SENSORS:
|
|
|
|
binary_sensors.append(NextcloudBinarySensor(name))
|
|
|
|
add_entities(binary_sensors, True)
|
|
|
|
|
|
|
|
|
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-03-14 11:14:29 +00:00
|
|
|
return self._state == "yes"
|