mirror of
https://github.com/home-assistant/core.git
synced 2025-06-01 03:37:08 +00:00
Use entity class attributes for aurora_abb_power (#52692)
This commit is contained in:
parent
b021e2ee8c
commit
71b14b51b4
@ -51,32 +51,13 @@ class AuroraABBSolarPVMonitorSensor(SensorEntity):
|
|||||||
"""Representation of a Sensor."""
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
_attr_unit_of_measurement = POWER_WATT
|
||||||
|
_attr_device_class = DEVICE_CLASS_POWER
|
||||||
|
|
||||||
def __init__(self, client, name, typename):
|
def __init__(self, client, name, typename):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._name = f"{name} {typename}"
|
self._attr_name = f"{name} {typename}"
|
||||||
self.client = client
|
self.client = client
|
||||||
self._state = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return POWER_WATT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class."""
|
|
||||||
return DEVICE_CLASS_POWER
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for the sensor.
|
"""Fetch new state data for the sensor.
|
||||||
@ -87,8 +68,7 @@ class AuroraABBSolarPVMonitorSensor(SensorEntity):
|
|||||||
self.client.connect()
|
self.client.connect()
|
||||||
# read ADC channel 3 (grid power output)
|
# read ADC channel 3 (grid power output)
|
||||||
power_watts = self.client.measure(3, True)
|
power_watts = self.client.measure(3, True)
|
||||||
self._state = round(power_watts, 1)
|
self._attr_state = round(power_watts, 1)
|
||||||
# _LOGGER.debug("Got reading %fW" % self._state)
|
|
||||||
except AuroraError as error:
|
except AuroraError as error:
|
||||||
# aurorapy does not have different exceptions (yet) for dealing
|
# aurorapy does not have different exceptions (yet) for dealing
|
||||||
# with timeout vs other comms errors.
|
# with timeout vs other comms errors.
|
||||||
@ -102,7 +82,7 @@ class AuroraABBSolarPVMonitorSensor(SensorEntity):
|
|||||||
_LOGGER.debug("No response from inverter (could be dark)")
|
_LOGGER.debug("No response from inverter (could be dark)")
|
||||||
else:
|
else:
|
||||||
raise error
|
raise error
|
||||||
self._state = None
|
self._attr_state = None
|
||||||
finally:
|
finally:
|
||||||
if self.client.serline.isOpen():
|
if self.client.serline.isOpen():
|
||||||
self.client.close()
|
self.client.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user