From 6be30b0289371bf71915ae31246ef37d7d34a45e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 20 Jul 2021 20:08:39 +0200 Subject: [PATCH] Use unit constants (#53244) * Powerwall - use POWER_KILO_WATT constant * Use constants firtz sensor --- homeassistant/components/fritz/sensor.py | 22 ++++++++++++-------- homeassistant/components/powerwall/const.py | 2 -- homeassistant/components/powerwall/sensor.py | 10 ++++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/fritz/sensor.py b/homeassistant/components/fritz/sensor.py index 5820be138b4..031f7bc555c 100644 --- a/homeassistant/components/fritz/sensor.py +++ b/homeassistant/components/fritz/sensor.py @@ -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, ), diff --git a/homeassistant/components/powerwall/const.py b/homeassistant/components/powerwall/const.py index f338d5f981d..c86333cb9f8 100644 --- a/homeassistant/components/powerwall/const.py +++ b/homeassistant/components/powerwall/const.py @@ -32,5 +32,3 @@ POWERWALL_HTTP_SESSION = "http_session" MODEL = "PowerWall 2" MANUFACTURER = "Tesla" - -ENERGY_KILO_WATT = "kW" diff --git a/homeassistant/components/powerwall/sensor.py b/homeassistant/components/powerwall/sensor.py index d6c326593aa..d536c776bf0 100644 --- a/homeassistant/components/powerwall/sensor.py +++ b/homeassistant/components/powerwall/sensor.py @@ -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__(