Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Summary binary data from Nextcoud."""
2 
3 from __future__ import annotations
4 
5 from typing import Final
6 
8  BinarySensorEntity,
9  BinarySensorEntityDescription,
10 )
11 from homeassistant.const import EntityCategory
12 from homeassistant.core import HomeAssistant
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from . import NextcloudConfigEntry
16 from .entity import NextcloudEntity
17 
18 BINARY_SENSORS: Final[list[BinarySensorEntityDescription]] = [
20  key="jit_enabled",
21  translation_key="nextcloud_jit_enabled",
22  entity_category=EntityCategory.DIAGNOSTIC,
23  entity_registry_enabled_default=False,
24  ),
26  key="jit_on",
27  translation_key="nextcloud_jit_on",
28  entity_category=EntityCategory.DIAGNOSTIC,
29  entity_registry_enabled_default=False,
30  ),
32  key="system_debug",
33  translation_key="nextcloud_system_debug",
34  entity_category=EntityCategory.DIAGNOSTIC,
35  ),
37  key="system_enable_avatars",
38  translation_key="nextcloud_system_enable_avatars",
39  entity_category=EntityCategory.DIAGNOSTIC,
40  ),
42  key="system_enable_previews",
43  translation_key="nextcloud_system_enable_previews",
44  entity_category=EntityCategory.DIAGNOSTIC,
45  ),
47  key="system_filelocking.enabled",
48  translation_key="nextcloud_system_filelocking_enabled",
49  entity_category=EntityCategory.DIAGNOSTIC,
50  ),
51 ]
52 
53 
55  hass: HomeAssistant,
56  entry: NextcloudConfigEntry,
57  async_add_entities: AddEntitiesCallback,
58 ) -> None:
59  """Set up the Nextcloud binary sensors."""
60  coordinator = entry.runtime_data
62  NextcloudBinarySensor(coordinator, entry, sensor)
63  for sensor in BINARY_SENSORS
64  if sensor.key in coordinator.data
65  )
66 
67 
69  """Represents a Nextcloud binary sensor."""
70 
71  @property
72  def is_on(self) -> bool:
73  """Return true if the binary sensor is on."""
74  val = self.coordinator.data.get(self.entity_descriptionentity_description.key)
75  return val is True or val == "yes"
None async_setup_entry(HomeAssistant hass, NextcloudConfigEntry entry, AddEntitiesCallback async_add_entities)