mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-11 17:14:28 +05:00
invert inputs
This commit is contained in:
@@ -16,7 +16,7 @@ from homeassistant.const import (
|
|||||||
CONF_ENTITY_ID,
|
CONF_ENTITY_ID,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from .const import EVENT_BINARY_SENSOR, DOMAIN, CONF_CUSTOM, CONF_SKIP
|
from .const import EVENT_BINARY_SENSOR, DOMAIN, CONF_CUSTOM, CONF_SKIP, CONF_INVERT
|
||||||
from .entities import MegaPushEntity
|
from .entities import MegaPushEntity
|
||||||
from .hub import MegaD
|
from .hub import MegaD
|
||||||
|
|
||||||
@@ -71,6 +71,10 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
|
|||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
return self._attrs
|
return self._attrs
|
||||||
|
|
||||||
|
@property
|
||||||
|
def invert(self):
|
||||||
|
return self.customize.get(CONF_INVERT, False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
val = self.mega.values.get(self.port, {}).get("value") \
|
val = self.mega.values.get(self.port, {}).get("value") \
|
||||||
@@ -79,9 +83,9 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
|
|||||||
return self._state == 'ON'
|
return self._state == 'ON'
|
||||||
elif val is not None:
|
elif val is not None:
|
||||||
if val in ['ON', 'OFF']:
|
if val in ['ON', 'OFF']:
|
||||||
return val == 'ON'
|
return val == 'ON' if not self.invert else val == 'OFF'
|
||||||
else:
|
else:
|
||||||
return val != 1
|
return val != 1 if not self.invert else val == 1
|
||||||
|
|
||||||
def _update(self, payload: dict):
|
def _update(self, payload: dict):
|
||||||
self.mega.values[self.port] = payload
|
self.mega.values[self.port] = payload
|
||||||
|
|||||||
Reference in New Issue
Block a user