Skip to content

Commit 21044ae

Browse files
committed
Invert contact protocols
1 parent dadaeaf commit 21044ae

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

custom_components/homeduino/binary_sensor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ async def async_setup_entry(
9898
device_class=device_class,
9999
id=id,
100100
unit=unit,
101+
inverted=protocol.startswith("contact"),
101102
)
102103

103104
entities.append(
@@ -132,6 +133,7 @@ class HomeduinoRFBinarySensorEntityDescription(
132133
id: int
133134
unit: int | None
134135
field: str | None = None
136+
inverted: bool = False
135137

136138

137139
class HomeduinoTransceiverBinarySensor(CoordinatorEntity, BinarySensorEntity):
@@ -239,10 +241,15 @@ def _handle_coordinator_update(self) -> None:
239241

240242
_LOGGER.debug(self.coordinator.data)
241243

242-
self._attr_is_on = self.coordinator.data.get("values", {}).get(
244+
is_on = self.coordinator.data.get("values", {}).get(
243245
self.entity_description.field
244246
if self.entity_description.field
245247
else "state"
246248
)
247249

250+
if self.entity_description.inverted:
251+
is_on = not is_on
252+
253+
self._attr_is_on = is_on
254+
248255
self.async_write_ha_state()

0 commit comments

Comments
 (0)