Check status field for UPS online binary sensor (#30144)

Avoids issue where status was previously reported as offline when
battery was low or UPS was over voltage
pull/30456/head
Josh Anderson 2020-01-03 16:40:36 +00:00 committed by Paulus Schoutsen
parent 6b519499a7
commit 8a1fc8b8f0
2 changed files with 4 additions and 4 deletions

View File

@ -18,11 +18,11 @@ DEFAULT_HOST = "localhost"
DEFAULT_PORT = 3551
DOMAIN = "apcupsd"
KEY_STATUS = "STATUS"
KEY_STATUS = "STATFLAG"
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
VALUE_ONLINE = "ONLINE"
VALUE_ONLINE = 8
CONFIG_SCHEMA = vol.Schema(
{

View File

@ -34,8 +34,8 @@ class OnlineStatus(BinarySensorDevice):
@property
def is_on(self):
"""Return true if the UPS is online, else false."""
return self._state == apcupsd.VALUE_ONLINE
return self._state & apcupsd.VALUE_ONLINE > 0
def update(self):
"""Get the status report from APCUPSd and set this entity's state."""
self._state = self._data.status[apcupsd.KEY_STATUS]
self._state = int(self._data.status[apcupsd.KEY_STATUS], 16)