1 """Provides a binary sensor for Home Connect."""
3 from dataclasses
import dataclass
8 BinarySensorDeviceClass,
10 BinarySensorEntityDescription,
22 from .
import HomeConnectConfigEntry
23 from .api
import HomeConnectDevice
27 BSH_DOOR_STATE_CLOSED,
28 BSH_DOOR_STATE_LOCKED,
30 BSH_REMOTE_CONTROL_ACTIVATION_STATE,
31 BSH_REMOTE_START_ALLOWANCE_STATE,
33 REFRIGERATION_STATUS_DOOR_CHILLER,
34 REFRIGERATION_STATUS_DOOR_CLOSED,
35 REFRIGERATION_STATUS_DOOR_FREEZER,
36 REFRIGERATION_STATUS_DOOR_OPEN,
37 REFRIGERATION_STATUS_DOOR_REFRIGERATOR,
39 from .entity
import HomeConnectEntity
41 _LOGGER = logging.getLogger(__name__)
42 REFRIGERATION_DOOR_BOOLEAN_MAP = {
43 REFRIGERATION_STATUS_DOOR_CLOSED:
False,
44 REFRIGERATION_STATUS_DOOR_OPEN:
True,
48 @dataclass(frozen=True, kw_only=True)
50 """Entity Description class for binary sensors."""
52 boolean_map: dict[str, bool] |
None =
None
57 key=BSH_REMOTE_CONTROL_ACTIVATION_STATE,
58 translation_key=
"remote_control",
61 key=BSH_REMOTE_START_ALLOWANCE_STATE,
62 translation_key=
"remote_start",
65 key=
"BSH.Common.Status.LocalControlActive",
66 translation_key=
"local_control",
69 key=
"BSH.Common.Status.BatteryChargingState",
70 device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
72 "BSH.Common.EnumType.BatteryChargingState.Charging":
True,
73 "BSH.Common.EnumType.BatteryChargingState.Discharging":
False,
75 translation_key=
"battery_charging_state",
78 key=
"BSH.Common.Status.ChargingConnection",
79 device_class=BinarySensorDeviceClass.PLUG,
81 "BSH.Common.EnumType.ChargingConnection.Connected":
True,
82 "BSH.Common.EnumType.ChargingConnection.Disconnected":
False,
84 translation_key=
"charging_connection",
87 key=
"ConsumerProducts.CleaningRobot.Status.DustBoxInserted",
88 translation_key=
"dust_box_inserted",
91 key=
"ConsumerProducts.CleaningRobot.Status.Lifted",
92 translation_key=
"lifted",
95 key=
"ConsumerProducts.CleaningRobot.Status.Lost",
96 translation_key=
"lost",
99 key=REFRIGERATION_STATUS_DOOR_CHILLER,
100 boolean_map=REFRIGERATION_DOOR_BOOLEAN_MAP,
101 device_class=BinarySensorDeviceClass.DOOR,
102 translation_key=
"chiller_door",
105 key=REFRIGERATION_STATUS_DOOR_FREEZER,
106 boolean_map=REFRIGERATION_DOOR_BOOLEAN_MAP,
107 device_class=BinarySensorDeviceClass.DOOR,
108 translation_key=
"freezer_door",
111 key=REFRIGERATION_STATUS_DOOR_REFRIGERATOR,
112 boolean_map=REFRIGERATION_DOOR_BOOLEAN_MAP,
113 device_class=BinarySensorDeviceClass.DOOR,
114 translation_key=
"refrigerator_door",
121 entry: HomeConnectConfigEntry,
122 async_add_entities: AddEntitiesCallback,
124 """Set up the Home Connect binary sensor."""
127 entities: list[BinarySensorEntity] = []
128 for device
in entry.runtime_data.devices:
131 for description
in BINARY_SENSORS
132 if description.key
in device.appliance.status
134 if BSH_DOOR_STATE
in device.appliance.status:
142 """Binary sensor for Home Connect."""
144 entity_description: HomeConnectBinarySensorEntityDescription
148 """Return true if the binary sensor is available."""
152 """Update the binary sensor's status."""
153 if not self.
devicedevice.appliance.status
or not (
154 status := self.
devicedevice.appliance.status.get(self.
bsh_keybsh_key, {}).
get(ATTR_VALUE)
160 elif status
not in [
True,
False]:
164 _LOGGER.debug(
"Updated, new state: %s", self.
_attr_is_on_attr_is_on)
168 """Binary sensor for Home Connect Generic Door."""
170 _attr_has_entity_name =
False
174 device: HomeConnectDevice,
176 """Initialize the entity."""
181 device_class=BinarySensorDeviceClass.DOOR,
183 BSH_DOOR_STATE_CLOSED:
False,
184 BSH_DOOR_STATE_LOCKED:
False,
185 BSH_DOOR_STATE_OPEN:
True,
193 """Call when entity is added to hass."""
197 items = automations + scripts
201 entity_reg: er.EntityRegistry = er.async_get(self.
hasshass)
202 entity_automations = [
204 for automation_id
in automations
205 if (automation_entity := entity_reg.async_get(automation_id))
209 for script_id
in scripts
210 if (script_entity := entity_reg.async_get(script_id))
214 f
"- [{item.original_name}](/config/automation/edit/{item.unique_id})"
215 for item
in entity_automations
217 f
"- [{item.original_name}](/config/script/edit/{item.unique_id})"
218 for item
in entity_scripts
224 f
"deprecated_binary_common_door_sensor_{self.entity_id}",
225 breaks_in_ha_version=
"2025.5.0",
227 severity=IssueSeverity.WARNING,
228 translation_key=
"deprecated_binary_common_door_sensor",
229 translation_placeholders={
231 "items":
"\n".join(items_list),
236 """Call when entity will be removed from hass."""
238 self.
hasshass, DOMAIN, f
"deprecated_binary_common_door_sensor_{self.entity_id}"
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None __init__(self, HomeConnectDevice device)
list[str] automations_with_entity(HomeAssistant hass, str entity_id)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, HomeConnectConfigEntry entry, AddEntitiesCallback async_add_entities)
list[OneWireBinarySensor] get_entities(OneWireHub onewire_hub)
None async_create_issue(HomeAssistant hass, str entry_id)
None async_delete_issue(HomeAssistant hass, str entry_id)
list[str] scripts_with_entity(HomeAssistant hass, str entity_id)