mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add state class to powerwall (#52102)
This commit is contained in:
parent
de5431c037
commit
c31f267106
@ -3,7 +3,7 @@ import logging
|
|||||||
|
|
||||||
from tesla_powerwall import MeterType
|
from tesla_powerwall import MeterType
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
||||||
from homeassistant.const import DEVICE_CLASS_BATTERY, DEVICE_CLASS_POWER, PERCENTAGE
|
from homeassistant.const import DEVICE_CLASS_BATTERY, DEVICE_CLASS_POWER, PERCENTAGE
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -64,20 +64,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
|
class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
|
||||||
"""Representation of an Powerwall charge sensor."""
|
"""Representation of an Powerwall charge sensor."""
|
||||||
|
|
||||||
@property
|
_attr_name = "Powerwall Charge"
|
||||||
def unit_of_measurement(self):
|
_attr_unit_of_measurement = PERCENTAGE
|
||||||
"""Return the unit of measurement."""
|
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||||
return PERCENTAGE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Device Name."""
|
|
||||||
return "Powerwall Charge"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Device Class."""
|
|
||||||
return DEVICE_CLASS_BATTERY
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
@ -93,6 +82,10 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
|
|||||||
class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
|
class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
|
||||||
"""Representation of an Powerwall Energy sensor."""
|
"""Representation of an Powerwall Energy sensor."""
|
||||||
|
|
||||||
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
_attr_unit_of_measurement = ENERGY_KILO_WATT
|
||||||
|
_attr_device_class = DEVICE_CLASS_POWER
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
meter: MeterType,
|
meter: MeterType,
|
||||||
@ -107,26 +100,10 @@ class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
|
|||||||
coordinator, site_info, status, device_type, powerwalls_serial_numbers
|
coordinator, site_info, status, device_type, powerwalls_serial_numbers
|
||||||
)
|
)
|
||||||
self._meter = meter
|
self._meter = meter
|
||||||
|
self._attr_name = f"Powerwall {self._meter.value.title()} Now"
|
||||||
@property
|
self._attr_unique_id = (
|
||||||
def unit_of_measurement(self):
|
f"{self.base_unique_id}_{self._meter.value}_instant_power"
|
||||||
"""Return the unit of measurement."""
|
)
|
||||||
return ENERGY_KILO_WATT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Device Name."""
|
|
||||||
return f"Powerwall {self._meter.value.title()} Now"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Device Class."""
|
|
||||||
return DEVICE_CLASS_POWER
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Device Uniqueid."""
|
|
||||||
return f"{self.base_unique_id}_{self._meter.value}_instant_power"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user