From 5a12056e59001afd2414c62e9442e37970d0d080 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Tue, 15 Sep 2020 19:59:26 +0200 Subject: [PATCH] Add and use volume cubic constants (#40106) --- homeassistant/components/airvisual/sensor.py | 4 ---- homeassistant/components/comfoconnect/sensor.py | 5 +++-- homeassistant/components/isy994/const.py | 12 +++++++----- homeassistant/components/mysensors/sensor.py | 3 ++- homeassistant/components/rainmachine/sensor.py | 4 ++-- .../components/zha/core/channels/smartenergy.py | 12 +++++++++--- homeassistant/const.py | 1 + 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/airvisual/sensor.py b/homeassistant/components/airvisual/sensor.py index 895ffa494a4..c67f31d0c3f 100644 --- a/homeassistant/components/airvisual/sensor.py +++ b/homeassistant/components/airvisual/sensor.py @@ -38,10 +38,6 @@ ATTR_POLLUTANT_SYMBOL = "pollutant_symbol" ATTR_POLLUTANT_UNIT = "pollutant_unit" ATTR_REGION = "region" -MASS_PARTS_PER_MILLION = "ppm" -MASS_PARTS_PER_BILLION = "ppb" -VOLUME_MICROGRAMS_PER_CUBIC_METER = "µg/m3" - SENSOR_KIND_LEVEL = "air_pollution_level" SENSOR_KIND_AQI = "air_quality_index" SENSOR_KIND_POLLUTANT = "main_pollutant" diff --git a/homeassistant/components/comfoconnect/sensor.py b/homeassistant/components/comfoconnect/sensor.py index 6ec92477555..5f04ba134a8 100644 --- a/homeassistant/components/comfoconnect/sensor.py +++ b/homeassistant/components/comfoconnect/sensor.py @@ -34,6 +34,7 @@ from homeassistant.const import ( TEMP_CELSIUS, TIME_DAYS, TIME_HOURS, + VOLUME_CUBIC_METERS, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -159,14 +160,14 @@ SENSOR_TYPES = { ATTR_AIR_FLOW_SUPPLY: { ATTR_DEVICE_CLASS: None, ATTR_LABEL: "Supply airflow", - ATTR_UNIT: f"m³/{TIME_HOURS}", + ATTR_UNIT: f"{VOLUME_CUBIC_METERS}/{TIME_HOURS}", ATTR_ICON: "mdi:fan", ATTR_ID: SENSOR_FAN_SUPPLY_FLOW, }, ATTR_AIR_FLOW_EXHAUST: { ATTR_DEVICE_CLASS: None, ATTR_LABEL: "Exhaust airflow", - ATTR_UNIT: f"m³/{TIME_HOURS}", + ATTR_UNIT: f"{VOLUME_CUBIC_METERS}/{TIME_HOURS}", ATTR_ICON: "mdi:fan", ATTR_ID: SENSOR_FAN_EXHAUST_FLOW, }, diff --git a/homeassistant/components/isy994/const.py b/homeassistant/components/isy994/const.py index d911fae2c82..4fb32d3843d 100644 --- a/homeassistant/components/isy994/const.py +++ b/homeassistant/components/isy994/const.py @@ -86,6 +86,8 @@ from homeassistant.const import ( TIME_YEARS, UV_INDEX, VOLT, + VOLUME_CUBIC_FEET, + VOLUME_CUBIC_METERS, VOLUME_GALLONS, VOLUME_LITERS, ) @@ -316,9 +318,9 @@ UOM_FRIENDLY_NAME = { "3": f"btu/{TIME_HOURS}", "4": TEMP_CELSIUS, "5": LENGTH_CENTIMETERS, - "6": f"{LENGTH_FEET}³", - "7": f"{LENGTH_FEET}³/{TIME_MINUTES}", - "8": "m³", + "6": VOLUME_CUBIC_FEET, + "7": f"{VOLUME_CUBIC_FEET}/{TIME_MINUTES}", + "8": f"{VOLUME_CUBIC_METERS}", "9": TIME_DAYS, "10": TIME_DAYS, "12": "dB", @@ -347,7 +349,7 @@ UOM_FRIENDLY_NAME = { "36": "lx", "37": "mercalli", "38": LENGTH_METERS, - "39": f"{LENGTH_METERS}³/{TIME_HOURS}", + "39": f"{VOLUME_CUBIC_METERS}/{TIME_HOURS}", "40": SPEED_METERS_PER_SECOND, "41": "mA", "42": TIME_MILLISECONDS, @@ -385,7 +387,7 @@ UOM_FRIENDLY_NAME = { "83": LENGTH_KILOMETERS, "85": "Ω", "86": "kΩ", - "87": f"{LENGTH_METERS}³/{LENGTH_METERS}³", + "87": f"{VOLUME_CUBIC_METERS}/{VOLUME_CUBIC_METERS}", "88": "Water activity", "89": "RPM", "90": FREQUENCY_HERTZ, diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index 8ff2139a7b4..24c1d9be09b 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -15,6 +15,7 @@ from homeassistant.const import ( TEMP_CELSIUS, TEMP_FAHRENHEIT, VOLT, + VOLUME_CUBIC_METERS, ) SENSORS = { @@ -36,7 +37,7 @@ SENSORS = { "V_KWH": [ENERGY_KILO_WATT_HOUR, None], "V_LIGHT_LEVEL": [PERCENTAGE, "mdi:white-balance-sunny"], "V_FLOW": [LENGTH_METERS, "mdi:gauge"], - "V_VOLUME": ["m³", None], + "V_VOLUME": [f"{VOLUME_CUBIC_METERS}", None], "V_LEVEL": { "S_SOUND": ["dB", "mdi:volume-high"], "S_VIBRATION": [FREQUENCY_HERTZ, None], diff --git a/homeassistant/components/rainmachine/sensor.py b/homeassistant/components/rainmachine/sensor.py index 6f87c34d607..8534748978d 100644 --- a/homeassistant/components/rainmachine/sensor.py +++ b/homeassistant/components/rainmachine/sensor.py @@ -1,7 +1,7 @@ """This platform provides support for sensor data from RainMachine.""" import logging -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import TEMP_CELSIUS, VOLUME_CUBIC_METERS from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -26,7 +26,7 @@ SENSORS = { TYPE_FLOW_SENSOR_CLICK_M3: ( "Flow Sensor Clicks", "mdi:water-pump", - "clicks/m^3", + f"clicks/{VOLUME_CUBIC_METERS}", None, False, DATA_PROVISION_SETTINGS, diff --git a/homeassistant/components/zha/core/channels/smartenergy.py b/homeassistant/components/zha/core/channels/smartenergy.py index 9138ea09782..a4bd2bf2d40 100644 --- a/homeassistant/components/zha/core/channels/smartenergy.py +++ b/homeassistant/components/zha/core/channels/smartenergy.py @@ -3,7 +3,13 @@ import logging import zigpy.zcl.clusters.smartenergy as smartenergy -from homeassistant.const import LENGTH_FEET, POWER_WATT, TIME_HOURS, TIME_SECONDS +from homeassistant.const import ( + POWER_WATT, + TIME_HOURS, + TIME_SECONDS, + VOLUME_CUBIC_FEET, + VOLUME_CUBIC_METERS, +) from homeassistant.core import callback from .. import registries, typing as zha_typing @@ -61,8 +67,8 @@ class Metering(ZigbeeChannel): unit_of_measure_map = { 0x00: POWER_WATT, - 0x01: f"m³/{TIME_HOURS}", - 0x02: f"{LENGTH_FEET}³/{TIME_HOURS}", + 0x01: f"{VOLUME_CUBIC_METERS}/{TIME_HOURS}", + 0x02: f"{VOLUME_CUBIC_FEET}/{TIME_HOURS}", 0x03: f"ccf/{TIME_HOURS}", 0x04: f"US gal/{TIME_HOURS}", 0x05: f"IMP gal/{TIME_HOURS}", diff --git a/homeassistant/const.py b/homeassistant/const.py index fc44f6a8712..22fde9f21dd 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -422,6 +422,7 @@ PRESSURE_PSI: str = "psi" VOLUME_LITERS: str = "L" VOLUME_MILLILITERS: str = "mL" VOLUME_CUBIC_METERS = f"{LENGTH_METERS}³" +VOLUME_CUBIC_FEET = f"{LENGTH_FEET}³" VOLUME_GALLONS: str = "gal" VOLUME_FLUID_OUNCE: str = "fl. oz."