Add and use more unit constants (#32122)
* Add and use speed constants * Add and use meter based volume and area constants * Add and use more mass unit constants * Add and use concentration unit constants * Add and use watts per square meter constant * Use more time constants * Use more data constantspull/32167/head
parent
c98f50115d
commit
496bd3dddf
|
@ -2,6 +2,7 @@
|
|||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_DEVICE_CLASS,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONF_NAME,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
|
@ -27,14 +28,13 @@ ATTR_LABEL = "label"
|
|||
ATTR_UNIT = "unit"
|
||||
|
||||
HUMI_PERCENT = "%"
|
||||
VOLUME_MICROGRAMS_PER_CUBIC_METER = "µg/m³"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
ATTR_API_PM1: {
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
ATTR_ICON: "mdi:blur",
|
||||
ATTR_LABEL: ATTR_API_PM1,
|
||||
ATTR_UNIT: VOLUME_MICROGRAMS_PER_CUBIC_METER,
|
||||
ATTR_UNIT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
},
|
||||
ATTR_API_HUMIDITY: {
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
|
|
|
@ -11,6 +11,9 @@ from homeassistant.const import (
|
|||
ATTR_ATTRIBUTION,
|
||||
ATTR_LATITUDE,
|
||||
ATTR_LONGITUDE,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_API_KEY,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
|
@ -37,10 +40,6 @@ CONF_COUNTRY = "country"
|
|||
DEFAULT_ATTRIBUTION = "Data provided by AirVisual"
|
||||
DEFAULT_SCAN_INTERVAL = timedelta(minutes=10)
|
||||
|
||||
MASS_PARTS_PER_MILLION = "ppm"
|
||||
MASS_PARTS_PER_BILLION = "ppb"
|
||||
VOLUME_MICROGRAMS_PER_CUBIC_METER = "µg/m3"
|
||||
|
||||
SENSOR_TYPE_LEVEL = "air_pollution_level"
|
||||
SENSOR_TYPE_AQI = "air_quality_index"
|
||||
SENSOR_TYPE_POLLUTANT = "main_pollutant"
|
||||
|
@ -70,12 +69,12 @@ POLLUTANT_LEVEL_MAPPING = [
|
|||
]
|
||||
|
||||
POLLUTANT_MAPPING = {
|
||||
"co": {"label": "Carbon Monoxide", "unit": MASS_PARTS_PER_MILLION},
|
||||
"n2": {"label": "Nitrogen Dioxide", "unit": MASS_PARTS_PER_BILLION},
|
||||
"o3": {"label": "Ozone", "unit": MASS_PARTS_PER_BILLION},
|
||||
"p1": {"label": "PM10", "unit": VOLUME_MICROGRAMS_PER_CUBIC_METER},
|
||||
"p2": {"label": "PM2.5", "unit": VOLUME_MICROGRAMS_PER_CUBIC_METER},
|
||||
"s2": {"label": "Sulfur Dioxide", "unit": MASS_PARTS_PER_BILLION},
|
||||
"co": {"label": "Carbon Monoxide", "unit": CONCENTRATION_PARTS_PER_MILLION},
|
||||
"n2": {"label": "Nitrogen Dioxide", "unit": CONCENTRATION_PARTS_PER_BILLION},
|
||||
"o3": {"label": "Ozone", "unit": CONCENTRATION_PARTS_PER_BILLION},
|
||||
"p1": {"label": "PM10", "unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
|
||||
"p2": {"label": "PM2.5", "unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
|
||||
"s2": {"label": "Sulfur Dioxide", "unit": CONCENTRATION_PARTS_PER_BILLION},
|
||||
}
|
||||
|
||||
SENSOR_LOCALES = {"cn": "Chinese", "us": "U.S."}
|
||||
|
|
|
@ -10,8 +10,10 @@ from homeassistant.config_entries import SOURCE_IMPORT
|
|||
from homeassistant.const import (
|
||||
ATTR_LOCATION,
|
||||
ATTR_NAME,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_API_KEY,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
@ -147,7 +149,7 @@ SENSOR_TYPES = {
|
|||
TYPE_BATT8: ("Battery 8", None, TYPE_BINARY_SENSOR, "battery"),
|
||||
TYPE_BATT9: ("Battery 9", None, TYPE_BINARY_SENSOR, "battery"),
|
||||
TYPE_BATTOUT: ("Battery", None, TYPE_BINARY_SENSOR, "battery"),
|
||||
TYPE_CO2: ("co2", "ppm", TYPE_SENSOR, None),
|
||||
TYPE_CO2: ("co2", CONCENTRATION_PARTS_PER_MILLION, TYPE_SENSOR, None),
|
||||
TYPE_DAILYRAININ: ("Daily Rain", "in", TYPE_SENSOR, None),
|
||||
TYPE_DEWPOINT: ("Dew Point", "°F", TYPE_SENSOR, "temperature"),
|
||||
TYPE_EVENTRAININ: ("Event Rain", "in", TYPE_SENSOR, None),
|
||||
|
@ -166,7 +168,7 @@ SENSOR_TYPES = {
|
|||
TYPE_HUMIDITY: ("Humidity", "%", TYPE_SENSOR, "humidity"),
|
||||
TYPE_HUMIDITYIN: ("Humidity In", "%", TYPE_SENSOR, "humidity"),
|
||||
TYPE_LASTRAIN: ("Last Rain", None, TYPE_SENSOR, "timestamp"),
|
||||
TYPE_MAXDAILYGUST: ("Max Gust", "mph", TYPE_SENSOR, None),
|
||||
TYPE_MAXDAILYGUST: ("Max Gust", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
|
||||
TYPE_MONTHLYRAININ: ("Monthly Rain", "in", TYPE_SENSOR, None),
|
||||
TYPE_RELAY10: ("Relay 10", None, TYPE_BINARY_SENSOR, "connectivity"),
|
||||
TYPE_RELAY1: ("Relay 1", None, TYPE_BINARY_SENSOR, "connectivity"),
|
||||
|
@ -217,12 +219,12 @@ SENSOR_TYPES = {
|
|||
TYPE_WEEKLYRAININ: ("Weekly Rain", "in", TYPE_SENSOR, None),
|
||||
TYPE_WINDDIR: ("Wind Dir", "°", TYPE_SENSOR, None),
|
||||
TYPE_WINDDIR_AVG10M: ("Wind Dir Avg 10m", "°", TYPE_SENSOR, None),
|
||||
TYPE_WINDDIR_AVG2M: ("Wind Dir Avg 2m", "mph", TYPE_SENSOR, None),
|
||||
TYPE_WINDDIR_AVG2M: ("Wind Dir Avg 2m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
|
||||
TYPE_WINDGUSTDIR: ("Gust Dir", "°", TYPE_SENSOR, None),
|
||||
TYPE_WINDGUSTMPH: ("Wind Gust", "mph", TYPE_SENSOR, None),
|
||||
TYPE_WINDSPDMPH_AVG10M: ("Wind Avg 10m", "mph", TYPE_SENSOR, None),
|
||||
TYPE_WINDSPDMPH_AVG2M: ("Wind Avg 2m", "mph", TYPE_SENSOR, None),
|
||||
TYPE_WINDSPEEDMPH: ("Wind Speed", "mph", TYPE_SENSOR, None),
|
||||
TYPE_WINDGUSTMPH: ("Wind Gust", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
|
||||
TYPE_WINDSPDMPH_AVG10M: ("Wind Avg 10m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
|
||||
TYPE_WINDSPDMPH_AVG2M: ("Wind Avg 2m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
|
||||
TYPE_WINDSPEEDMPH: ("Wind Speed", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
|
||||
TYPE_YEARLYRAININ: ("Yearly Rain", "in", TYPE_SENSOR, None),
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import voluptuous as vol
|
|||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
|
@ -30,7 +31,7 @@ SENSOR_TYPES = {
|
|||
"signal_strength": ["Signal Strength", None, "signal"],
|
||||
"temperature": ["Temperature", TEMP_CELSIUS, "thermometer"],
|
||||
"humidity": ["Humidity", "%", "water-percent"],
|
||||
"air_quality": ["Air Quality", "ppm", "biohazard"],
|
||||
"air_quality": ["Air Quality", CONCENTRATION_PARTS_PER_MILLION, "biohazard"],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -8,6 +8,9 @@ from python_awair import AwairClient
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_DEVICES,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
|
@ -50,29 +53,29 @@ SENSOR_TYPES = {
|
|||
},
|
||||
"CO2": {
|
||||
"device_class": DEVICE_CLASS_CARBON_DIOXIDE,
|
||||
"unit_of_measurement": "ppm",
|
||||
"unit_of_measurement": CONCENTRATION_PARTS_PER_MILLION,
|
||||
"icon": "mdi:periodic-table-co2",
|
||||
},
|
||||
"VOC": {
|
||||
"device_class": DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
|
||||
"unit_of_measurement": "ppb",
|
||||
"unit_of_measurement": CONCENTRATION_PARTS_PER_BILLION,
|
||||
"icon": "mdi:cloud",
|
||||
},
|
||||
# Awair docs don't actually specify the size they measure for 'dust',
|
||||
# but 2.5 allows the sensor to show up in HomeKit
|
||||
"DUST": {
|
||||
"device_class": DEVICE_CLASS_PM2_5,
|
||||
"unit_of_measurement": "µg/m3",
|
||||
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
"icon": "mdi:cloud",
|
||||
},
|
||||
"PM25": {
|
||||
"device_class": DEVICE_CLASS_PM2_5,
|
||||
"unit_of_measurement": "µg/m3",
|
||||
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
"icon": "mdi:cloud",
|
||||
},
|
||||
"PM10": {
|
||||
"device_class": DEVICE_CLASS_PM10,
|
||||
"unit_of_measurement": "µg/m3",
|
||||
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
"icon": "mdi:cloud",
|
||||
},
|
||||
"score": {
|
||||
|
|
|
@ -19,8 +19,8 @@ from homeassistant.const import (
|
|||
CONF_LONGITUDE,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TIME_HOURS,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -59,7 +59,7 @@ SENSOR_TYPES = {
|
|||
"cloud_type_id": ["Cloud Type ID", None],
|
||||
"cloud_type": ["Cloud Type", None],
|
||||
"delta_t": ["Delta Temp C", TEMP_CELSIUS],
|
||||
"gust_kmh": ["Wind Gust kmh", f"km/{TIME_HOURS}"],
|
||||
"gust_kmh": ["Wind Gust kmh", SPEED_KILOMETERS_PER_HOUR],
|
||||
"gust_kt": ["Wind Gust kt", "kt"],
|
||||
"air_temp": ["Air Temp C", TEMP_CELSIUS],
|
||||
"dewpt": ["Dew Point C", TEMP_CELSIUS],
|
||||
|
@ -76,7 +76,7 @@ SENSOR_TYPES = {
|
|||
"vis_km": ["Visability km", "km"],
|
||||
"weather": ["Weather", None],
|
||||
"wind_dir": ["Wind Direction", None],
|
||||
"wind_spd_kmh": ["Wind Speed kmh", f"km/{TIME_HOURS}"],
|
||||
"wind_spd_kmh": ["Wind Speed kmh", SPEED_KILOMETERS_PER_HOUR],
|
||||
"wind_spd_kt": ["Wind Speed kt", "kt"],
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ from homeassistant.const import (
|
|||
CONF_LONGITUDE,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TIME_HOURS,
|
||||
)
|
||||
|
@ -68,15 +70,15 @@ SENSOR_TYPES = {
|
|||
"humidity": ["Humidity", "%", "mdi:water-percent"],
|
||||
"temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"],
|
||||
"groundtemperature": ["Ground temperature", TEMP_CELSIUS, "mdi:thermometer"],
|
||||
"windspeed": ["Wind speed", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windspeed": ["Wind speed", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"windforce": ["Wind force", "Bft", "mdi:weather-windy"],
|
||||
"winddirection": ["Wind direction", None, "mdi:compass-outline"],
|
||||
"windazimuth": ["Wind direction azimuth", "°", "mdi:compass-outline"],
|
||||
"pressure": ["Pressure", "hPa", "mdi:gauge"],
|
||||
"visibility": ["Visibility", "km", None],
|
||||
"windgust": ["Wind gust", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windgust": ["Wind gust", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"precipitation": ["Precipitation", f"mm/{TIME_HOURS}", "mdi:weather-pouring"],
|
||||
"irradiance": ["Irradiance", "W/m2", "mdi:sunglasses"],
|
||||
"irradiance": ["Irradiance", IRRADIATION_WATTS_PER_SQUARE_METER, "mdi:sunglasses"],
|
||||
"precipitation_forecast_average": [
|
||||
"Precipitation forecast average",
|
||||
f"mm/{TIME_HOURS}",
|
||||
|
@ -133,11 +135,11 @@ SENSOR_TYPES = {
|
|||
"windforce_3d": ["Wind force 3d", "Bft", "mdi:weather-windy"],
|
||||
"windforce_4d": ["Wind force 4d", "Bft", "mdi:weather-windy"],
|
||||
"windforce_5d": ["Wind force 5d", "Bft", "mdi:weather-windy"],
|
||||
"windspeed_1d": ["Wind speed 1d", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windspeed_2d": ["Wind speed 2d", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windspeed_3d": ["Wind speed 3d", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windspeed_4d": ["Wind speed 4d", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windspeed_5d": ["Wind speed 5d", f"km/{TIME_HOURS}", "mdi:weather-windy"],
|
||||
"windspeed_1d": ["Wind speed 1d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"windspeed_2d": ["Wind speed 2d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"windspeed_3d": ["Wind speed 3d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"windspeed_4d": ["Wind speed 4d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"windspeed_5d": ["Wind speed 5d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
|
||||
"winddirection_1d": ["Wind direction 1d", None, "mdi:compass-outline"],
|
||||
"winddirection_2d": ["Wind direction 2d", None, "mdi:compass-outline"],
|
||||
"winddirection_3d": ["Wind direction 3d", None, "mdi:compass-outline"],
|
||||
|
|
|
@ -15,8 +15,10 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TIME_HOURS,
|
||||
TIME_SECONDS,
|
||||
UNIT_UV_INDEX,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -161,11 +163,11 @@ SENSOR_TYPES = {
|
|||
],
|
||||
"wind_speed": [
|
||||
"Wind Speed",
|
||||
f"m/{TIME_SECONDS}",
|
||||
"mph",
|
||||
f"km/{TIME_HOURS}",
|
||||
"mph",
|
||||
"mph",
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
["currently", "hourly", "daily"],
|
||||
],
|
||||
|
@ -181,11 +183,11 @@ SENSOR_TYPES = {
|
|||
],
|
||||
"wind_gust": [
|
||||
"Wind Gust",
|
||||
f"m/{TIME_SECONDS}",
|
||||
"mph",
|
||||
f"km/{TIME_HOURS}",
|
||||
"mph",
|
||||
"mph",
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy-variant",
|
||||
["currently", "hourly", "daily"],
|
||||
],
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Definitions for DSMR Reader sensors added to MQTT."""
|
||||
|
||||
from homeassistant.const import VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
def dsmr_transform(value):
|
||||
"""Transform DSMR version value to right format."""
|
||||
|
@ -79,7 +81,7 @@ DEFINITIONS = {
|
|||
"dsmr/reading/extra_device_delivered": {
|
||||
"name": "Gas meter usage",
|
||||
"icon": "mdi:fire",
|
||||
"unit": "m3",
|
||||
"unit": VOLUME_CUBIC_METERS,
|
||||
},
|
||||
"dsmr/reading/phase_voltage_l1": {
|
||||
"name": "Current voltage L1",
|
||||
|
@ -99,12 +101,12 @@ DEFINITIONS = {
|
|||
"dsmr/consumption/gas/delivered": {
|
||||
"name": "Gas usage",
|
||||
"icon": "mdi:fire",
|
||||
"unit": "m3",
|
||||
"unit": VOLUME_CUBIC_METERS,
|
||||
},
|
||||
"dsmr/consumption/gas/currently_delivered": {
|
||||
"name": "Current gas usage",
|
||||
"icon": "mdi:fire",
|
||||
"unit": "m3",
|
||||
"unit": VOLUME_CUBIC_METERS,
|
||||
},
|
||||
"dsmr/consumption/gas/read_at": {
|
||||
"name": "Gas meter read",
|
||||
|
@ -159,7 +161,7 @@ DEFINITIONS = {
|
|||
"dsmr/day-consumption/gas": {
|
||||
"name": "Gas usage",
|
||||
"icon": "mdi:counter",
|
||||
"unit": "m3",
|
||||
"unit": VOLUME_CUBIC_METERS,
|
||||
},
|
||||
"dsmr/day-consumption/gas_cost": {
|
||||
"name": "Gas cost",
|
||||
|
|
|
@ -3,6 +3,7 @@ import logging
|
|||
|
||||
from homeassistant.components.sensor import ENTITY_ID_FORMAT
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
|
@ -20,8 +21,13 @@ SENSOR_TYPES = {
|
|||
None,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
],
|
||||
"com.fibaro.smokeSensor": ["Smoke", "ppm", "mdi:fire", None],
|
||||
"CO2": ["CO2", "ppm", "mdi:cloud", None],
|
||||
"com.fibaro.smokeSensor": [
|
||||
"Smoke",
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
"mdi:fire",
|
||||
None,
|
||||
],
|
||||
"CO2": ["CO2", CONCENTRATION_PARTS_PER_MILLION, "mdi:cloud", None],
|
||||
"com.fibaro.humiditySensor": ["Humidity", "%", None, DEVICE_CLASS_HUMIDITY],
|
||||
"com.fibaro.lightSensor": ["Light", "lx", None, DEVICE_CLASS_ILLUMINANCE],
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA
|
|||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_UNIT_SYSTEM,
|
||||
MASS_KILOGRAMS,
|
||||
MASS_MILLIGRAMS,
|
||||
TIME_MILLISECONDS,
|
||||
TIME_MINUTES,
|
||||
)
|
||||
|
@ -115,7 +117,7 @@ FITBIT_MEASUREMENTS = {
|
|||
"weight": "lbs",
|
||||
"body": "in",
|
||||
"liquids": "fl. oz.",
|
||||
"blood glucose": "mg/dL",
|
||||
"blood glucose": f"{MASS_MILLIGRAMS}/dL",
|
||||
"battery": "",
|
||||
},
|
||||
"en_GB": {
|
||||
|
@ -134,7 +136,7 @@ FITBIT_MEASUREMENTS = {
|
|||
"distance": "kilometers",
|
||||
"elevation": "meters",
|
||||
"height": "centimeters",
|
||||
"weight": "kilograms",
|
||||
"weight": MASS_KILOGRAMS,
|
||||
"body": "centimeters",
|
||||
"liquids": "milliliters",
|
||||
"blood glucose": "mmol/L",
|
||||
|
|
|
@ -10,6 +10,9 @@ import voluptuous as vol
|
|||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
ATTR_TIME,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_TOKEN,
|
||||
CONF_USERNAME,
|
||||
TEMP_CELSIUS,
|
||||
|
@ -32,11 +35,19 @@ ATTR_FOOBOT_INDEX = "index"
|
|||
|
||||
SENSOR_TYPES = {
|
||||
"time": [ATTR_TIME, TIME_SECONDS],
|
||||
"pm": [ATTR_PM2_5, "µg/m3", "mdi:cloud"],
|
||||
"pm": [ATTR_PM2_5, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, "mdi:cloud"],
|
||||
"tmp": [ATTR_TEMPERATURE, TEMP_CELSIUS, "mdi:thermometer"],
|
||||
"hum": [ATTR_HUMIDITY, "%", "mdi:water-percent"],
|
||||
"co2": [ATTR_CARBON_DIOXIDE, "ppm", "mdi:periodic-table-co2"],
|
||||
"voc": [ATTR_VOLATILE_ORGANIC_COMPOUNDS, "ppb", "mdi:cloud"],
|
||||
"co2": [
|
||||
ATTR_CARBON_DIOXIDE,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
"mdi:periodic-table-co2",
|
||||
],
|
||||
"voc": [
|
||||
ATTR_VOLATILE_ORGANIC_COMPOUNDS,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
"mdi:cloud",
|
||||
],
|
||||
"allpollu": [ATTR_FOOBOT_INDEX, "%", "mdi:percent"],
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
"""Support for Homekit sensors."""
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
|
||||
from homeassistant.const import DEVICE_CLASS_BATTERY, TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
||||
from . import KNOWN_DEVICES, HomeKitEntity
|
||||
|
@ -13,7 +17,6 @@ CO2_ICON = "mdi:periodic-table-co2"
|
|||
|
||||
UNIT_PERCENT = "%"
|
||||
UNIT_LUX = "lux"
|
||||
UNIT_CO2 = "ppm"
|
||||
|
||||
|
||||
class HomeKitHumiditySensor(HomeKitEntity):
|
||||
|
@ -149,7 +152,7 @@ class HomeKitCarbonDioxideSensor(HomeKitEntity):
|
|||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return units for the sensor."""
|
||||
return UNIT_CO2
|
||||
return CONCENTRATION_PARTS_PER_MILLION
|
||||
|
||||
def _update_carbon_dioxide_level(self, value):
|
||||
self._state = value
|
||||
|
|
|
@ -8,7 +8,8 @@ from homeassistant.const import (
|
|||
DEVICE_CLASS_TEMPERATURE,
|
||||
ENERGY_WATT_HOUR,
|
||||
POWER_WATT,
|
||||
TIME_HOURS,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
VOLUME_CUBIC_METERS,
|
||||
)
|
||||
|
||||
from .const import ATTR_DISCOVER_DEVICES
|
||||
|
@ -39,8 +40,8 @@ HM_UNIT_HA_CAST = {
|
|||
"CURRENT": "mA",
|
||||
"VOLTAGE": "V",
|
||||
"ENERGY_COUNTER": ENERGY_WATT_HOUR,
|
||||
"GAS_POWER": "m3",
|
||||
"GAS_ENERGY_COUNTER": "m3",
|
||||
"GAS_POWER": VOLUME_CUBIC_METERS,
|
||||
"GAS_ENERGY_COUNTER": VOLUME_CUBIC_METERS,
|
||||
"LUX": "lx",
|
||||
"ILLUMINATION": "lx",
|
||||
"CURRENT_ILLUMINATION": "lx",
|
||||
|
@ -48,7 +49,7 @@ HM_UNIT_HA_CAST = {
|
|||
"LOWEST_ILLUMINATION": "lx",
|
||||
"HIGHEST_ILLUMINATION": "lx",
|
||||
"RAIN_COUNTER": "mm",
|
||||
"WIND_SPEED": f"km/{TIME_HOURS}",
|
||||
"WIND_SPEED": SPEED_KILOMETERS_PER_HOUR,
|
||||
"WIND_DIRECTION": "°",
|
||||
"WIND_DIRECTION_RANGE": "°",
|
||||
"SUNSHINEDURATION": "#",
|
||||
|
|
|
@ -31,8 +31,8 @@ from homeassistant.const import (
|
|||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
POWER_WATT,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TIME_HOURS,
|
||||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
|
@ -333,7 +333,7 @@ class HomematicipWindspeedSensor(HomematicipGenericDevice):
|
|||
@property
|
||||
def unit_of_measurement(self) -> str:
|
||||
"""Return the unit this state is expressed in."""
|
||||
return f"km/{TIME_HOURS}"
|
||||
return SPEED_KILOMETERS_PER_HOUR
|
||||
|
||||
@property
|
||||
def device_state_attributes(self) -> Dict[str, Any]:
|
||||
|
|
|
@ -4,7 +4,11 @@ from typing import Callable
|
|||
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
POWER_WATT,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
TIME_DAYS,
|
||||
|
@ -51,7 +55,7 @@ UOM_FRIENDLY_NAME = {
|
|||
"29": "kV",
|
||||
"30": "kW",
|
||||
"31": "kPa",
|
||||
"32": "KPH",
|
||||
"32": SPEED_KILOMETERS_PER_HOUR,
|
||||
"33": "kWH",
|
||||
"34": "liedu",
|
||||
"35": "l",
|
||||
|
@ -59,7 +63,7 @@ UOM_FRIENDLY_NAME = {
|
|||
"37": "mercalli",
|
||||
"38": "m",
|
||||
"39": "m³/hr",
|
||||
"40": f"m/{TIME_SECONDS}",
|
||||
"40": SPEED_METERS_PER_SECOND,
|
||||
"41": "mA",
|
||||
"42": TIME_MILLISECONDS,
|
||||
"43": "mV",
|
||||
|
@ -67,13 +71,13 @@ UOM_FRIENDLY_NAME = {
|
|||
"45": TIME_MINUTES,
|
||||
"46": "mm/hr",
|
||||
"47": TIME_MONTHS,
|
||||
"48": "MPH",
|
||||
"49": f"m/{TIME_SECONDS}",
|
||||
"48": SPEED_MILES_PER_HOUR,
|
||||
"49": SPEED_METERS_PER_SECOND,
|
||||
"50": "ohm",
|
||||
"51": "%",
|
||||
"52": "lb",
|
||||
"53": "power factor",
|
||||
"54": "ppm",
|
||||
"54": CONCENTRATION_PARTS_PER_MILLION,
|
||||
"55": "pulse count",
|
||||
"57": TIME_SECONDS,
|
||||
"58": TIME_SECONDS,
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
)
|
||||
|
||||
DOMAIN = "kaiterra"
|
||||
|
||||
DISPATCHER_KAITERRA = "kaiterra_update"
|
||||
|
@ -44,7 +51,16 @@ ATTR_AQI_LEVEL = "air_quality_index_level"
|
|||
ATTR_AQI_POLLUTANT = "air_quality_index_pollutant"
|
||||
|
||||
AVAILABLE_AQI_STANDARDS = ["us", "cn", "in"]
|
||||
AVAILABLE_UNITS = ["x", "%", "C", "F", "mg/m³", "µg/m³", "ppm", "ppb"]
|
||||
AVAILABLE_UNITS = [
|
||||
"x",
|
||||
"%",
|
||||
"C",
|
||||
"F",
|
||||
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
]
|
||||
AVAILABLE_DEVICE_TYPES = ["laseregg", "sensedge"]
|
||||
|
||||
CONF_AQI_STANDARD = "aqi_standard"
|
||||
|
|
|
@ -7,6 +7,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_SENSORS,
|
||||
|
@ -39,18 +40,20 @@ SENSOR_TEMPERATURE = "temperature"
|
|||
|
||||
TOPIC_UPDATE = f"{DOMAIN}_data_update"
|
||||
|
||||
VOLUME_MICROGRAMS_PER_CUBIC_METER = "µg/m3"
|
||||
|
||||
SENSORS = {
|
||||
SENSOR_TEMPERATURE: ["Temperature", "mdi:thermometer", TEMP_CELSIUS],
|
||||
SENSOR_HUMIDITY: ["Humidity", "mdi:water-percent", "%"],
|
||||
SENSOR_PRESSURE: ["Pressure", "mdi:arrow-down-bold", "Pa"],
|
||||
SENSOR_PRESSURE_AT_SEALEVEL: ["Pressure at sealevel", "mdi:download", "Pa"],
|
||||
SENSOR_PM10: ["PM10", "mdi:thought-bubble", VOLUME_MICROGRAMS_PER_CUBIC_METER],
|
||||
SENSOR_PM10: [
|
||||
"PM10",
|
||||
"mdi:thought-bubble",
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
],
|
||||
SENSOR_PM2_5: [
|
||||
"PM2.5",
|
||||
"mdi:thought-bubble-outline",
|
||||
VOLUME_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
],
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Meteo-France component constants."""
|
||||
|
||||
from homeassistant.const import TEMP_CELSIUS, TIME_HOURS, TIME_MINUTES
|
||||
from homeassistant.const import SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, TIME_MINUTES
|
||||
|
||||
DOMAIN = "meteo_france"
|
||||
PLATFORMS = ["sensor", "weather"]
|
||||
|
@ -47,7 +47,7 @@ SENSOR_TYPES = {
|
|||
},
|
||||
"wind_speed": {
|
||||
SENSOR_TYPE_NAME: "Wind Speed",
|
||||
SENSOR_TYPE_UNIT: f"km/{TIME_HOURS}",
|
||||
SENSOR_TYPE_UNIT: SPEED_KILOMETERS_PER_HOUR,
|
||||
SENSOR_TYPE_ICON: "mdi:weather-windy",
|
||||
SENSOR_TYPE_CLASS: None,
|
||||
},
|
||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.const import (
|
|||
CONF_LONGITUDE,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -64,9 +65,9 @@ SENSOR_TYPES = {
|
|||
"weather": ["Weather", None],
|
||||
"temperature": ["Temperature", TEMP_CELSIUS],
|
||||
"feels_like_temperature": ["Feels Like Temperature", TEMP_CELSIUS],
|
||||
"wind_speed": ["Wind Speed", "mph"],
|
||||
"wind_speed": ["Wind Speed", SPEED_MILES_PER_HOUR],
|
||||
"wind_direction": ["Wind Direction", None],
|
||||
"wind_gust": ["Wind Gust", "mph"],
|
||||
"wind_gust": ["Wind Gust", SPEED_MILES_PER_HOUR],
|
||||
"visibility": ["Visibility", None],
|
||||
"visibility_distance": ["Visibility Distance", "km"],
|
||||
"uv": ["UV", None],
|
||||
|
|
|
@ -8,6 +8,7 @@ import voluptuous as vol
|
|||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
TEMP_FAHRENHEIT,
|
||||
|
@ -28,7 +29,10 @@ ATTR_CO2_CONCENTRATION = "co2_concentration"
|
|||
|
||||
SENSOR_TEMPERATURE = "temperature"
|
||||
SENSOR_CO2 = "co2"
|
||||
SENSOR_TYPES = {SENSOR_TEMPERATURE: ["Temperature", None], SENSOR_CO2: ["CO2", "ppm"]}
|
||||
SENSOR_TYPES = {
|
||||
SENSOR_TEMPERATURE: ["Temperature", None],
|
||||
SENSOR_CO2: ["CO2", CONCENTRATION_PARTS_PER_MILLION],
|
||||
}
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
|
|
|
@ -3,6 +3,7 @@ from homeassistant.components import mysensors
|
|||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
MASS_KILOGRAMS,
|
||||
POWER_WATT,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
|
@ -20,7 +21,7 @@ SENSORS = {
|
|||
"V_WIND": [None, "mdi:weather-windy"],
|
||||
"V_GUST": [None, "mdi:weather-windy"],
|
||||
"V_DIRECTION": ["°", "mdi:compass"],
|
||||
"V_WEIGHT": ["kg", "mdi:weight-kilogram"],
|
||||
"V_WEIGHT": [MASS_KILOGRAMS, "mdi:weight-kilogram"],
|
||||
"V_DISTANCE": ["m", "mdi:ruler"],
|
||||
"V_IMPEDANCE": ["ohm", None],
|
||||
"V_WATT": [POWER_WATT, None],
|
||||
|
|
|
@ -5,11 +5,12 @@ import logging
|
|||
import pyatmo
|
||||
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TIME_HOURS,
|
||||
)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -53,7 +54,7 @@ SENSOR_TYPES = {
|
|||
"mdi:thermometer",
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
],
|
||||
"co2": ["CO2", "ppm", "mdi:periodic-table-co2", None],
|
||||
"co2": ["CO2", CONCENTRATION_PARTS_PER_MILLION, "mdi:periodic-table-co2", None],
|
||||
"pressure": ["Pressure", "mbar", "mdi:gauge", None],
|
||||
"noise": ["Noise", "dB", "mdi:volume-high", None],
|
||||
"humidity": ["Humidity", "%", "mdi:water-percent", DEVICE_CLASS_HUMIDITY],
|
||||
|
@ -67,10 +68,20 @@ SENSOR_TYPES = {
|
|||
"max_temp": ["Max Temp.", TEMP_CELSIUS, "mdi:thermometer", None],
|
||||
"windangle": ["Angle", "", "mdi:compass", None],
|
||||
"windangle_value": ["Angle Value", "º", "mdi:compass", None],
|
||||
"windstrength": ["Wind Strength", f"km/{TIME_HOURS}", "mdi:weather-windy", None],
|
||||
"windstrength": [
|
||||
"Wind Strength",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
None,
|
||||
],
|
||||
"gustangle": ["Gust Angle", "", "mdi:compass", None],
|
||||
"gustangle_value": ["Gust Angle Value", "º", "mdi:compass", None],
|
||||
"guststrength": ["Gust Strength", f"km/{TIME_HOURS}", "mdi:weather-windy", None],
|
||||
"guststrength": [
|
||||
"Gust Strength",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
None,
|
||||
],
|
||||
"reachable": ["Reachability", "", "mdi:signal", None],
|
||||
"rf_status": ["Radio", "", "mdi:signal", None],
|
||||
"rf_status_lvl": ["Radio_lvl", "", "mdi:signal", None],
|
||||
|
|
|
@ -12,9 +12,9 @@ from homeassistant.const import (
|
|||
CONF_API_KEY,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
TIME_SECONDS,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -34,7 +34,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
|||
SENSOR_TYPES = {
|
||||
"weather": ["Condition", None],
|
||||
"temperature": ["Temperature", None],
|
||||
"wind_speed": ["Wind speed", f"m/{TIME_SECONDS}"],
|
||||
"wind_speed": ["Wind speed", SPEED_METERS_PER_SECOND],
|
||||
"wind_bearing": ["Wind bearing", "°"],
|
||||
"humidity": ["Humidity", "%"],
|
||||
"pressure": ["Pressure", "mbar"],
|
||||
|
|
|
@ -5,7 +5,7 @@ from pmsensor import serial_pm as pm
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.const import CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
@ -79,7 +79,7 @@ class ParticulateMatterSensor(Entity):
|
|||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return "µg/m³"
|
||||
return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
|
||||
def update(self):
|
||||
"""Read from sensor and update the state."""
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT, VOLUME_CUBIC_METERS
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import DATA_SMAPPEE
|
||||
|
@ -43,8 +43,20 @@ SENSOR_TYPES = {
|
|||
ENERGY_KILO_WATT_HOUR,
|
||||
"consumption",
|
||||
],
|
||||
"water_sensor_1": ["Water Sensor 1", "mdi:water", "water", "m3", "value1"],
|
||||
"water_sensor_2": ["Water Sensor 2", "mdi:water", "water", "m3", "value2"],
|
||||
"water_sensor_1": [
|
||||
"Water Sensor 1",
|
||||
"mdi:water",
|
||||
"water",
|
||||
VOLUME_CUBIC_METERS,
|
||||
"value1",
|
||||
],
|
||||
"water_sensor_2": [
|
||||
"Water Sensor 2",
|
||||
"mdi:water",
|
||||
"water",
|
||||
VOLUME_CUBIC_METERS,
|
||||
"value2",
|
||||
],
|
||||
"water_sensor_temperature": [
|
||||
"Water Sensor Temperature",
|
||||
"mdi:temperature-celsius",
|
||||
|
|
|
@ -5,6 +5,7 @@ from typing import Optional, Sequence
|
|||
from pysmartthings import Attribute, Capability
|
||||
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
|
@ -42,13 +43,23 @@ CAPABILITY_TO_SENSORS = {
|
|||
Map(Attribute.body_weight_measurement, "Body Weight", MASS_KILOGRAMS, None)
|
||||
],
|
||||
Capability.carbon_dioxide_measurement: [
|
||||
Map(Attribute.carbon_dioxide, "Carbon Dioxide Measurement", "ppm", None)
|
||||
Map(
|
||||
Attribute.carbon_dioxide,
|
||||
"Carbon Dioxide Measurement",
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
None,
|
||||
)
|
||||
],
|
||||
Capability.carbon_monoxide_detector: [
|
||||
Map(Attribute.carbon_monoxide, "Carbon Monoxide Detector", None, None)
|
||||
],
|
||||
Capability.carbon_monoxide_measurement: [
|
||||
Map(Attribute.carbon_monoxide_level, "Carbon Monoxide Measurement", "ppm", None)
|
||||
Map(
|
||||
Attribute.carbon_monoxide_level,
|
||||
"Carbon Monoxide Measurement",
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
None,
|
||||
)
|
||||
],
|
||||
Capability.dishwasher_operating_state: [
|
||||
Map(Attribute.machine_state, "Dishwasher Machine State", None, None),
|
||||
|
@ -82,12 +93,17 @@ CAPABILITY_TO_SENSORS = {
|
|||
Map(
|
||||
Attribute.equivalent_carbon_dioxide_measurement,
|
||||
"Equivalent Carbon Dioxide Measurement",
|
||||
"ppm",
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
None,
|
||||
)
|
||||
],
|
||||
Capability.formaldehyde_measurement: [
|
||||
Map(Attribute.formaldehyde_level, "Formaldehyde Measurement", "ppm", None)
|
||||
Map(
|
||||
Attribute.formaldehyde_level,
|
||||
"Formaldehyde Measurement",
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
None,
|
||||
)
|
||||
],
|
||||
Capability.illuminance_measurement: [
|
||||
Map(Attribute.illuminance, "Illuminance", "lux", DEVICE_CLASS_ILLUMINANCE)
|
||||
|
@ -203,7 +219,12 @@ CAPABILITY_TO_SENSORS = {
|
|||
Capability.three_axis: [],
|
||||
Capability.tv_channel: [Map(Attribute.tv_channel, "Tv Channel", None, None)],
|
||||
Capability.tvoc_measurement: [
|
||||
Map(Attribute.tvoc_level, "Tvoc Measurement", "ppm", None)
|
||||
Map(
|
||||
Attribute.tvoc_level,
|
||||
"Tvoc Measurement",
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
None,
|
||||
)
|
||||
],
|
||||
Capability.ultraviolet_index: [
|
||||
Map(Attribute.ultraviolet_index, "Ultraviolet Index", None, None)
|
||||
|
|
|
@ -7,9 +7,9 @@ from homeassistant.const import (
|
|||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
POWER_WATT,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
TEMP_CELSIUS,
|
||||
TIME_HOURS,
|
||||
TIME_SECONDS,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
|
@ -41,8 +41,8 @@ SENSOR_TYPES = {
|
|||
SENSOR_TYPE_RAINRATE: ["Rain rate", f"mm/{TIME_HOURS}", "mdi:water", None],
|
||||
SENSOR_TYPE_RAINTOTAL: ["Rain total", "mm", "mdi:water", None],
|
||||
SENSOR_TYPE_WINDDIRECTION: ["Wind direction", "", "", None],
|
||||
SENSOR_TYPE_WINDAVERAGE: ["Wind average", f"m/{TIME_SECONDS}", "", None],
|
||||
SENSOR_TYPE_WINDGUST: ["Wind gust", f"m/{TIME_SECONDS}", "", None],
|
||||
SENSOR_TYPE_WINDAVERAGE: ["Wind average", SPEED_METERS_PER_SECOND, "", None],
|
||||
SENSOR_TYPE_WINDGUST: ["Wind gust", SPEED_METERS_PER_SECOND, "", None],
|
||||
SENSOR_TYPE_UV: ["UV", "UV", "", None],
|
||||
SENSOR_TYPE_WATT: ["Power", POWER_WATT, "", None],
|
||||
SENSOR_TYPE_LUMINANCE: ["Luminance", "lx", None, DEVICE_CLASS_ILLUMINANCE],
|
||||
|
|
|
@ -16,8 +16,8 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
TEMP_CELSIUS,
|
||||
TIME_SECONDS,
|
||||
)
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -74,7 +74,7 @@ SENSOR_TYPES = {
|
|||
],
|
||||
"wind_speed": [
|
||||
"Wind speed",
|
||||
f"m/{TIME_SECONDS}",
|
||||
SPEED_METERS_PER_SECOND,
|
||||
"windforce",
|
||||
"mdi:weather-windy",
|
||||
None,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Support for UPnP/IGD Sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import TIME_SECONDS
|
||||
from homeassistant.const import DATA_BYTES, DATA_KIBIBYTES, TIME_SECONDS
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -19,15 +19,15 @@ PACKETS_RECEIVED = "packets_received"
|
|||
PACKETS_SENT = "packets_sent"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
BYTES_RECEIVED: {"name": "bytes received", "unit": "bytes"},
|
||||
BYTES_SENT: {"name": "bytes sent", "unit": "bytes"},
|
||||
BYTES_RECEIVED: {"name": "bytes received", "unit": DATA_BYTES},
|
||||
BYTES_SENT: {"name": "bytes sent", "unit": DATA_BYTES},
|
||||
PACKETS_RECEIVED: {"name": "packets received", "unit": "packets"},
|
||||
PACKETS_SENT: {"name": "packets sent", "unit": "packets"},
|
||||
}
|
||||
|
||||
IN = "received"
|
||||
OUT = "sent"
|
||||
KBYTE = 1024
|
||||
KIBIBYTE = 1024
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
|
@ -226,7 +226,7 @@ class KBytePerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
|||
@property
|
||||
def unit(self) -> str:
|
||||
"""Get unit we are measuring in."""
|
||||
return "kB"
|
||||
return DATA_KIBIBYTES
|
||||
|
||||
async def _async_fetch_value(self) -> float:
|
||||
"""Fetch value from device."""
|
||||
|
@ -241,7 +241,7 @@ class KBytePerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
|||
if self._state is None:
|
||||
return None
|
||||
|
||||
return format(float(self._state / KBYTE), ".1f")
|
||||
return format(float(self._state / KIBIBYTE), ".1f")
|
||||
|
||||
|
||||
class PacketsPerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
||||
|
|
|
@ -59,11 +59,9 @@ MEAS_TEMP_C = "temperature_c"
|
|||
MEAS_WEIGHT_KG = "weight_kg"
|
||||
|
||||
UOM_BEATS_PER_MINUTE = "bpm"
|
||||
UOM_BREATHS_PER_MINUTE = "br/m"
|
||||
UOM_BREATHS_PER_MINUTE = f"br/{const.TIME_MINUTES}"
|
||||
UOM_FREQUENCY = "times"
|
||||
UOM_METERS_PER_SECOND = f"m/{const.TIME_SECONDS}"
|
||||
UOM_MMHG = "mmhg"
|
||||
UOM_PERCENT = "%"
|
||||
UOM_LENGTH_M = const.LENGTH_METERS
|
||||
UOM_MASS_KG = const.MASS_KILOGRAMS
|
||||
UOM_TEMP_C = const.TEMP_CELSIUS
|
||||
|
|
|
@ -13,7 +13,7 @@ from withings_api.common import (
|
|||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TIME_SECONDS
|
||||
from homeassistant.const import MASS_KILOGRAMS, SPEED_METERS_PER_SECOND, TIME_SECONDS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -87,35 +87,35 @@ WITHINGS_ATTRIBUTES = [
|
|||
const.MEAS_WEIGHT_KG,
|
||||
MeasureType.WEIGHT,
|
||||
"Weight",
|
||||
const.UOM_MASS_KG,
|
||||
MASS_KILOGRAMS,
|
||||
"mdi:weight-kilogram",
|
||||
),
|
||||
WithingsMeasureAttribute(
|
||||
const.MEAS_FAT_MASS_KG,
|
||||
MeasureType.FAT_MASS_WEIGHT,
|
||||
"Fat Mass",
|
||||
const.UOM_MASS_KG,
|
||||
MASS_KILOGRAMS,
|
||||
"mdi:weight-kilogram",
|
||||
),
|
||||
WithingsMeasureAttribute(
|
||||
const.MEAS_FAT_FREE_MASS_KG,
|
||||
MeasureType.FAT_FREE_MASS,
|
||||
"Fat Free Mass",
|
||||
const.UOM_MASS_KG,
|
||||
MASS_KILOGRAMS,
|
||||
"mdi:weight-kilogram",
|
||||
),
|
||||
WithingsMeasureAttribute(
|
||||
const.MEAS_MUSCLE_MASS_KG,
|
||||
MeasureType.MUSCLE_MASS,
|
||||
"Muscle Mass",
|
||||
const.UOM_MASS_KG,
|
||||
MASS_KILOGRAMS,
|
||||
"mdi:weight-kilogram",
|
||||
),
|
||||
WithingsMeasureAttribute(
|
||||
const.MEAS_BONE_MASS_KG,
|
||||
MeasureType.BONE_MASS,
|
||||
"Bone Mass",
|
||||
const.UOM_MASS_KG,
|
||||
MASS_KILOGRAMS,
|
||||
"mdi:weight-kilogram",
|
||||
),
|
||||
WithingsMeasureAttribute(
|
||||
|
@ -188,7 +188,7 @@ WITHINGS_ATTRIBUTES = [
|
|||
const.MEAS_PWV,
|
||||
MeasureType.PULSE_WAVE_VELOCITY,
|
||||
"Pulse Wave Velocity",
|
||||
const.UOM_METERS_PER_SECOND,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
None,
|
||||
),
|
||||
WithingsSleepStateAttribute(
|
||||
|
|
|
@ -17,10 +17,13 @@ from homeassistant.const import (
|
|||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
LENGTH_FEET,
|
||||
LENGTH_INCHES,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
|
@ -421,7 +424,10 @@ SENSOR_TYPES = {
|
|||
"Station ID", "station_id", "mdi:home"
|
||||
),
|
||||
"solarradiation": WUCurrentConditionsSensorConfig(
|
||||
"Solar Radiation", "solarradiation", "mdi:weather-sunny", "w/m2"
|
||||
"Solar Radiation",
|
||||
"solarradiation",
|
||||
"mdi:weather-sunny",
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
),
|
||||
"temperature_string": WUCurrentConditionsSensorConfig(
|
||||
"Temperature Summary", "temperature_string", "mdi:thermometer"
|
||||
|
@ -455,16 +461,16 @@ SENSOR_TYPES = {
|
|||
"Wind Direction", "wind_dir", "mdi:weather-windy"
|
||||
),
|
||||
"wind_gust_kph": WUCurrentConditionsSensorConfig(
|
||||
"Wind Gust", "wind_gust_kph", "mdi:weather-windy", "kph"
|
||||
"Wind Gust", "wind_gust_kph", "mdi:weather-windy", SPEED_KILOMETERS_PER_HOUR
|
||||
),
|
||||
"wind_gust_mph": WUCurrentConditionsSensorConfig(
|
||||
"Wind Gust", "wind_gust_mph", "mdi:weather-windy", "mph"
|
||||
"Wind Gust", "wind_gust_mph", "mdi:weather-windy", SPEED_MILES_PER_HOUR
|
||||
),
|
||||
"wind_kph": WUCurrentConditionsSensorConfig(
|
||||
"Wind Speed", "wind_kph", "mdi:weather-windy", "kph"
|
||||
"Wind Speed", "wind_kph", "mdi:weather-windy", SPEED_KILOMETERS_PER_HOUR
|
||||
),
|
||||
"wind_mph": WUCurrentConditionsSensorConfig(
|
||||
"Wind Speed", "wind_mph", "mdi:weather-windy", "mph"
|
||||
"Wind Speed", "wind_mph", "mdi:weather-windy", SPEED_MILES_PER_HOUR
|
||||
),
|
||||
"wind_string": WUCurrentConditionsSensorConfig(
|
||||
"Wind Summary", "wind_string", "mdi:weather-windy"
|
||||
|
@ -738,52 +744,132 @@ SENSOR_TYPES = {
|
|||
device_class="temperature",
|
||||
),
|
||||
"wind_gust_1d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind Today", 0, "maxwind", "kph", "kph", "mdi:weather-windy"
|
||||
"Max. Wind Today",
|
||||
0,
|
||||
"maxwind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_2d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind Tomorrow", 1, "maxwind", "kph", "kph", "mdi:weather-windy"
|
||||
"Max. Wind Tomorrow",
|
||||
1,
|
||||
"maxwind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_3d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind in 3 Days", 2, "maxwind", "kph", "kph", "mdi:weather-windy"
|
||||
"Max. Wind in 3 Days",
|
||||
2,
|
||||
"maxwind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_4d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind in 4 Days", 3, "maxwind", "kph", "kph", "mdi:weather-windy"
|
||||
"Max. Wind in 4 Days",
|
||||
3,
|
||||
"maxwind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_1d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind Today", 0, "maxwind", "mph", "mph", "mdi:weather-windy"
|
||||
"Max. Wind Today",
|
||||
0,
|
||||
"maxwind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_2d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind Tomorrow", 1, "maxwind", "mph", "mph", "mdi:weather-windy"
|
||||
"Max. Wind Tomorrow",
|
||||
1,
|
||||
"maxwind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_3d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind in 3 Days", 2, "maxwind", "mph", "mph", "mdi:weather-windy"
|
||||
"Max. Wind in 3 Days",
|
||||
2,
|
||||
"maxwind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_gust_4d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Max. Wind in 4 Days", 3, "maxwind", "mph", "mph", "mdi:weather-windy"
|
||||
"Max. Wind in 4 Days",
|
||||
3,
|
||||
"maxwind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_1d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind Today", 0, "avewind", "kph", "kph", "mdi:weather-windy"
|
||||
"Avg. Wind Today",
|
||||
0,
|
||||
"avewind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_2d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind Tomorrow", 1, "avewind", "kph", "kph", "mdi:weather-windy"
|
||||
"Avg. Wind Tomorrow",
|
||||
1,
|
||||
"avewind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_3d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind in 3 Days", 2, "avewind", "kph", "kph", "mdi:weather-windy"
|
||||
"Avg. Wind in 3 Days",
|
||||
2,
|
||||
"avewind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_4d_kph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind in 4 Days", 3, "avewind", "kph", "kph", "mdi:weather-windy"
|
||||
"Avg. Wind in 4 Days",
|
||||
3,
|
||||
"avewind",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_1d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind Today", 0, "avewind", "mph", "mph", "mdi:weather-windy"
|
||||
"Avg. Wind Today",
|
||||
0,
|
||||
"avewind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_2d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind Tomorrow", 1, "avewind", "mph", "mph", "mdi:weather-windy"
|
||||
"Avg. Wind Tomorrow",
|
||||
1,
|
||||
"avewind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_3d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind in 3 Days", 2, "avewind", "mph", "mph", "mdi:weather-windy"
|
||||
"Avg. Wind in 3 Days",
|
||||
2,
|
||||
"avewind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"wind_4d_mph": WUDailySimpleForecastSensorConfig(
|
||||
"Avg. Wind in 4 Days", 3, "avewind", "mph", "mph", "mdi:weather-windy"
|
||||
"Avg. Wind in 4 Days",
|
||||
3,
|
||||
"avewind",
|
||||
SPEED_MILES_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
"mdi:weather-windy",
|
||||
),
|
||||
"precip_1d_mm": WUDailySimpleForecastSensorConfig(
|
||||
"Precipitation Intensity Today", 0, "qpf_allday", "mm", "mm", "mdi:umbrella"
|
||||
|
|
|
@ -5,7 +5,12 @@ from miio import AirQualityMonitor, Device, DeviceException
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.air_quality import PLATFORM_SCHEMA, AirQualityEntity
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.exceptions import NoEntitySpecifiedError, PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
|
@ -88,7 +93,7 @@ class AirMonitorB1(AirQualityEntity):
|
|||
self._device = device
|
||||
self._unique_id = unique_id
|
||||
self._icon = "mdi:cloud"
|
||||
self._unit_of_measurement = "μg/m3"
|
||||
self._unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
self._available = None
|
||||
self._air_quality_index = None
|
||||
self._carbon_dioxide = None
|
||||
|
|
|
@ -21,8 +21,8 @@ from homeassistant.const import (
|
|||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
PRESSURE_HPA,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
TEMP_CELSIUS,
|
||||
TIME_SECONDS,
|
||||
)
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -42,8 +42,8 @@ SENSOR_TYPES = {
|
|||
"symbol": ["Symbol", None, None],
|
||||
"precipitation": ["Precipitation", "mm", None],
|
||||
"temperature": ["Temperature", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE],
|
||||
"windSpeed": ["Wind speed", f"m/{TIME_SECONDS}", None],
|
||||
"windGust": ["Wind gust", f"m/{TIME_SECONDS}", None],
|
||||
"windSpeed": ["Wind speed", SPEED_METERS_PER_SECOND, None],
|
||||
"windGust": ["Wind gust", SPEED_METERS_PER_SECOND, None],
|
||||
"pressure": ["Pressure", PRESSURE_HPA, DEVICE_CLASS_PRESSURE],
|
||||
"windDirection": ["Wind direction", "°", None],
|
||||
"humidity": ["Humidity", "%", DEVICE_CLASS_HUMIDITY],
|
||||
|
|
|
@ -17,7 +17,7 @@ from homeassistant.const import (
|
|||
CONF_LONGITUDE,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
TIME_HOURS,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
__version__,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -40,12 +40,17 @@ SENSOR_TYPES = {
|
|||
"pressure": ("Pressure", "hPa", "LDstat hPa", float),
|
||||
"pressure_sealevel": ("Pressure at Sea Level", "hPa", "LDred hPa", float),
|
||||
"humidity": ("Humidity", "%", "RF %", int),
|
||||
"wind_speed": ("Wind Speed", f"km/{TIME_HOURS}", f"WG km/{TIME_HOURS}", float),
|
||||
"wind_speed": (
|
||||
"Wind Speed",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
f"WG {SPEED_KILOMETERS_PER_HOUR}",
|
||||
float,
|
||||
),
|
||||
"wind_bearing": ("Wind Bearing", "°", "WR °", int),
|
||||
"wind_max_speed": (
|
||||
"Top Wind Speed",
|
||||
f"km/{TIME_HOURS}",
|
||||
f"WSG km/{TIME_HOURS}",
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
f"WSG {SPEED_KILOMETERS_PER_HOUR}",
|
||||
float,
|
||||
),
|
||||
"wind_max_bearing": ("Top Wind Bearing", "°", "WSR °", int),
|
||||
|
|
|
@ -375,13 +375,19 @@ PRESSURE_PSI: str = "psi"
|
|||
# Volume units
|
||||
VOLUME_LITERS: str = "L"
|
||||
VOLUME_MILLILITERS: str = "mL"
|
||||
VOLUME_CUBIC_METERS = f"{LENGTH_METERS}³"
|
||||
|
||||
VOLUME_GALLONS: str = "gal"
|
||||
VOLUME_FLUID_OUNCE: str = "fl. oz."
|
||||
|
||||
# Area units
|
||||
AREA_SQUARE_METERS = f"{LENGTH_METERS}²"
|
||||
|
||||
# Mass units
|
||||
MASS_GRAMS: str = "g"
|
||||
MASS_KILOGRAMS: str = "kg"
|
||||
MASS_MILLIGRAMS = "mg"
|
||||
MASS_MICROGRAMS = "µg"
|
||||
|
||||
MASS_OUNCES: str = "oz"
|
||||
MASS_POUNDS: str = "lb"
|
||||
|
@ -389,6 +395,20 @@ MASS_POUNDS: str = "lb"
|
|||
# UV Index units
|
||||
UNIT_UV_INDEX: str = "UV index"
|
||||
|
||||
# Irradiation units
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER = f"{POWER_WATT}/{AREA_SQUARE_METERS}"
|
||||
|
||||
# Concentration units
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER = f"{MASS_MICROGRAMS}/{VOLUME_CUBIC_METERS}"
|
||||
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER = f"{MASS_MILLIGRAMS}/{VOLUME_CUBIC_METERS}"
|
||||
CONCENTRATION_PARTS_PER_MILLION = "ppm"
|
||||
CONCENTRATION_PARTS_PER_BILLION = "ppb"
|
||||
|
||||
# Speed units
|
||||
SPEED_METERS_PER_SECOND = f"{LENGTH_METERS}/{TIME_SECONDS}"
|
||||
SPEED_KILOMETERS_PER_HOUR = f"{LENGTH_KILOMETERS}/{TIME_HOURS}"
|
||||
SPEED_MILES_PER_HOUR = "mph"
|
||||
|
||||
# Data units
|
||||
DATA_BITS = "bit"
|
||||
DATA_KILOBITS = "kbit"
|
||||
|
|
|
@ -16,6 +16,9 @@ from homeassistant.components.awair.sensor import (
|
|||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_UNAVAILABLE,
|
||||
|
@ -183,7 +186,7 @@ async def test_awair_co2(hass):
|
|||
sensor = hass.states.get("sensor.awair_co2")
|
||||
assert sensor.state == "612"
|
||||
assert sensor.attributes["device_class"] == DEVICE_CLASS_CARBON_DIOXIDE
|
||||
assert sensor.attributes["unit_of_measurement"] == "ppm"
|
||||
assert sensor.attributes["unit_of_measurement"] == CONCENTRATION_PARTS_PER_MILLION
|
||||
|
||||
|
||||
async def test_awair_voc(hass):
|
||||
|
@ -193,7 +196,7 @@ async def test_awair_voc(hass):
|
|||
sensor = hass.states.get("sensor.awair_voc")
|
||||
assert sensor.state == "1012"
|
||||
assert sensor.attributes["device_class"] == DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS
|
||||
assert sensor.attributes["unit_of_measurement"] == "ppb"
|
||||
assert sensor.attributes["unit_of_measurement"] == CONCENTRATION_PARTS_PER_BILLION
|
||||
|
||||
|
||||
async def test_awair_dust(hass):
|
||||
|
@ -205,7 +208,10 @@ async def test_awair_dust(hass):
|
|||
sensor = hass.states.get("sensor.awair_pm2_5")
|
||||
assert sensor.state == "6.2"
|
||||
assert sensor.attributes["device_class"] == DEVICE_CLASS_PM2_5
|
||||
assert sensor.attributes["unit_of_measurement"] == "µg/m3"
|
||||
assert (
|
||||
sensor.attributes["unit_of_measurement"]
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
|
||||
|
||||
async def test_awair_unsupported_sensors(hass):
|
||||
|
|
|
@ -15,7 +15,7 @@ import pytest
|
|||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.dsmr.sensor import DerivativeDSMREntity
|
||||
from homeassistant.const import TIME_HOURS
|
||||
from homeassistant.const import TIME_HOURS, VOLUME_CUBIC_METERS
|
||||
|
||||
from tests.common import assert_setup_component
|
||||
|
||||
|
@ -67,7 +67,7 @@ async def test_default_setup(hass, mock_connection_factory):
|
|||
GAS_METER_READING: MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
),
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ async def test_default_setup(hass, mock_connection_factory):
|
|||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == "m3"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
async def test_derivative():
|
||||
|
@ -119,7 +119,7 @@ async def test_derivative():
|
|||
"1.0.0": MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
)
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ async def test_derivative():
|
|||
"1.0.0": MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642543)},
|
||||
{"value": Decimal(745.698), "unit": "m3"},
|
||||
{"value": Decimal(745.698), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
)
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ async def test_derivative():
|
|||
abs(entity.state - 0.033) < 0.00001
|
||||
), "state should be hourly usage calculated from first and second update"
|
||||
|
||||
assert entity.unit_of_measurement == f"m3/{TIME_HOURS}"
|
||||
assert entity.unit_of_measurement == f"{VOLUME_CUBIC_METERS}/{TIME_HOURS}"
|
||||
|
||||
|
||||
async def test_v4_meter(hass, mock_connection_factory):
|
||||
|
@ -160,7 +160,7 @@ async def test_v4_meter(hass, mock_connection_factory):
|
|||
HOURLY_GAS_METER_READING: MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
),
|
||||
ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]),
|
||||
|
@ -185,7 +185,7 @@ async def test_v4_meter(hass, mock_connection_factory):
|
|||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == "m3"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
async def test_belgian_meter(hass, mock_connection_factory):
|
||||
|
@ -204,7 +204,7 @@ async def test_belgian_meter(hass, mock_connection_factory):
|
|||
BELGIUM_HOURLY_GAS_METER_READING: MBusObject(
|
||||
[
|
||||
{"value": datetime.datetime.fromtimestamp(1551642213)},
|
||||
{"value": Decimal(745.695), "unit": "m3"},
|
||||
{"value": Decimal(745.695), "unit": VOLUME_CUBIC_METERS},
|
||||
]
|
||||
),
|
||||
ELECTRICITY_ACTIVE_TARIFF: CosemObject([{"value": "0001", "unit": ""}]),
|
||||
|
@ -229,7 +229,7 @@ async def test_belgian_meter(hass, mock_connection_factory):
|
|||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == "m3"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
|
||||
|
||||
async def test_belgian_meter_low(hass, mock_connection_factory):
|
||||
|
|
|
@ -8,7 +8,12 @@ import pytest
|
|||
|
||||
from homeassistant.components.foobot import sensor as foobot
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -33,11 +38,11 @@ async def test_default_setup(hass, aioclient_mock):
|
|||
assert await async_setup_component(hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
|
||||
|
||||
metrics = {
|
||||
"co2": ["1232.0", "ppm"],
|
||||
"co2": ["1232.0", CONCENTRATION_PARTS_PER_MILLION],
|
||||
"temperature": ["21.1", TEMP_CELSIUS],
|
||||
"humidity": ["49.5", "%"],
|
||||
"pm2_5": ["144.8", "µg/m3"],
|
||||
"voc": ["340.7", "ppb"],
|
||||
"pm2_5": ["144.8", CONCENTRATION_MICROGRAMS_PER_CUBIC_METER],
|
||||
"voc": ["340.7", CONCENTRATION_PARTS_PER_BILLION],
|
||||
"index": ["138.9", "%"],
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,14 @@ from homeassistant.components.homematicip_cloud.sensor import (
|
|||
ATTR_TEMPERATURE_OFFSET,
|
||||
ATTR_WIND_DIRECTION,
|
||||
ATTR_WIND_DIRECTION_VARIATION,
|
||||
TIME_HOURS,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, POWER_WATT, TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
POWER_WATT,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||
|
@ -285,7 +289,7 @@ async def test_hmip_windspeed_sensor(hass, default_mock_hap_factory):
|
|||
)
|
||||
|
||||
assert ha_state.state == "2.6"
|
||||
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == f"km/{TIME_HOURS}"
|
||||
assert ha_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == SPEED_KILOMETERS_PER_HOUR
|
||||
await async_manipulate_test_data(hass, hmip_device, "windSpeed", 9.4)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == "9.4"
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import DEFAULT, Mock, patch
|
|||
|
||||
import homeassistant.components.mhz19.sensor as mhz19
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import TEMP_FAHRENHEIT
|
||||
from homeassistant.const import CONCENTRATION_PARTS_PER_MILLION, TEMP_FAHRENHEIT
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
|
@ -100,7 +100,7 @@ class TestMHZ19Sensor(unittest.TestCase):
|
|||
|
||||
assert "name: CO2" == sensor.name
|
||||
assert 1000 == sensor.state
|
||||
assert "ppm" == sensor.unit_of_measurement
|
||||
assert CONCENTRATION_PARTS_PER_MILLION == sensor.unit_of_measurement
|
||||
assert sensor.should_poll
|
||||
assert {"temperature": 24} == sensor.device_state_attributes
|
||||
|
||||
|
|
|
@ -5,7 +5,11 @@ from homeassistant import setup
|
|||
from homeassistant.components import climate, sensor
|
||||
from homeassistant.components.demo.sensor import DemoSensor
|
||||
import homeassistant.components.prometheus as prometheus
|
||||
from homeassistant.const import DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
DEVICE_CLASS_POWER,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
|
@ -47,7 +51,12 @@ async def prometheus_client(loop, hass, hass_client):
|
|||
await sensor4.async_update_ha_state()
|
||||
|
||||
sensor5 = DemoSensor(
|
||||
None, "SPS30 PM <1µm Weight concentration", 3.7069, None, "µg/m³", None
|
||||
None,
|
||||
"SPS30 PM <1µm Weight concentration",
|
||||
3.7069,
|
||||
None,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
None,
|
||||
)
|
||||
sensor5.hass = hass
|
||||
sensor5.entity_id = "sensor.sps30_pm_1um_weight_concentration"
|
||||
|
|
|
@ -3,7 +3,7 @@ from datetime import datetime
|
|||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.const import TIME_SECONDS
|
||||
from homeassistant.const import SPEED_METERS_PER_SECOND
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import assert_setup_component, load_fixture
|
||||
|
@ -71,7 +71,7 @@ async def test_custom_setup(hass, aioclient_mock):
|
|||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.yr_wind_speed")
|
||||
assert state.attributes.get("unit_of_measurement") == f"m/{TIME_SECONDS}"
|
||||
assert state.attributes.get("unit_of_measurement") == SPEED_METERS_PER_SECOND
|
||||
assert state.state == "3.5"
|
||||
|
||||
|
||||
|
@ -117,5 +117,5 @@ async def test_forecast_setup(hass, aioclient_mock):
|
|||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.yr_wind_speed")
|
||||
assert state.attributes.get("unit_of_measurement") == f"m/{TIME_SECONDS}"
|
||||
assert state.attributes.get("unit_of_measurement") == SPEED_METERS_PER_SECOND
|
||||
assert state.state == "3.6"
|
||||
|
|
Loading…
Reference in New Issue