invert inputs

This commit is contained in:
Andrey
2021-01-31 17:36:56 +03:00
parent 5f94186a14
commit e8d92cfa36

View File

@@ -16,7 +16,7 @@ from homeassistant.const import (
CONF_ENTITY_ID,
)
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 .hub import MegaD
@@ -71,6 +71,10 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
def state_attributes(self):
return self._attrs
@property
def invert(self):
return self.customize.get(CONF_INVERT, False)
@property
def is_on(self) -> bool:
val = self.mega.values.get(self.port, {}).get("value") \
@@ -79,9 +83,9 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
return self._state == 'ON'
elif val is not None:
if val in ['ON', 'OFF']:
return val == 'ON'
return val == 'ON' if not self.invert else val == 'OFF'
else:
return val != 1
return val != 1 if not self.invert else val == 1
def _update(self, payload: dict):
self.mega.values[self.port] = payload