Fix misleading comments in tomorrowio (#74049)
* Fix misleading comments in tomorrowio * Add test
This commit is contained in:
parent
5f06404db5
commit
84ea8a3c43
2 changed files with 45 additions and 13 deletions
|
@ -28,7 +28,6 @@ from homeassistant.const import (
|
|||
IRRADIATION_BTUS_PER_HOUR_SQUARE_FOOT,
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_METERS,
|
||||
LENGTH_MILES,
|
||||
PERCENTAGE,
|
||||
PRESSURE_HPA,
|
||||
|
@ -40,6 +39,7 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.util.distance import convert as distance_convert
|
||||
from homeassistant.util.speed import convert as speed_convert
|
||||
|
||||
from . import TomorrowioDataUpdateCoordinator, TomorrowioEntity
|
||||
from .const import (
|
||||
|
@ -113,14 +113,14 @@ SENSOR_TYPES = (
|
|||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
# Data comes in as inHg
|
||||
# Data comes in as hPa
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_PRESSURE_SURFACE_LEVEL,
|
||||
name="Pressure (Surface Level)",
|
||||
native_unit_of_measurement=PRESSURE_HPA,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
),
|
||||
# Data comes in as BTUs/(hr * ft^2)
|
||||
# Data comes in as W/m^2, convert to BTUs/(hr * ft^2) for imperial
|
||||
# https://www.theunitconverter.com/watt-square-meter-to-btu-hour-square-foot-conversion/
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_SOLAR_GHI,
|
||||
|
@ -129,7 +129,7 @@ SENSOR_TYPES = (
|
|||
unit_metric=IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
imperial_conversion=(1 / 3.15459),
|
||||
),
|
||||
# Data comes in as miles
|
||||
# Data comes in as km, convert to miles for imperial
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_CLOUD_BASE,
|
||||
name="Cloud Base",
|
||||
|
@ -139,7 +139,7 @@ SENSOR_TYPES = (
|
|||
val, LENGTH_KILOMETERS, LENGTH_MILES
|
||||
),
|
||||
),
|
||||
# Data comes in as miles
|
||||
# Data comes in as km, convert to miles for imperial
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_CLOUD_CEILING,
|
||||
name="Cloud Ceiling",
|
||||
|
@ -154,16 +154,15 @@ SENSOR_TYPES = (
|
|||
name="Cloud Cover",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
# Data comes in as MPH
|
||||
# Data comes in as m/s, convert to mi/h for imperial
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_WIND_GUST,
|
||||
name="Wind Gust",
|
||||
unit_imperial=SPEED_MILES_PER_HOUR,
|
||||
unit_metric=SPEED_METERS_PER_SECOND,
|
||||
imperial_conversion=lambda val: distance_convert(
|
||||
val, LENGTH_METERS, LENGTH_MILES
|
||||
)
|
||||
* 3600,
|
||||
imperial_conversion=lambda val: speed_convert(
|
||||
val, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR
|
||||
),
|
||||
),
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_PRECIPITATION_TYPE,
|
||||
|
@ -172,7 +171,7 @@ SENSOR_TYPES = (
|
|||
device_class="tomorrowio__precipitation_type",
|
||||
icon="mdi:weather-snowy-rainy",
|
||||
),
|
||||
# Data comes in as ppb
|
||||
# Data comes in as ppb, convert to µg/m^3
|
||||
# Molecular weight of Ozone is 48
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_OZONE,
|
||||
|
@ -193,7 +192,7 @@ SENSOR_TYPES = (
|
|||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
device_class=SensorDeviceClass.PM10,
|
||||
),
|
||||
# Data comes in as ppb
|
||||
# Data comes in as ppb, convert to µg/m^3
|
||||
# Molecular weight of Nitrogen Dioxide is 46.01
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_NITROGEN_DIOXIDE,
|
||||
|
@ -202,7 +201,7 @@ SENSOR_TYPES = (
|
|||
multiplication_factor=convert_ppb_to_ugm3(46.01),
|
||||
device_class=SensorDeviceClass.NITROGEN_DIOXIDE,
|
||||
),
|
||||
# Data comes in as ppb
|
||||
# Data comes in as ppb, convert to ppm
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_CARBON_MONOXIDE,
|
||||
name="Carbon Monoxide",
|
||||
|
@ -210,6 +209,7 @@ SENSOR_TYPES = (
|
|||
multiplication_factor=1 / 1000,
|
||||
device_class=SensorDeviceClass.CO,
|
||||
),
|
||||
# Data comes in as ppb, convert to µg/m^3
|
||||
# Molecular weight of Sulphur Dioxide is 64.07
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_SULPHUR_DIOXIDE,
|
||||
|
|
|
@ -25,6 +25,7 @@ from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
|
|||
from homeassistant.core import HomeAssistant, State, callback
|
||||
from homeassistant.helpers.entity_registry import async_get
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
|
||||
from .const import API_V4_ENTRY_DATA
|
||||
|
||||
|
@ -169,6 +170,37 @@ async def test_v4_sensor(hass: HomeAssistant) -> None:
|
|||
check_sensor_state(hass, PRECIPITATION_TYPE, "rain")
|
||||
|
||||
|
||||
async def test_v4_sensor_imperial(hass: HomeAssistant) -> None:
|
||||
"""Test v4 sensor data."""
|
||||
hass.config.units = IMPERIAL_SYSTEM
|
||||
await _setup(hass, V4_FIELDS, API_V4_ENTRY_DATA)
|
||||
check_sensor_state(hass, O3, "91.35")
|
||||
check_sensor_state(hass, CO, "0.0")
|
||||
check_sensor_state(hass, NO2, "20.08")
|
||||
check_sensor_state(hass, SO2, "4.32")
|
||||
check_sensor_state(hass, PM25, "0.15")
|
||||
check_sensor_state(hass, PM10, "0.57")
|
||||
check_sensor_state(hass, MEP_AQI, "23")
|
||||
check_sensor_state(hass, MEP_HEALTH_CONCERN, "good")
|
||||
check_sensor_state(hass, MEP_PRIMARY_POLLUTANT, "pm10")
|
||||
check_sensor_state(hass, EPA_AQI, "24")
|
||||
check_sensor_state(hass, EPA_HEALTH_CONCERN, "good")
|
||||
check_sensor_state(hass, EPA_PRIMARY_POLLUTANT, "pm25")
|
||||
check_sensor_state(hass, FIRE_INDEX, "10")
|
||||
check_sensor_state(hass, GRASS_POLLEN, "none")
|
||||
check_sensor_state(hass, WEED_POLLEN, "none")
|
||||
check_sensor_state(hass, TREE_POLLEN, "none")
|
||||
check_sensor_state(hass, FEELS_LIKE, "214.3")
|
||||
check_sensor_state(hass, DEW_POINT, "163.08")
|
||||
check_sensor_state(hass, PRESSURE_SURFACE_LEVEL, "29.47")
|
||||
check_sensor_state(hass, GHI, "0.0")
|
||||
check_sensor_state(hass, CLOUD_BASE, "0.46")
|
||||
check_sensor_state(hass, CLOUD_COVER, "100")
|
||||
check_sensor_state(hass, CLOUD_CEILING, "0.46")
|
||||
check_sensor_state(hass, WIND_GUST, "28.27")
|
||||
check_sensor_state(hass, PRECIPITATION_TYPE, "rain")
|
||||
|
||||
|
||||
async def test_entity_description() -> None:
|
||||
"""Test improper entity description raises."""
|
||||
with pytest.raises(ValueError):
|
||||
|
|
Loading…
Add table
Reference in a new issue