Skip to content

Commit

Permalink
improve binary_sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Oct 25, 2024
1 parent f7b9fc5 commit 68da05f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions custom_components/xiaomi_miot/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import json
from datetime import datetime
from functools import cached_property

from homeassistant.const import (
STATE_OFF,
Expand Down Expand Up @@ -91,16 +92,16 @@ def set_state(self, data: dict):
val = data.get(self.attr)
if val is None:
return
if self.invert:
if self.custom_reverse:
self._attr_extra_state_attributes['reverse_state'] = True
val = not val
self._attr_is_on = val

def get_state(self) -> dict:
return {self.attr: not self._attr_is_on if self.invert else self._attr_is_on}
return {self.attr: not self._attr_is_on if self.custom_reverse else self._attr_is_on}

@property
def invert(self) -> bool:
@cached_property
def custom_reverse(self):
return self.custom_config_bool('reverse_state', False)

XEntity.CLS[ENTITY_DOMAIN] = BinarySensorEntity
Expand Down

0 comments on commit 68da05f

Please sign in to comment.