From 3a5b66fd60eb157047fd20716a57b6c75628ccfc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 12 Oct 2022 15:02:47 +0200 Subject: [PATCH] Use percentage constant in components (#80173) --- homeassistant/components/amberelectric/sensor.py | 4 ++-- homeassistant/components/lyric/sensor.py | 3 ++- homeassistant/components/statistics/sensor.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/amberelectric/sensor.py b/homeassistant/components/amberelectric/sensor.py index 522cde2a95f..98aed91a941 100644 --- a/homeassistant/components/amberelectric/sensor.py +++ b/homeassistant/components/amberelectric/sensor.py @@ -20,7 +20,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CURRENCY_DOLLAR, ENERGY_KILO_WATT_HOUR +from homeassistant.const import CURRENCY_DOLLAR, ENERGY_KILO_WATT_HOUR, PERCENTAGE from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -247,7 +247,7 @@ async def async_setup_entry( renewables_description = SensorEntityDescription( key="renewables", name=f"{entry.title} - Renewables", - native_unit_of_measurement="%", + native_unit_of_measurement=PERCENTAGE, state_class=SensorStateClass.MEASUREMENT, icon="mdi:solar-power", ) diff --git a/homeassistant/components/lyric/sensor.py b/homeassistant/components/lyric/sensor.py index d727b24eee4..4d132381d42 100644 --- a/homeassistant/components/lyric/sensor.py +++ b/homeassistant/components/lyric/sensor.py @@ -16,6 +16,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry +from homeassistant.const import PERCENTAGE from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -114,7 +115,7 @@ async def async_setup_entry( name="Outdoor Humidity", device_class=SensorDeviceClass.HUMIDITY, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement="%", + native_unit_of_measurement=PERCENTAGE, value=lambda device: device.displayedOutdoorHumidity, ), location, diff --git a/homeassistant/components/statistics/sensor.py b/homeassistant/components/statistics/sensor.py index 3f33fa015b9..db50e4249f2 100644 --- a/homeassistant/components/statistics/sensor.py +++ b/homeassistant/components/statistics/sensor.py @@ -25,6 +25,7 @@ from homeassistant.const import ( CONF_ENTITY_ID, CONF_NAME, CONF_UNIQUE_ID, + PERCENTAGE, STATE_UNAVAILABLE, STATE_UNKNOWN, ) @@ -377,7 +378,7 @@ class StatisticsSensor(SensorEntity): base_unit: str | None = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) unit: str | None if self.is_binary and self._state_characteristic in STAT_BINARY_PERCENTAGE: - unit = "%" + unit = PERCENTAGE elif not base_unit: unit = None elif self._state_characteristic in STAT_NUMERIC_RETAIN_UNIT: