Use unit constants (#53244)

* Powerwall - use POWER_KILO_WATT constant

* Use constants firtz sensor
This commit is contained in:
Marc Mueller 2021-07-20 20:08:39 +02:00 committed by GitHub
parent a05392fbf2
commit 6be30b0289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View file

@ -10,7 +10,11 @@ from fritzconnection.lib.fritzstatus import FritzStatus
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_TIMESTAMP
from homeassistant.const import (
DATA_GIGABYTES,
DATA_RATE_KILOBYTES_PER_SECOND,
DEVICE_CLASS_TIMESTAMP,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utcnow
@ -97,38 +101,38 @@ SENSOR_DATA = {
"kb_s_sent": SensorData(
name="kB/s sent",
state_class=STATE_CLASS_MEASUREMENT,
unit_of_measurement="kB/s",
unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
icon="mdi:upload",
state_provider=_retrieve_kb_s_sent_state,
),
"kb_s_received": SensorData(
name="kB/s received",
state_class=STATE_CLASS_MEASUREMENT,
unit_of_measurement="kB/s",
unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
icon="mdi:download",
state_provider=_retrieve_kb_s_received_state,
),
"max_kb_s_sent": SensorData(
name="Max kb/s sent",
unit_of_measurement="kb/s",
name="Max kB/s sent",
unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
icon="mdi:upload",
state_provider=_retrieve_max_kb_s_sent_state,
),
"max_kb_s_received": SensorData(
name="Max kb/s received",
unit_of_measurement="kb/s",
name="Max kB/s received",
unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
icon="mdi:download",
state_provider=_retrieve_max_kb_s_received_state,
),
"gb_sent": SensorData(
name="GB sent",
unit_of_measurement="GB",
unit_of_measurement=DATA_GIGABYTES,
icon="mdi:upload",
state_provider=_retrieve_gb_sent_state,
),
"gb_received": SensorData(
name="GB received",
unit_of_measurement="GB",
unit_of_measurement=DATA_GIGABYTES,
icon="mdi:download",
state_provider=_retrieve_gb_received_state,
),

View file

@ -32,5 +32,3 @@ POWERWALL_HTTP_SESSION = "http_session"
MODEL = "PowerWall 2"
MANUFACTURER = "Tesla"
ENERGY_KILO_WATT = "kW"

View file

@ -4,7 +4,12 @@ import logging
from tesla_powerwall import MeterType
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,
POWER_KILO_WATT,
)
from .const import (
ATTR_ENERGY_EXPORTED,
@ -14,7 +19,6 @@ from .const import (
ATTR_INSTANT_TOTAL_CURRENT,
ATTR_IS_ACTIVE,
DOMAIN,
ENERGY_KILO_WATT,
POWERWALL_API_CHARGE,
POWERWALL_API_DEVICE_TYPE,
POWERWALL_API_METERS,
@ -83,7 +87,7 @@ class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall Energy sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_unit_of_measurement = ENERGY_KILO_WATT
_attr_unit_of_measurement = POWER_KILO_WATT
_attr_device_class = DEVICE_CLASS_POWER
def __init__(