mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 04:41:30 -04:00
Use atmospheric pressure device class for NWS pressure sensors (#187721)
This commit is contained in:
@@ -118,7 +118,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
|
||||
NWSSensorEntityDescription(
|
||||
key="barometricPressure",
|
||||
name="Barometric Pressure",
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfPressure.PA,
|
||||
unit_convert=UnitOfPressure.INHG,
|
||||
@@ -126,7 +126,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
|
||||
NWSSensorEntityDescription(
|
||||
key="seaLevelPressure",
|
||||
name="Sea Level Pressure",
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfPressure.PA,
|
||||
unit_convert=UnitOfPressure.INHG,
|
||||
|
||||
@@ -5,8 +5,14 @@ from pytest_homeassistant.common import MockConfigEntry
|
||||
|
||||
from homeassistant.components.nws.const import ATTRIBUTION, DOMAIN
|
||||
from homeassistant.components.nws.sensor import SENSOR_TYPES
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, STATE_UNKNOWN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNKNOWN,
|
||||
UnitOfPressure,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util import slugify
|
||||
@@ -71,6 +77,57 @@ async def test_imperial_metric(
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("units", "expected_unit"),
|
||||
[
|
||||
(US_CUSTOMARY_SYSTEM, UnitOfPressure.INHG),
|
||||
(METRIC_SYSTEM, UnitOfPressure.PA),
|
||||
],
|
||||
)
|
||||
async def test_pressure_sensors_use_atmospheric_pressure(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
units,
|
||||
expected_unit,
|
||||
mock_simple_nws,
|
||||
no_weather,
|
||||
) -> None:
|
||||
"""Test the pressure sensors report the atmospheric pressure device class."""
|
||||
pressure_descriptions = [
|
||||
description
|
||||
for description in SENSOR_TYPES
|
||||
if description.key in ("barometricPressure", "seaLevelPressure")
|
||||
]
|
||||
assert len(pressure_descriptions) == 2
|
||||
for description in pressure_descriptions:
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"35_-75_{description.key}",
|
||||
suggested_object_id=f"abc_{description.name}",
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
hass.config.units = units
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=NWS_CONFIG,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for description in pressure_descriptions:
|
||||
assert description.name
|
||||
state = hass.states.get(f"sensor.abc_{slugify(description.name)}")
|
||||
assert state
|
||||
assert (
|
||||
state.attributes[ATTR_DEVICE_CLASS]
|
||||
== SensorDeviceClass.ATMOSPHERIC_PRESSURE
|
||||
)
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == expected_unit
|
||||
|
||||
|
||||
@pytest.mark.parametrize("values", [NONE_OBSERVATION, None])
|
||||
async def test_none_values(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user