1 """Binary sensors for key RainMachine data."""
3 from dataclasses
import dataclass
6 DOMAIN
as BINARY_SENSOR_DOMAIN,
8 BinarySensorEntityDescription,
14 from .
import RainMachineConfigEntry
15 from .const
import DATA_PROVISION_SETTINGS, DATA_RESTRICTIONS_CURRENT
16 from .entity
import RainMachineEntity, RainMachineEntityDescription
18 EntityDomainReplacementStrategy,
19 async_finish_entity_domain_replacements,
23 TYPE_FLOW_SENSOR =
"flow_sensor"
24 TYPE_FREEZE =
"freeze"
25 TYPE_HOURLY =
"hourly"
27 TYPE_RAINDELAY =
"raindelay"
28 TYPE_RAINSENSOR =
"rainsensor"
29 TYPE_WEEKDAY =
"weekday"
32 @dataclass(frozen=True, kw_only=True)
34 BinarySensorEntityDescription, RainMachineEntityDescription
36 """Describe a RainMachine binary sensor."""
41 BINARY_SENSOR_DESCRIPTIONS = (
44 translation_key=TYPE_FLOW_SENSOR,
45 api_category=DATA_PROVISION_SETTINGS,
46 data_key=
"useFlowSensor",
50 translation_key=TYPE_FREEZE,
51 entity_category=EntityCategory.DIAGNOSTIC,
52 api_category=DATA_RESTRICTIONS_CURRENT,
57 translation_key=TYPE_HOURLY,
58 entity_category=EntityCategory.DIAGNOSTIC,
59 api_category=DATA_RESTRICTIONS_CURRENT,
64 translation_key=TYPE_MONTH,
65 entity_category=EntityCategory.DIAGNOSTIC,
66 api_category=DATA_RESTRICTIONS_CURRENT,
71 translation_key=TYPE_RAINDELAY,
72 entity_category=EntityCategory.DIAGNOSTIC,
73 api_category=DATA_RESTRICTIONS_CURRENT,
78 translation_key=TYPE_RAINSENSOR,
79 entity_category=EntityCategory.DIAGNOSTIC,
80 entity_registry_enabled_default=
False,
81 api_category=DATA_RESTRICTIONS_CURRENT,
82 data_key=
"rainSensor",
86 translation_key=TYPE_WEEKDAY,
87 entity_category=EntityCategory.DIAGNOSTIC,
88 api_category=DATA_RESTRICTIONS_CURRENT,
96 entry: RainMachineConfigEntry,
97 async_add_entities: AddEntitiesCallback,
99 """Set up RainMachine binary sensors based on a config entry."""
100 data = entry.runtime_data
107 BINARY_SENSOR_DOMAIN,
108 f
"{data.controller.mac}_freeze_protection",
109 f
"switch.{data.controller.name.lower()}_freeze_protect_enabled",
110 breaks_in_ha_version=
"2022.12.0",
111 remove_old_entity=
True,
114 BINARY_SENSOR_DOMAIN,
115 f
"{data.controller.mac}_extra_water_on_hot_days",
116 f
"switch.{data.controller.name.lower()}_hot_days_extra_watering",
117 breaks_in_ha_version=
"2022.12.0",
118 remove_old_entity=
True,
123 api_category_sensor_map = {
124 DATA_PROVISION_SETTINGS: ProvisionSettingsBinarySensor,
125 DATA_RESTRICTIONS_CURRENT: CurrentRestrictionsBinarySensor,
129 api_category_sensor_map[description.api_category](entry, data, description)
130 for description
in BINARY_SENSOR_DESCRIPTIONS
132 (coordinator := data.coordinators[description.api_category])
is not None
134 and key_exists(coordinator.data, description.data_key)
140 """Define a binary sensor that handles current restrictions data."""
142 entity_description: RainMachineBinarySensorDescription
146 """Update the state."""
150 self.
_attr_is_on_attr_is_on = self.coordinator.data.get(
"hourly")
152 self.
_attr_is_on_attr_is_on = self.coordinator.data.get(
"month")
154 self.
_attr_is_on_attr_is_on = self.coordinator.data.get(
"rainDelay")
156 self.
_attr_is_on_attr_is_on = self.coordinator.data.get(
"rainSensor")
158 self.
_attr_is_on_attr_is_on = self.coordinator.data.get(
"weekDay")
162 """Define a binary sensor that handles provisioning data."""
164 entity_description: RainMachineBinarySensorDescription
168 """Update the state."""
None update_from_latest_data(self)
None update_from_latest_data(self)
web.Response get(self, web.Request request, str config_key)
None async_finish_entity_domain_replacements(HomeAssistant hass, ConfigEntry entry, Iterable[EntityDomainReplacementStrategy] entity_replacement_strategies)
None async_setup_entry(HomeAssistant hass, RainMachineConfigEntry entry, AddEntitiesCallback async_add_entities)
bool key_exists(dict[str, Any] data, str search_key)