From 7de1fe7416410f51d6e7280f1552cfd77b301ffd Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sat, 19 Sep 2020 17:30:22 +0200 Subject: [PATCH] Use percentage constant in more integrations (#40165) --- homeassistant/components/growatt_server/sensor.py | 5 +++-- homeassistant/components/numato/__init__.py | 4 ++-- tests/components/nut/test_sensor.py | 6 +++--- tests/testing_config/custom_components/test/sensor.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/growatt_server/sensor.py b/homeassistant/components/growatt_server/sensor.py index 384b35a0aff..e6ed422db0f 100644 --- a/homeassistant/components/growatt_server/sensor.py +++ b/homeassistant/components/growatt_server/sensor.py @@ -22,6 +22,7 @@ from homeassistant.const import ( ELECTRICAL_CURRENT_AMPERE, ENERGY_KILO_WATT_HOUR, FREQUENCY_HERTZ, + PERCENTAGE, POWER_WATT, TEMP_CELSIUS, VOLT, @@ -231,7 +232,7 @@ STORAGE_SENSOR_TYPES = { ), "storage_battery_percentage": ( "Battery percentage", - "%", + PERCENTAGE, "capacity", {"device_class": DEVICE_CLASS_BATTERY}, ), @@ -339,7 +340,7 @@ STORAGE_SENSOR_TYPES = { ), "storage_load_percentage": ( "Load percentage", - "%", + PERCENTAGE, "loadPercent", {"device_class": DEVICE_CLASS_BATTERY, "round": 2}, ), diff --git a/homeassistant/components/numato/__init__.py b/homeassistant/components/numato/__init__.py index 8efc56e12fe..0f088cd179d 100644 --- a/homeassistant/components/numato/__init__.py +++ b/homeassistant/components/numato/__init__.py @@ -12,6 +12,7 @@ from homeassistant.const import ( CONF_SWITCHES, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, + PERCENTAGE, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import load_platform @@ -31,7 +32,6 @@ CONF_DST_UNIT = "unit" DEFAULT_INVERT_LOGIC = False DEFAULT_SRC_RANGE = [0, 1024] DEFAULT_DST_RANGE = [0.0, 100.0] -DEFAULT_UNIT = "%" DEFAULT_DEV = [f"/dev/ttyACM{i}" for i in range(10)] PORT_RANGE = range(1, 8) # ports 0-7 are ADC capable @@ -82,7 +82,7 @@ ADC_SCHEMA = vol.Schema( vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_SRC_RANGE, default=DEFAULT_SRC_RANGE): int_range, vol.Optional(CONF_DST_RANGE, default=DEFAULT_DST_RANGE): float_range, - vol.Optional(CONF_DST_UNIT, default=DEFAULT_UNIT): cv.string, + vol.Optional(CONF_DST_UNIT, default=PERCENTAGE): cv.string, } ) diff --git a/tests/components/nut/test_sensor.py b/tests/components/nut/test_sensor.py index 42fdc09e2b1..4950d467d6a 100644 --- a/tests/components/nut/test_sensor.py +++ b/tests/components/nut/test_sensor.py @@ -72,7 +72,7 @@ async def test_5e850i(hass): "device_class": "battery", "friendly_name": "Ups1 Battery Charge", "state": "Online", - "unit_of_measurement": "%", + "unit_of_measurement": PERCENTAGE, } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears @@ -97,7 +97,7 @@ async def test_5e650i(hass): "device_class": "battery", "friendly_name": "Ups1 Battery Charge", "state": "Online Battery Charging", - "unit_of_measurement": "%", + "unit_of_measurement": PERCENTAGE, } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears @@ -125,7 +125,7 @@ async def test_backupsses600m1(hass): "device_class": "battery", "friendly_name": "Ups1 Battery Charge", "state": "Online", - "unit_of_measurement": "%", + "unit_of_measurement": PERCENTAGE, } # Only test for a subset of attributes in case # HA changes the implementation and a new one appears diff --git a/tests/testing_config/custom_components/test/sensor.py b/tests/testing_config/custom_components/test/sensor.py index 7cb8bb070b1..d9ed47844af 100644 --- a/tests/testing_config/custom_components/test/sensor.py +++ b/tests/testing_config/custom_components/test/sensor.py @@ -22,7 +22,7 @@ UNITS_OF_MEASUREMENT = { sensor.DEVICE_CLASS_POWER: "kW", # power (W/kW) sensor.DEVICE_CLASS_CURRENT: "A", # current (A) sensor.DEVICE_CLASS_ENERGY: "kWh", # energy (Wh/kWh) - sensor.DEVICE_CLASS_POWER_FACTOR: "%", # power factor (no unit, min: -1.0, max: 1.0) + sensor.DEVICE_CLASS_POWER_FACTOR: PERCENTAGE, # power factor (no unit, min: -1.0, max: 1.0) sensor.DEVICE_CLASS_VOLTAGE: "V", # voltage (V) }