Use atmospheric pressure device class for WeatherFlow station pressure (#182996)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Andreas Ehn
2026-09-25 12:10:49 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 8f3b07ea39
commit 668b21e591
7 changed files with 1768 additions and 7 deletions
@@ -96,10 +96,8 @@ rules:
test-coverage:
status: todo
comment: |
Only config-flow tests exist (tests/components/weatherflow/
test_config_flow.py). There are no tests for the sensor or event
platform entities, nor for async_setup_entry / async_unload_entry
behaviour. Coverage is well below the 95% Silver threshold.
There are no tests for the event platform entities, nor for
async_unload_entry / device removal behaviour.
# Gold
devices: done
@@ -194,7 +194,6 @@ SENSORS: tuple[WeatherFlowSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
state_class=SensorStateClass.TOTAL,
device_class=SensorDeviceClass.PRECIPITATION,
imperial_suggested_unit=UnitOfPrecipitationDepth.INCHES,
raw_data_conv_fn=lambda raw_data: raw_data.magnitude,
),
WeatherFlowSensorEntityDescription(
@@ -225,10 +224,9 @@ SENSORS: tuple[WeatherFlowSensorEntityDescription, ...] = (
key="station_pressure",
translation_key="station_pressure",
native_unit_of_measurement=UnitOfPressure.MBAR,
device_class=SensorDeviceClass.PRESSURE,
device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=5,
imperial_suggested_unit=UnitOfPressure.INHG,
raw_data_conv_fn=lambda raw_data: raw_data.magnitude,
),
WeatherFlowSensorEntityDescription(
+21
View File
@@ -1 +1,22 @@
"""Tests for the WeatherFlow integration."""
from pyweatherflowudp.aioudp import LocalEndpoint
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture_bytes
HUB_ADDRESS = ("192.0.2.1", 50222)
async def setup_integration(
hass: HomeAssistant, config_entry: MockConfigEntry, endpoint: LocalEndpoint
) -> None:
"""Set up the integration and receive the UDP packets of a Tempest."""
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
for fixture in ("device.json", "obs_st.json"):
endpoint.feed_datagram(load_fixture_bytes(fixture, "weatherflow"), HUB_ADDRESS)
await hass.async_block_till_done()
+9
View File
@@ -5,6 +5,7 @@ from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
from pyweatherflowudp.aioudp import LocalEndpoint
from pyweatherflowudp.client import EVENT_DEVICE_DISCOVERED
from pyweatherflowudp.device import WeatherFlowDevice
@@ -28,6 +29,14 @@ def mock_config_entry() -> MockConfigEntry:
return MockConfigEntry(domain=DOMAIN, data={})
@pytest.fixture
def mock_udp_endpoint() -> Generator[LocalEndpoint]:
"""Replace the UDP socket with an endpoint the tests feed packets into."""
endpoint = LocalEndpoint()
with patch("pyweatherflowudp.client.open_local_endpoint", return_value=endpoint):
yield endpoint
@pytest.fixture
def mock_has_devices() -> Generator[AsyncMock]:
"""Return a mock has_devices function."""
@@ -0,0 +1,12 @@
{
"serial_number": "ST-00000001",
"type": "obs_st",
"hub_sn": "HB-00000001",
"obs": [
[
1510855980, 0.18, 0.22, 0.27, 144, 6, 1008.15, 22.37, 72.91, 328, 4.86, 3,
0.12, 1, 0, 0, 2.587, 1
]
],
"firmware_revision": 129
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,65 @@
"""Tests for the WeatherFlow sensor platform."""
from unittest.mock import patch
import pytest
from pyweatherflowudp.aioudp import LocalEndpoint
from syrupy.assertion import SnapshotAssertion
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.util.unit_system import (
METRIC_SYSTEM,
US_CUSTOMARY_SYSTEM,
UnitSystem,
)
from . import setup_integration
from tests.common import MockConfigEntry, snapshot_platform
RAIN_LAST_MINUTE = "sensor.st_00000001_precipitation"
STATION_PRESSURE = "sensor.st_00000001_air_pressure"
VAPOR_PRESSURE = "sensor.st_00000001_vapor_pressure"
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_all_entities(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
mock_config_entry: MockConfigEntry,
mock_udp_endpoint: LocalEndpoint,
) -> None:
"""Test all sensor entities."""
with patch("homeassistant.components.weatherflow.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry, mock_udp_endpoint)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize(
("unit_system", "entity_id", "unit"),
[
pytest.param(METRIC_SYSTEM, STATION_PRESSURE, "hPa", id="metric-pressure"),
pytest.param(METRIC_SYSTEM, VAPOR_PRESSURE, "mbar", id="metric-vapor"),
pytest.param(METRIC_SYSTEM, RAIN_LAST_MINUTE, "mm", id="metric-rain"),
pytest.param(US_CUSTOMARY_SYSTEM, STATION_PRESSURE, "inHg", id="us-pressure"),
pytest.param(US_CUSTOMARY_SYSTEM, VAPOR_PRESSURE, "inHg", id="us-vapor"),
pytest.param(US_CUSTOMARY_SYSTEM, RAIN_LAST_MINUTE, "in", id="us-rain"),
],
)
async def test_unit_system(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_udp_endpoint: LocalEndpoint,
unit_system: UnitSystem,
entity_id: str,
unit: str,
) -> None:
"""Test sensors are shown in the units of the configured unit system."""
hass.config.units = unit_system
await setup_integration(hass, mock_config_entry, mock_udp_endpoint)
assert hass.states.get(entity_id).attributes[ATTR_UNIT_OF_MEASUREMENT] == unit