diff --git a/homeassistant/components/weatherflow/quality_scale.yaml b/homeassistant/components/weatherflow/quality_scale.yaml index 3b894c3033ab..fe717c0daa97 100644 --- a/homeassistant/components/weatherflow/quality_scale.yaml +++ b/homeassistant/components/weatherflow/quality_scale.yaml @@ -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 diff --git a/homeassistant/components/weatherflow/sensor.py b/homeassistant/components/weatherflow/sensor.py index 0b5fcc6dcfd4..a4361cfadc0a 100644 --- a/homeassistant/components/weatherflow/sensor.py +++ b/homeassistant/components/weatherflow/sensor.py @@ -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( diff --git a/tests/components/weatherflow/__init__.py b/tests/components/weatherflow/__init__.py index e7dd3dc0958c..45a4e4b03f9e 100644 --- a/tests/components/weatherflow/__init__.py +++ b/tests/components/weatherflow/__init__.py @@ -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() diff --git a/tests/components/weatherflow/conftest.py b/tests/components/weatherflow/conftest.py index 21c251d39b5f..69a2fe6a6ea8 100644 --- a/tests/components/weatherflow/conftest.py +++ b/tests/components/weatherflow/conftest.py @@ -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.""" diff --git a/tests/components/weatherflow/fixtures/obs_st.json b/tests/components/weatherflow/fixtures/obs_st.json new file mode 100644 index 000000000000..a1590e8ba010 --- /dev/null +++ b/tests/components/weatherflow/fixtures/obs_st.json @@ -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 +} diff --git a/tests/components/weatherflow/snapshots/test_sensor.ambr b/tests/components/weatherflow/snapshots/test_sensor.ambr new file mode 100644 index 000000000000..6f7bb09eade2 --- /dev/null +++ b/tests/components/weatherflow/snapshots/test_sensor.ambr @@ -0,0 +1,1658 @@ +# serializer version: 1 +# name: test_all_entities[sensor.st_00000001_air_density-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_air_density', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Air density', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 5, + }), + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Air density', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'air_density', + 'unique_id': 'ST-00000001_air_density', + 'unit_of_measurement': 'kg/m³', + }) +# --- +# name: test_all_entities[sensor.st_00000001_air_density-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'ST-00000001 Air density', + : , + : 'kg/m³', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_air_density', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1.18848260320538', + }) +# --- +# name: test_all_entities[sensor.st_00000001_air_pressure-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_air_pressure', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Air pressure', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 5, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Air pressure', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'station_pressure', + 'unique_id': 'ST-00000001_station_pressure', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_air_pressure-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'atmospheric_pressure', + : 'ST-00000001 Air pressure', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_air_pressure', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1008.15', + }) +# --- +# name: test_all_entities[sensor.st_00000001_battery-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.st_00000001_battery', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Battery', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_battery_percent', + 'unit_of_measurement': '%', + }) +# --- +# name: test_all_entities[sensor.st_00000001_battery-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'battery', + : 'ST-00000001 Battery', + : , + : '%', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_battery', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '96.8611111111111', + }) +# --- +# name: test_all_entities[sensor.st_00000001_battery_voltage-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.st_00000001_battery_voltage', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Battery voltage', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery voltage', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'battery_voltage', + 'unique_id': 'ST-00000001_battery', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_battery_voltage-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'voltage', + : 'ST-00000001 Battery voltage', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_battery_voltage', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '2.587', + }) +# --- +# name: test_all_entities[sensor.st_00000001_dew_point-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_dew_point', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Dew point', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 1, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Dew point', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'dew_point', + 'unique_id': 'ST-00000001_dew_point_temperature', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_dew_point-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'temperature', + : 'ST-00000001 Dew point', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_dew_point', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '17.2769447809253', + }) +# --- +# name: test_all_entities[sensor.st_00000001_feels_like-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_feels_like', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Feels like', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 1, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Feels like', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'feels_like', + 'unique_id': 'ST-00000001_feels_like_temperature', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_feels_like-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'temperature', + : 'ST-00000001 Feels like', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_feels_like', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '22.37', + }) +# --- +# name: test_all_entities[sensor.st_00000001_humidity-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_humidity', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Humidity', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Humidity', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_relative_humidity', + 'unit_of_measurement': '%', + }) +# --- +# name: test_all_entities[sensor.st_00000001_humidity-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'humidity', + : 'ST-00000001 Humidity', + : , + : '%', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_humidity', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '72.91', + }) +# --- +# name: test_all_entities[sensor.st_00000001_illuminance-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_illuminance', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Illuminance', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Illuminance', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_illuminance', + 'unit_of_measurement': 'lx', + }) +# --- +# name: test_all_entities[sensor.st_00000001_illuminance-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'illuminance', + : 'ST-00000001 Illuminance', + : , + : 'lx', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_illuminance', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '328', + }) +# --- +# name: test_all_entities[sensor.st_00000001_irradiance-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_irradiance', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Irradiance', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Irradiance', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_solar_radiation', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_irradiance-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'irradiance', + : 'ST-00000001 Irradiance', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_irradiance', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '3', + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_average_distance-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_lightning_average_distance', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Lightning average distance', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Lightning average distance', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'lightning_average_distance', + 'unique_id': 'ST-00000001_lightning_strike_average_distance', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_average_distance-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'distance', + : 'ST-00000001 Lightning average distance', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_lightning_average_distance', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_count-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_lightning_count', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Lightning count', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Lightning count', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'lightning_count', + 'unique_id': 'ST-00000001_lightning_strike_count', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_count-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'ST-00000001 Lightning count', + : '2017-11-16T18:13:00+00:00', + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_lightning_count', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_last_distance-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_lightning_last_distance', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Lightning last distance', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Lightning last distance', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'lightning_strike_last_distance', + 'unique_id': 'ST-00000001_lightning_strike_last_distance', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_last_distance-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'distance', + : 'ST-00000001 Lightning last distance', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_lightning_last_distance', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unavailable', + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_last_energy-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_lightning_last_energy', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Lightning last energy', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Lightning last energy', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'lightning_strike_last_energy', + 'unique_id': 'ST-00000001_lightning_strike_last_energy', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_last_energy-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'ST-00000001 Lightning last energy', + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_lightning_last_energy', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unavailable', + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_last_strike-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_lightning_last_strike', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Lightning last strike', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Lightning last strike', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'lightning_strike_last_epoch', + 'unique_id': 'ST-00000001_lightning_strike_last_epoch', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[sensor.st_00000001_lightning_last_strike-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'timestamp', + : 'ST-00000001 Lightning last strike', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_lightning_last_strike', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unavailable', + }) +# --- +# name: test_all_entities[sensor.st_00000001_precipitation-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_precipitation', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Precipitation', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Precipitation', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_rain_accumulation_previous_minute', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_precipitation-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'precipitation', + : 'ST-00000001 Precipitation', + : '2017-11-16T18:13:00+00:00', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_precipitation', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.12', + }) +# --- +# name: test_all_entities[sensor.st_00000001_precipitation_intensity-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_precipitation_intensity', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Precipitation intensity', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Precipitation intensity', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_rain_rate', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_precipitation_intensity-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'precipitation_intensity', + : 'ST-00000001 Precipitation intensity', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_precipitation_intensity', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '7.2', + }) +# --- +# name: test_all_entities[sensor.st_00000001_precipitation_type-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + 'none', + 'rain', + 'hail', + 'rain_hail', + 'unknown', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_precipitation_type', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Precipitation type', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Precipitation type', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'precipitation_type', + 'unique_id': 'ST-00000001_precipitation_type', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[sensor.st_00000001_precipitation_type-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'enum', + : 'ST-00000001 Precipitation type', + : list([ + 'none', + 'rain', + 'hail', + 'rain_hail', + 'unknown', + ]), + }), + 'context': , + 'entity_id': 'sensor.st_00000001_precipitation_type', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'rain', + }) +# --- +# name: test_all_entities[sensor.st_00000001_signal_strength-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.st_00000001_signal_strength', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Signal strength', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Signal strength', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_rssi', + 'unit_of_measurement': 'dBm', + }) +# --- +# name: test_all_entities[sensor.st_00000001_signal_strength-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'signal_strength', + : 'ST-00000001 Signal strength', + : , + : 'dBm', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_signal_strength', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '-17', + }) +# --- +# name: test_all_entities[sensor.st_00000001_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Temperature', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 1, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Temperature', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_air_temperature', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'temperature', + : 'ST-00000001 Temperature', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '22.37', + }) +# --- +# name: test_all_entities[sensor.st_00000001_uptime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.st_00000001_uptime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Uptime', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Uptime', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'uptime', + 'unique_id': 'ST-00000001_up_since', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[sensor.st_00000001_uptime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'timestamp', + : 'ST-00000001 Uptime', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_uptime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '2017-11-16T17:35:34+00:00', + }) +# --- +# name: test_all_entities[sensor.st_00000001_uv_index-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_uv_index', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'UV index', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'UV index', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'uv_index', + 'unique_id': 'ST-00000001_uv', + 'unit_of_measurement': 'UV index', + }) +# --- +# name: test_all_entities[sensor.st_00000001_uv_index-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'ST-00000001 UV index', + : , + : 'UV index', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_uv_index', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '4.86', + }) +# --- +# name: test_all_entities[sensor.st_00000001_vapor_pressure-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_vapor_pressure', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Vapor pressure', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 5, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Vapor pressure', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'vapor_pressure', + 'unique_id': 'ST-00000001_vapor_pressure', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_vapor_pressure-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'pressure', + : 'ST-00000001 Vapor pressure', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_vapor_pressure', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '19.7224081566478', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wet_bulb_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wet_bulb_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wet bulb temperature', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 1, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wet bulb temperature', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'wet_bulb_temperature', + 'unique_id': 'ST-00000001_wet_bulb_temperature', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_wet_bulb_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'temperature', + : 'ST-00000001 Wet bulb temperature', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wet_bulb_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '18.9695525487391', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_direction-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wind_direction', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wind direction', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wind direction', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'wind_direction', + 'unique_id': 'ST-00000001_wind_direction', + 'unit_of_measurement': '°', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_direction-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'wind_direction', + : 'ST-00000001 Wind direction', + : , + : '°', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wind_direction', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '144', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_direction_average-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wind_direction_average', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wind direction average', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wind direction average', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'wind_direction_average', + 'unique_id': 'ST-00000001_wind_direction_average', + 'unit_of_measurement': '°', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_direction_average-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'wind_direction', + : 'ST-00000001 Wind direction average', + : '°', + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wind_direction_average', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '144', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_gust-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wind_gust', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wind gust', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wind gust', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'wind_gust', + 'unique_id': 'ST-00000001_wind_gust', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_gust-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'wind_speed', + : 'ST-00000001 Wind gust', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wind_gust', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.972', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_lull-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wind_lull', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wind lull', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wind lull', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'wind_lull', + 'unique_id': 'ST-00000001_wind_lull', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_lull-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'wind_speed', + : 'ST-00000001 Wind lull', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wind_lull', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.648', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_speed-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wind_speed', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wind speed', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wind speed', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ST-00000001_wind_speed', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_speed-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'wind_speed', + : 'ST-00000001 Wind speed', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wind_speed', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.792', + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_speed_average-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.st_00000001_wind_speed_average', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Wind speed average', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Wind speed average', + 'platform': 'weatherflow', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'wind_speed_average', + 'unique_id': 'ST-00000001_wind_average', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.st_00000001_wind_speed_average-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'wind_speed', + : 'ST-00000001 Wind speed average', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.st_00000001_wind_speed_average', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.792', + }) +# --- diff --git a/tests/components/weatherflow/test_sensor.py b/tests/components/weatherflow/test_sensor.py new file mode 100644 index 000000000000..c818e70fbc41 --- /dev/null +++ b/tests/components/weatherflow/test_sensor.py @@ -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