1 """Support for 1-Wire environment switches."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
14 from .
import OneWireConfigEntry
15 from .const
import DEVICE_KEYS_0_3, DEVICE_KEYS_0_7, DEVICE_KEYS_A_B, READ_MODE_BOOL
16 from .entity
import OneWireEntity, OneWireEntityDescription
17 from .onewirehub
import OneWireHub
20 @dataclass(frozen=True)
22 """Class describing OneWire switch entities."""
25 DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
29 entity_registry_enabled_default=
False,
30 read_mode=READ_MODE_BOOL,
31 translation_key=
"pio",
37 key=f
"PIO.{device_key}",
38 entity_registry_enabled_default=
False,
39 read_mode=READ_MODE_BOOL,
40 translation_key=
"pio_id",
41 translation_placeholders={
"id":
str(device_key)},
43 for device_key
in DEVICE_KEYS_A_B
47 key=f
"latch.{device_key}",
48 entity_registry_enabled_default=
False,
49 read_mode=READ_MODE_BOOL,
50 translation_key=
"latch_id",
51 translation_placeholders={
"id":
str(device_key)},
53 for device_key
in DEVICE_KEYS_A_B
59 entity_registry_enabled_default=
False,
60 entity_category=EntityCategory.CONFIG,
61 read_mode=READ_MODE_BOOL,
62 translation_key=
"iad",
68 key=f
"PIO.{device_key}",
69 entity_registry_enabled_default=
False,
70 read_mode=READ_MODE_BOOL,
71 translation_key=
"pio_id",
72 translation_placeholders={
"id":
str(device_key)},
74 for device_key
in DEVICE_KEYS_0_7
78 key=f
"latch.{device_key}",
79 entity_registry_enabled_default=
False,
80 read_mode=READ_MODE_BOOL,
81 translation_key=
"latch_id",
82 translation_placeholders={
"id":
str(device_key)},
84 for device_key
in DEVICE_KEYS_0_7
89 key=f
"PIO.{device_key}",
90 entity_registry_enabled_default=
False,
91 read_mode=READ_MODE_BOOL,
92 translation_key=
"pio_id",
93 translation_placeholders={
"id":
str(device_key)},
95 for device_key
in DEVICE_KEYS_A_B
102 HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = {
105 key=f
"hub/branch.{device_key}",
106 entity_registry_enabled_default=
False,
107 read_mode=READ_MODE_BOOL,
108 entity_category=EntityCategory.CONFIG,
109 translation_key=
"hub_branch_id",
110 translation_placeholders={
"id":
str(device_key)},
112 for device_key
in DEVICE_KEYS_0_3
114 "HB_MOISTURE_METER":
tuple(
117 key=f
"moisture/is_leaf.{device_key}",
118 entity_registry_enabled_default=
False,
119 read_mode=READ_MODE_BOOL,
120 entity_category=EntityCategory.CONFIG,
121 translation_key=
"leaf_sensor_id",
122 translation_placeholders={
"id":
str(device_key)},
124 for device_key
in DEVICE_KEYS_0_3
128 key=f
"moisture/is_moisture.{device_key}",
129 entity_registry_enabled_default=
False,
130 read_mode=READ_MODE_BOOL,
131 entity_category=EntityCategory.CONFIG,
132 translation_key=
"moisture_sensor_id",
133 translation_placeholders={
"id":
str(device_key)},
135 for device_key
in DEVICE_KEYS_0_3
142 device_sub_type: str,
143 ) -> dict[str, tuple[OneWireEntityDescription, ...]]:
144 """Return the proper info array for the device type."""
145 if "HobbyBoard" in device_sub_type:
147 return DEVICE_SWITCHES
152 config_entry: OneWireConfigEntry,
153 async_add_entities: AddEntitiesCallback,
155 """Set up 1-Wire platform."""
156 entities = await hass.async_add_executor_job(
157 get_entities, config_entry.runtime_data
163 """Get a list of entities."""
164 if not onewire_hub.devices:
167 entities: list[OneWireSwitch] = []
169 for device
in onewire_hub.devices:
170 family = device.family
171 device_type = device.type
172 device_id = device.id
173 device_info = device.device_info
174 device_sub_type =
"std"
175 if device_type
and "EF" in family:
176 device_sub_type =
"HobbyBoard"
185 device_file = os.path.join(os.path.split(device.path)[0], description.key)
188 description=description,
190 device_file=device_file,
191 device_info=device_info,
192 owproxy=onewire_hub.owproxy,
200 """Implementation of a 1-Wire switch."""
202 entity_description: OneWireSwitchEntityDescription
206 """Return true if switch is on."""
207 if self.
_state_state
is None:
212 """Turn the entity on."""
216 """Turn the entity off."""
None _write_value(self, bytes value)
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, OneWireConfigEntry config_entry, AddEntitiesCallback async_add_entities)
dict[str, tuple[OneWireEntityDescription,...]] get_sensor_types(str device_sub_type)
list[OneWireSwitch] get_entities(OneWireHub onewire_hub)