1 """Support for getting status from a Pi-hole system."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
13 BinarySensorEntityDescription,
20 from .
import PiHoleConfigEntry
21 from .entity
import PiHoleEntity
24 @dataclass(frozen=True, kw_only=True)
26 """Describes PiHole binary sensor entity."""
28 state_value: Callable[[Hole], bool]
29 extra_value: Callable[[Hole], dict[str, Any] |
None] =
lambda api:
None
32 BINARY_SENSOR_TYPES: tuple[PiHoleBinarySensorEntityDescription, ...] = (
35 translation_key=
"status",
36 state_value=
lambda api:
bool(api.data.get(
"status") ==
"enabled"),
43 entry: PiHoleConfigEntry,
44 async_add_entities: AddEntitiesCallback,
46 """Set up the Pi-hole binary sensor."""
47 name = entry.data[CONF_NAME]
48 hole_data = entry.runtime_data
53 hole_data.coordinator,
58 for description
in BINARY_SENSOR_TYPES
65 """Representation of a Pi-hole binary sensor."""
67 entity_description: PiHoleBinarySensorEntityDescription
68 _attr_has_entity_name =
True
73 coordinator: DataUpdateCoordinator[
None],
75 server_unique_id: str,
76 description: PiHoleBinarySensorEntityDescription,
78 """Initialize a Pi-hole sensor."""
79 super().
__init__(api, coordinator, name, server_unique_id)
81 self.
_attr_unique_id_attr_unique_id = f
"{self._server_unique_id}/{description.key}"
85 """Return if the service is on."""
91 """Return the state attributes of the Pi-hole."""
None __init__(self, Hole api, DataUpdateCoordinator[None] coordinator, str name, str server_unique_id, PiHoleBinarySensorEntityDescription description)
dict[str, Any]|None extra_state_attributes(self)
None async_setup_entry(HomeAssistant hass, PiHoleConfigEntry entry, AddEntitiesCallback async_add_entities)