1 """Support for 1-Wire binary sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
9 BinarySensorDeviceClass,
11 BinarySensorEntityDescription,
17 from .
import OneWireConfigEntry
18 from .const
import DEVICE_KEYS_0_3, DEVICE_KEYS_0_7, DEVICE_KEYS_A_B, READ_MODE_BOOL
19 from .entity
import OneWireEntity, OneWireEntityDescription
20 from .onewirehub
import OneWireHub
23 @dataclass(frozen=True)
25 OneWireEntityDescription, BinarySensorEntityDescription
27 """Class describing OneWire binary sensor entities."""
30 DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
33 key=f
"sensed.{device_key}",
34 entity_registry_enabled_default=
False,
35 read_mode=READ_MODE_BOOL,
36 translation_key=
"sensed_id",
37 translation_placeholders={
"id":
str(device_key)},
39 for device_key
in DEVICE_KEYS_A_B
43 key=f
"sensed.{device_key}",
44 entity_registry_enabled_default=
False,
45 read_mode=READ_MODE_BOOL,
46 translation_key=
"sensed_id",
47 translation_placeholders={
"id":
str(device_key)},
49 for device_key
in DEVICE_KEYS_0_7
53 key=f
"sensed.{device_key}",
54 entity_registry_enabled_default=
False,
55 read_mode=READ_MODE_BOOL,
56 translation_key=
"sensed_id",
57 translation_placeholders={
"id":
str(device_key)},
59 for device_key
in DEVICE_KEYS_A_B
65 HOBBYBOARD_EF: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
68 key=f
"hub/short.{device_key}",
69 entity_registry_enabled_default=
False,
70 read_mode=READ_MODE_BOOL,
71 entity_category=EntityCategory.DIAGNOSTIC,
72 device_class=BinarySensorDeviceClass.PROBLEM,
73 translation_key=
"hub_short_id",
74 translation_placeholders={
"id":
str(device_key)},
76 for device_key
in DEVICE_KEYS_0_3
83 ) -> dict[str, tuple[OneWireBinarySensorEntityDescription, ...]]:
84 """Return the proper info array for the device type."""
85 if "HobbyBoard" in device_sub_type:
87 return DEVICE_BINARY_SENSORS
92 config_entry: OneWireConfigEntry,
93 async_add_entities: AddEntitiesCallback,
95 """Set up 1-Wire platform."""
96 entities = await hass.async_add_executor_job(
97 get_entities, config_entry.runtime_data
102 def get_entities(onewire_hub: OneWireHub) -> list[OneWireBinarySensor]:
103 """Get a list of entities."""
104 if not onewire_hub.devices:
107 entities: list[OneWireBinarySensor] = []
108 for device
in onewire_hub.devices:
109 family = device.family
110 device_id = device.id
111 device_type = device.type
112 device_info = device.device_info
113 device_sub_type =
"std"
114 if device_type
and "EF" in family:
115 device_sub_type =
"HobbyBoard"
121 device_file = os.path.join(os.path.split(device.path)[0], description.key)
124 description=description,
126 device_file=device_file,
127 device_info=device_info,
128 owproxy=onewire_hub.owproxy,
136 """Implementation of a 1-Wire binary sensor."""
138 entity_description: OneWireBinarySensorEntityDescription
142 """Return true if sensor is on."""
143 if self.
_state_state
is None:
None async_setup_entry(HomeAssistant hass, OneWireConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[OneWireBinarySensor] get_entities(OneWireHub onewire_hub)
dict[str, tuple[OneWireBinarySensorEntityDescription,...]] get_sensor_types(str device_sub_type)