mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add some metadata to pvoutput energy sensor (#54074)
This commit is contained in:
parent
b930e17d64
commit
3655859be2
@ -6,7 +6,12 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.rest.data import RestData
|
from homeassistant.components.rest.data import RestData
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
PLATFORM_SCHEMA,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
SensorEntity,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DATE,
|
ATTR_DATE,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
@ -14,6 +19,7 @@ from homeassistant.const import (
|
|||||||
ATTR_VOLTAGE,
|
ATTR_VOLTAGE,
|
||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
|
ENERGY_WATT_HOUR,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -66,10 +72,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
class PvoutputSensor(SensorEntity):
|
class PvoutputSensor(SensorEntity):
|
||||||
"""Representation of a PVOutput sensor."""
|
"""Representation of a PVOutput sensor."""
|
||||||
|
|
||||||
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||||
|
_attr_unit_of_measurement = ENERGY_WATT_HOUR
|
||||||
|
|
||||||
def __init__(self, rest, name):
|
def __init__(self, rest, name):
|
||||||
"""Initialize a PVOutput sensor."""
|
"""Initialize a PVOutput sensor."""
|
||||||
self.rest = rest
|
self.rest = rest
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self.pvcoutput = None
|
self.pvcoutput = None
|
||||||
self.status = namedtuple(
|
self.status = namedtuple(
|
||||||
"status",
|
"status",
|
||||||
@ -86,11 +96,6 @@ class PvoutputSensor(SensorEntity):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
@ -125,6 +130,7 @@ class PvoutputSensor(SensorEntity):
|
|||||||
def _async_update_from_rest_data(self):
|
def _async_update_from_rest_data(self):
|
||||||
"""Update state from the rest data."""
|
"""Update state from the rest data."""
|
||||||
try:
|
try:
|
||||||
|
# https://pvoutput.org/help/api_specification.html#get-status-service
|
||||||
self.pvcoutput = self.status._make(self.rest.data.split(","))
|
self.pvcoutput = self.status._make(self.rest.data.split(","))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.pvcoutput = None
|
self.pvcoutput = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user