mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add sensor platform to SMHI (#139295)
This commit is contained in:
parent
29e105b0ef
commit
a6828898d1
@ -11,7 +11,7 @@ from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import SMHIConfigEntry, SMHIDataUpdateCoordinator
|
||||
|
||||
PLATFORMS = [Platform.WEATHER]
|
||||
PLATFORMS = [Platform.SENSOR, Platform.WEATHER]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: SMHIConfigEntry) -> bool:
|
||||
|
@ -61,3 +61,8 @@ class SMHIDataUpdateCoordinator(DataUpdateCoordinator[SMHIForecastData]):
|
||||
daily=_forecast_daily,
|
||||
hourly=_forecast_hourly,
|
||||
)
|
||||
|
||||
@property
|
||||
def current(self) -> SMHIForecast:
|
||||
"""Return the current metrics."""
|
||||
return self.data.daily[0]
|
||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
@ -16,7 +17,6 @@ class SmhiWeatherBaseEntity(CoordinatorEntity[SMHIDataUpdateCoordinator]):
|
||||
|
||||
_attr_attribution = "Swedish weather institute (SMHI)"
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -36,6 +36,12 @@ class SmhiWeatherBaseEntity(CoordinatorEntity[SMHIDataUpdateCoordinator]):
|
||||
)
|
||||
self.update_entity_data()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
self.update_entity_data()
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
@abstractmethod
|
||||
def update_entity_data(self) -> None:
|
||||
"""Refresh the entity data."""
|
||||
|
27
homeassistant/components/smhi/icons.json
Normal file
27
homeassistant/components/smhi/icons.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"thunder": {
|
||||
"default": "mdi:lightning-bolt"
|
||||
},
|
||||
"total_cloud": {
|
||||
"default": "mdi:cloud"
|
||||
},
|
||||
"low_cloud": {
|
||||
"default": "mdi:cloud-arrow-down"
|
||||
},
|
||||
"medium_cloud": {
|
||||
"default": "mdi:cloud-arrow-right"
|
||||
},
|
||||
"high_cloud": {
|
||||
"default": "mdi:cloud-arrow-up"
|
||||
},
|
||||
"precipitation_category": {
|
||||
"default": "mdi:weather-pouring"
|
||||
},
|
||||
"frozen_precipitation": {
|
||||
"default": "mdi:weather-snowy-rainy"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
139
homeassistant/components/smhi/sensor.py
Normal file
139
homeassistant/components/smhi/sensor.py
Normal file
@ -0,0 +1,139 @@
|
||||
"""Sensor platform for SMHI integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LOCATION, CONF_LONGITUDE, PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .coordinator import SMHIConfigEntry, SMHIDataUpdateCoordinator
|
||||
from .entity import SmhiWeatherBaseEntity
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
def get_percentage_values(entity: SMHISensor, key: str) -> int | None:
|
||||
"""Return percentage values in correct range."""
|
||||
value: int | None = entity.coordinator.current.get(key) # type: ignore[assignment]
|
||||
if value is not None and 0 <= value <= 100:
|
||||
return value
|
||||
if value is not None:
|
||||
return 0
|
||||
return None
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class SMHISensorEntityDescription(SensorEntityDescription):
|
||||
"""Describes SMHI sensor entity."""
|
||||
|
||||
value_fn: Callable[[SMHISensor], StateType | datetime]
|
||||
|
||||
|
||||
SENSOR_DESCRIPTIONS: tuple[SMHISensorEntityDescription, ...] = (
|
||||
SMHISensorEntityDescription(
|
||||
key="thunder",
|
||||
translation_key="thunder",
|
||||
value_fn=lambda entity: get_percentage_values(entity, "thunder"),
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
SMHISensorEntityDescription(
|
||||
key="total_cloud",
|
||||
translation_key="total_cloud",
|
||||
value_fn=lambda entity: get_percentage_values(entity, "total_cloud"),
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SMHISensorEntityDescription(
|
||||
key="low_cloud",
|
||||
translation_key="low_cloud",
|
||||
value_fn=lambda entity: get_percentage_values(entity, "low_cloud"),
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SMHISensorEntityDescription(
|
||||
key="medium_cloud",
|
||||
translation_key="medium_cloud",
|
||||
value_fn=lambda entity: get_percentage_values(entity, "medium_cloud"),
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SMHISensorEntityDescription(
|
||||
key="high_cloud",
|
||||
translation_key="high_cloud",
|
||||
value_fn=lambda entity: get_percentage_values(entity, "high_cloud"),
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SMHISensorEntityDescription(
|
||||
key="precipitation_category",
|
||||
translation_key="precipitation_category",
|
||||
value_fn=lambda entity: str(
|
||||
get_percentage_values(entity, "precipitation_category")
|
||||
),
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=["0", "1", "2", "3", "4", "5", "6"],
|
||||
),
|
||||
SMHISensorEntityDescription(
|
||||
key="frozen_precipitation",
|
||||
translation_key="frozen_precipitation",
|
||||
value_fn=lambda entity: get_percentage_values(entity, "frozen_precipitation"),
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: SMHIConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up SMHI sensor platform."""
|
||||
|
||||
coordinator = entry.runtime_data
|
||||
location = entry.data
|
||||
async_add_entities(
|
||||
SMHISensor(
|
||||
location[CONF_LOCATION][CONF_LATITUDE],
|
||||
location[CONF_LOCATION][CONF_LONGITUDE],
|
||||
coordinator=coordinator,
|
||||
entity_description=description,
|
||||
)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
)
|
||||
|
||||
|
||||
class SMHISensor(SmhiWeatherBaseEntity, SensorEntity):
|
||||
"""Representation of a SMHI Sensor."""
|
||||
|
||||
entity_description: SMHISensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
latitude: str,
|
||||
longitude: str,
|
||||
coordinator: SMHIDataUpdateCoordinator,
|
||||
entity_description: SMHISensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initiate SMHI Sensor."""
|
||||
self.entity_description = entity_description
|
||||
super().__init__(
|
||||
latitude,
|
||||
longitude,
|
||||
coordinator,
|
||||
)
|
||||
self._attr_unique_id = f"{latitude}, {longitude}-{entity_description.key}"
|
||||
|
||||
def update_entity_data(self) -> None:
|
||||
"""Refresh the entity data."""
|
||||
if self.coordinator.data.daily:
|
||||
self._attr_native_value = self.entity_description.value_fn(self)
|
@ -23,5 +23,39 @@
|
||||
"error": {
|
||||
"wrong_location": "Location Sweden only"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"thunder": {
|
||||
"name": "Thunder probability"
|
||||
},
|
||||
"total_cloud": {
|
||||
"name": "Total cloud coverage"
|
||||
},
|
||||
"low_cloud": {
|
||||
"name": "Low cloud coverage"
|
||||
},
|
||||
"medium_cloud": {
|
||||
"name": "Medium cloud coverage"
|
||||
},
|
||||
"high_cloud": {
|
||||
"name": "High cloud coverage"
|
||||
},
|
||||
"precipitation_category": {
|
||||
"name": "Precipitation category",
|
||||
"state": {
|
||||
"0": "No precipitation",
|
||||
"1": "Snow",
|
||||
"2": "Snow and rain",
|
||||
"3": "Rain",
|
||||
"4": "Drizzle",
|
||||
"5": "Freezing rain",
|
||||
"6": "Freezing drizzle"
|
||||
}
|
||||
},
|
||||
"frozen_precipitation": {
|
||||
"name": "Frozen precipitation"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ class SmhiWeather(SmhiWeatherBaseEntity, SingleCoordinatorWeatherEntity):
|
||||
_attr_supported_features = (
|
||||
WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
|
||||
)
|
||||
_attr_name = None
|
||||
|
||||
def update_entity_data(self) -> None:
|
||||
"""Refresh the entity data."""
|
||||
|
370
tests/components/smhi/snapshots/test_sensor.ambr
Normal file
370
tests/components/smhi/snapshots/test_sensor.ambr
Normal file
@ -0,0 +1,370 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_frozen_precipitation-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_frozen_precipitation',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Frozen precipitation',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'frozen_precipitation',
|
||||
'unique_id': '59.32624, 17.84197-frozen_precipitation',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_frozen_precipitation-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'friendly_name': 'Test Frozen precipitation',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_frozen_precipitation',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_high_cloud_coverage-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_high_cloud_coverage',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'High cloud coverage',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'high_cloud',
|
||||
'unique_id': '59.32624, 17.84197-high_cloud',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_high_cloud_coverage-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'friendly_name': 'Test High cloud coverage',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_high_cloud_coverage',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '88',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_low_cloud_coverage-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_low_cloud_coverage',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Low cloud coverage',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'low_cloud',
|
||||
'unique_id': '59.32624, 17.84197-low_cloud',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_low_cloud_coverage-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'friendly_name': 'Test Low cloud coverage',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_low_cloud_coverage',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '100',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_medium_cloud_coverage-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_medium_cloud_coverage',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Medium cloud coverage',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'medium_cloud',
|
||||
'unique_id': '59.32624, 17.84197-medium_cloud',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_medium_cloud_coverage-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'friendly_name': 'Test Medium cloud coverage',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_medium_cloud_coverage',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '88',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_precipitation_category-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'options': list([
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_precipitation_category',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Precipitation category',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'precipitation_category',
|
||||
'unique_id': '59.32624, 17.84197-precipitation_category',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_precipitation_category-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'device_class': 'enum',
|
||||
'friendly_name': 'Test Precipitation category',
|
||||
'options': list([
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_precipitation_category',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_thunder_probability-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_thunder_probability',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Thunder probability',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'thunder',
|
||||
'unique_id': '59.32624, 17.84197-thunder',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_thunder_probability-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'friendly_name': 'Test Thunder probability',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_thunder_probability',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '37',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_total_cloud_coverage-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.test_total_cloud_coverage',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Total cloud coverage',
|
||||
'platform': 'smhi',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'total_cloud',
|
||||
'unique_id': '59.32624, 17.84197-total_cloud',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_setup[load_platforms0][sensor.test_total_cloud_coverage-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Swedish weather institute (SMHI)',
|
||||
'friendly_name': 'Test Total cloud coverage',
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.test_total_cloud_coverage',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '100',
|
||||
})
|
||||
# ---
|
26
tests/components/smhi/test_sensor.py
Normal file
26
tests/components/smhi/test_sensor.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""Test for the smhi weather entity."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
@pytest.mark.parametrize(
|
||||
"load_platforms",
|
||||
[[Platform.SENSOR]],
|
||||
)
|
||||
async def test_sensor_setup(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: EntityRegistry,
|
||||
load_int: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test for successfully setting up the smhi sensors."""
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
|
Loading…
x
Reference in New Issue
Block a user