diff --git a/homeassistant/components/apcupsd/binary_sensor.py b/homeassistant/components/apcupsd/binary_sensor.py index daf9592f3e6..8a1f98329bb 100644 --- a/homeassistant/components/apcupsd/binary_sensor.py +++ b/homeassistant/components/apcupsd/binary_sensor.py @@ -25,20 +25,9 @@ class OnlineStatus(BinarySensorEntity): def __init__(self, config, data): """Initialize the APCUPSd binary device.""" - self._config = config self._data = data - self._state = None - - @property - def name(self): - """Return the name of the UPS online status sensor.""" - return self._config[CONF_NAME] - - @property - def is_on(self): - """Return true if the UPS is online, else false.""" - return self._state & VALUE_ONLINE > 0 + self._attr_name = config[CONF_NAME] def update(self): """Get the status report from APCUPSd and set this entity's state.""" - self._state = int(self._data.status[KEY_STATUS], 16) + self._attr_is_on = int(self._data.status[KEY_STATUS], 16) & VALUE_ONLINE > 0 diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 36dc1155b7f..190a3f5f1d8 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -162,39 +162,18 @@ class APCUPSdSensor(SensorEntity): """Initialize the sensor.""" self._data = data self.type = sensor_type - self._name = SENSOR_PREFIX + SENSOR_TYPES[sensor_type][0] - self._unit = SENSOR_TYPES[sensor_type][1] - self._inferred_unit = None - self._state = None - - @property - def name(self): - """Return the name of the UPS sensor.""" - return self._name - - @property - def icon(self): - """Icon to use in the frontend, if any.""" - return SENSOR_TYPES[self.type][2] - - @property - def state(self): - """Return true if the UPS is online, else False.""" - return self._state - - @property - def unit_of_measurement(self): - """Return the unit of measurement of this entity, if any.""" - if not self._unit: - return self._inferred_unit - return self._unit + self._attr_name = SENSOR_PREFIX + SENSOR_TYPES[sensor_type][0] + self._attr_icon = SENSOR_TYPES[self.type][2] + if SENSOR_TYPES[sensor_type][1]: + self._attr_unit_of_measurement = SENSOR_TYPES[sensor_type][1] def update(self): """Get the latest status and use it to update our sensor state.""" if self.type.upper() not in self._data.status: - self._state = None - self._inferred_unit = None + self._attr_state = None else: - self._state, self._inferred_unit = infer_unit( + self._attr_state, inferred_unit = infer_unit( self._data.status[self.type.upper()] ) + if not self._attr_unit_of_measurement: + self._attr_unit_of_measurement = inferred_unit