Remove global variable from apcupsd (#33717)
* Remove global variable from apcupsd * Run isort * Address review comments
This commit is contained in:
1 parent
00e67fb2c7
commit
60dd2213cf
3 files changed
+15
-13
No files matched your search
@@ -1,11 +1,12 @@
|
||||
"""Support for tracking the online status of a UPS."""
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import apcupsd
|
||||
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorDevice
|
||||
from homeassistant.const import CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from . import DOMAIN, KEY_STATUS, VALUE_ONLINE
|
||||
|
||||
DEFAULT_NAME = "UPS Online Status"
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string}
|
||||
@@ -14,7 +15,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up an APCUPSd Online Status binary sensor."""
|
||||
add_entities([OnlineStatus(config, apcupsd.DATA)], True)
|
||||
apcups_data = hass.data[DOMAIN]
|
||||
|
||||
add_entities([OnlineStatus(config, apcups_data)], True)
|
||||
|
||||
|
||||
class OnlineStatus(BinarySensorDevice):
|
||||
@@ -34,8 +37,8 @@ class OnlineStatus(BinarySensorDevice):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the UPS is online, else false."""
|
||||
return self._state & apcupsd.VALUE_ONLINE > 0
|
||||
return self._state & VALUE_ONLINE > 0
|
||||
|
||||
def update(self):
|
||||
"""Get the status report from APCUPSd and set this entity's state."""
|
||||
self._state = int(self._data.status[apcupsd.KEY_STATUS], 16)
|
||||
self._state = int(self._data.status[KEY_STATUS], 16)
|
||||
Reference in new issue
Block a user