Use attr** in lightwave (#61881)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-16 22:57:15 +01:00 committed by GitHub
parent bb538a9782
commit 6778e4058e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 139 deletions

View file

@ -1,6 +1,10 @@
"""Support for LightwaveRF TRV - Associated Battery."""
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.const import CONF_NAME, DEVICE_CLASS_BATTERY, PERCENTAGE
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import CONF_NAME, PERCENTAGE
from . import CONF_SERIAL, LIGHTWAVE_LINK
@ -25,31 +29,20 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class LightwaveBattery(SensorEntity):
"""Lightwave TRV Battery."""
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_state_class = SensorStateClass.MEASUREMENT
def __init__(self, name, lwlink, serial):
"""Initialize the Lightwave Trv battery sensor."""
self._name = name
self._state = None
self._attr_name = name
self._lwlink = lwlink
self._serial = serial
self._attr_unique_id = f"{serial}-trv-battery"
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def native_value(self):
"""Return the state of the sensor."""
return self._state
def update(self):
"""Communicate with a Lightwave RTF Proxy to get state."""
(dummy_temp, dummy_targ, battery, dummy_output) = self._lwlink.read_trv_status(
self._serial
)
self._state = battery
self._attr_native_value = battery