mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Fix station name sensor for metoffice (#145500)
This commit is contained in:
parent
59bf39f4ed
commit
655f009f07
@ -9,6 +9,7 @@ from datapoint.Forecast import Forecast
|
|||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
DOMAIN as SENSOR_DOMAIN,
|
DOMAIN as SENSOR_DOMAIN,
|
||||||
|
EntityCategory,
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
@ -59,6 +60,7 @@ SENSOR_TYPES: tuple[MetOfficeSensorEntityDescription, ...] = (
|
|||||||
native_attr_name="name",
|
native_attr_name="name",
|
||||||
name="Station name",
|
name="Station name",
|
||||||
icon="mdi:label-outline",
|
icon="mdi:label-outline",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
MetOfficeSensorEntityDescription(
|
MetOfficeSensorEntityDescription(
|
||||||
@ -235,14 +237,13 @@ class MetOfficeCurrentSensor(
|
|||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
value = get_attribute(
|
native_attr = self.entity_description.native_attr_name
|
||||||
self.coordinator.data.now(), self.entity_description.native_attr_name
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
if native_attr == "name":
|
||||||
self.entity_description.native_attr_name == "significantWeatherCode"
|
return str(self.coordinator.data.name)
|
||||||
and value is not None
|
|
||||||
):
|
value = get_attribute(self.coordinator.data.now(), native_attr)
|
||||||
|
if native_attr == "significantWeatherCode" and value is not None:
|
||||||
value = CONDITION_MAP.get(value)
|
value = CONDITION_MAP.get(value)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
@ -40,6 +40,12 @@ KINGSLYNN_SENSOR_RESULTS = {
|
|||||||
"probability_of_precipitation": "67",
|
"probability_of_precipitation": "67",
|
||||||
"pressure": "998.20",
|
"pressure": "998.20",
|
||||||
"wind_speed": "22.21",
|
"wind_speed": "22.21",
|
||||||
|
"wind_direction": "180",
|
||||||
|
"wind_gust": "40.26",
|
||||||
|
"feels_like_temperature": "3.4",
|
||||||
|
"visibility_distance": "7478.00",
|
||||||
|
"humidity": "97.5",
|
||||||
|
"station_name": "King's Lynn",
|
||||||
}
|
}
|
||||||
|
|
||||||
WAVERTREE_SENSOR_RESULTS = {
|
WAVERTREE_SENSOR_RESULTS = {
|
||||||
@ -49,6 +55,12 @@ WAVERTREE_SENSOR_RESULTS = {
|
|||||||
"probability_of_precipitation": "61",
|
"probability_of_precipitation": "61",
|
||||||
"pressure": "987.50",
|
"pressure": "987.50",
|
||||||
"wind_speed": "17.60",
|
"wind_speed": "17.60",
|
||||||
|
"wind_direction": "176",
|
||||||
|
"wind_gust": "34.52",
|
||||||
|
"feels_like_temperature": "5.8",
|
||||||
|
"visibility_distance": "5106.00",
|
||||||
|
"humidity": "95.13",
|
||||||
|
"station_name": "Wavertree",
|
||||||
}
|
}
|
||||||
|
|
||||||
DEVICE_KEY_KINGSLYNN = {(DOMAIN, TEST_COORDINATES_KINGSLYNN)}
|
DEVICE_KEY_KINGSLYNN = {(DOMAIN, TEST_COORDINATES_KINGSLYNN)}
|
||||||
|
@ -28,6 +28,7 @@ from tests.common import MockConfigEntry, async_load_fixture, get_sensor_display
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.freeze_time(datetime.datetime(2024, 11, 23, 12, tzinfo=datetime.UTC))
|
@pytest.mark.freeze_time(datetime.datetime(2024, 11, 23, 12, tzinfo=datetime.UTC))
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
async def test_one_sensor_site_running(
|
async def test_one_sensor_site_running(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
@ -78,6 +79,7 @@ async def test_one_sensor_site_running(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.freeze_time(datetime.datetime(2024, 11, 23, 12, tzinfo=datetime.UTC))
|
@pytest.mark.freeze_time(datetime.datetime(2024, 11, 23, 12, tzinfo=datetime.UTC))
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
async def test_two_sensor_sites_running(
|
async def test_two_sensor_sites_running(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user