mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
New api endpoint for Trafikverket Weather (#104165)
* New api endpoint for Trafikverket Weather * fix tests
This commit is contained in:
parent
0eb8daee23
commit
47cd368ed2
@ -6,5 +6,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_camera",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.8"]
|
||||
"requirements": ["pytrafikverket==0.3.9.1"]
|
||||
}
|
||||
|
@ -6,5 +6,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_ferry",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.8"]
|
||||
"requirements": ["pytrafikverket==0.3.9.1"]
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ from typing import Any
|
||||
from pytrafikverket import TrafikverketTrain
|
||||
from pytrafikverket.exceptions import (
|
||||
InvalidAuthentication,
|
||||
MultipleTrainAnnouncementFound,
|
||||
MultipleTrainStationsFound,
|
||||
NoTrainAnnouncementFound,
|
||||
NoTrainStationFound,
|
||||
@ -107,8 +106,6 @@ async def validate_input(
|
||||
errors["base"] = "more_stations"
|
||||
except NoTrainAnnouncementFound:
|
||||
errors["base"] = "no_trains"
|
||||
except MultipleTrainAnnouncementFound:
|
||||
errors["base"] = "multiple_trains"
|
||||
except UnknownError as error:
|
||||
_LOGGER.error("Unknown error occurred during validation %s", str(error))
|
||||
errors["base"] = "cannot_connect"
|
||||
|
@ -8,7 +8,6 @@ import logging
|
||||
from pytrafikverket import TrafikverketTrain
|
||||
from pytrafikverket.exceptions import (
|
||||
InvalidAuthentication,
|
||||
MultipleTrainAnnouncementFound,
|
||||
NoTrainAnnouncementFound,
|
||||
UnknownError,
|
||||
)
|
||||
@ -112,7 +111,6 @@ class TVDataUpdateCoordinator(DataUpdateCoordinator[TrainData]):
|
||||
raise ConfigEntryAuthFailed from error
|
||||
except (
|
||||
NoTrainAnnouncementFound,
|
||||
MultipleTrainAnnouncementFound,
|
||||
UnknownError,
|
||||
) as error:
|
||||
raise UpdateFailed(
|
||||
|
@ -6,5 +6,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_train",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.8"]
|
||||
"requirements": ["pytrafikverket==0.3.9.1"]
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
"invalid_station": "Could not find a station with the specified name",
|
||||
"more_stations": "Found multiple stations with the specified name",
|
||||
"no_trains": "No train found",
|
||||
"multiple_trains": "Multiple trains found",
|
||||
"incorrect_api_key": "Invalid API key for selected account"
|
||||
},
|
||||
"step": {
|
||||
|
@ -6,5 +6,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/trafikverket_weatherstation",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pytrafikverket"],
|
||||
"requirements": ["pytrafikverket==0.3.8"]
|
||||
"requirements": ["pytrafikverket==0.3.9.1"]
|
||||
}
|
||||
|
@ -24,48 +24,17 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.dt import as_utc
|
||||
|
||||
from .const import ATTRIBUTION, CONF_STATION, DOMAIN, NONE_IS_ZERO_SENSORS
|
||||
from .coordinator import TVDataUpdateCoordinator
|
||||
|
||||
WIND_DIRECTIONS = [
|
||||
"east",
|
||||
"north_east",
|
||||
"east_south_east",
|
||||
"north",
|
||||
"north_north_east",
|
||||
"north_north_west",
|
||||
"north_west",
|
||||
"south",
|
||||
"south_east",
|
||||
"south_south_west",
|
||||
"south_west",
|
||||
"west",
|
||||
]
|
||||
PRECIPITATION_AMOUNTNAME = [
|
||||
"error",
|
||||
"mild_rain",
|
||||
"moderate_rain",
|
||||
"heavy_rain",
|
||||
"mild_snow_rain",
|
||||
"moderate_snow_rain",
|
||||
"heavy_snow_rain",
|
||||
"mild_snow",
|
||||
"moderate_snow",
|
||||
"heavy_snow",
|
||||
"other",
|
||||
"none",
|
||||
"error",
|
||||
]
|
||||
PRECIPITATION_TYPE = [
|
||||
"drizzle",
|
||||
"hail",
|
||||
"none",
|
||||
"no",
|
||||
"rain",
|
||||
"snow",
|
||||
"rain_snow_mixed",
|
||||
"freezing_rain",
|
||||
"snow",
|
||||
"sleet",
|
||||
"yes",
|
||||
]
|
||||
|
||||
|
||||
@ -103,8 +72,7 @@ SENSOR_TYPES: tuple[TrafikverketSensorEntityDescription, ...] = (
|
||||
TrafikverketSensorEntityDescription(
|
||||
key="precipitation",
|
||||
translation_key="precipitation",
|
||||
api_key="precipitationtype_translated",
|
||||
name="Precipitation type",
|
||||
api_key="precipitationtype",
|
||||
icon="mdi:weather-snowy-rainy",
|
||||
entity_registry_enabled_default=False,
|
||||
options=PRECIPITATION_TYPE,
|
||||
@ -114,20 +82,10 @@ SENSOR_TYPES: tuple[TrafikverketSensorEntityDescription, ...] = (
|
||||
key="wind_direction",
|
||||
translation_key="wind_direction",
|
||||
api_key="winddirection",
|
||||
name="Wind direction",
|
||||
native_unit_of_measurement=DEGREE,
|
||||
icon="mdi:flag-triangle",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
TrafikverketSensorEntityDescription(
|
||||
key="wind_direction_text",
|
||||
translation_key="wind_direction_text",
|
||||
api_key="winddirectiontext_translated",
|
||||
name="Wind direction text",
|
||||
icon="mdi:flag-triangle",
|
||||
options=WIND_DIRECTIONS,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
),
|
||||
TrafikverketSensorEntityDescription(
|
||||
key="wind_speed",
|
||||
api_key="windforce",
|
||||
@ -160,15 +118,6 @@ SENSOR_TYPES: tuple[TrafikverketSensorEntityDescription, ...] = (
|
||||
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
TrafikverketSensorEntityDescription(
|
||||
key="precipitation_amountname",
|
||||
translation_key="precipitation_amountname",
|
||||
api_key="precipitation_amountname_translated",
|
||||
icon="mdi:weather-pouring",
|
||||
entity_registry_enabled_default=False,
|
||||
options=PRECIPITATION_AMOUNTNAME,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
),
|
||||
TrafikverketSensorEntityDescription(
|
||||
key="measure_time",
|
||||
translation_key="measure_time",
|
||||
@ -195,12 +144,6 @@ async def async_setup_entry(
|
||||
)
|
||||
|
||||
|
||||
def _to_datetime(measuretime: str) -> datetime:
|
||||
"""Return isoformatted utc time."""
|
||||
time_obj = datetime.strptime(measuretime, "%Y-%m-%dT%H:%M:%S.%f%z")
|
||||
return as_utc(time_obj)
|
||||
|
||||
|
||||
class TrafikverketWeatherStation(
|
||||
CoordinatorEntity[TVDataUpdateCoordinator], SensorEntity
|
||||
):
|
||||
@ -246,10 +189,3 @@ class TrafikverketWeatherStation(
|
||||
if state is None and self.entity_description.key in NONE_IS_ZERO_SENSORS:
|
||||
return 0
|
||||
return state
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if entity is available."""
|
||||
if TYPE_CHECKING:
|
||||
assert self.coordinator.data.active
|
||||
return self.coordinator.data.active and super().available
|
||||
|
@ -35,56 +35,20 @@
|
||||
"precipitation": {
|
||||
"name": "Precipitation type",
|
||||
"state": {
|
||||
"drizzle": "Drizzle",
|
||||
"hail": "Hail",
|
||||
"none": "None",
|
||||
"no": "No",
|
||||
"rain": "Rain",
|
||||
"freezing_rain": "Freezing rain",
|
||||
"snow": "Snow",
|
||||
"rain_snow_mixed": "Rain and snow mixed",
|
||||
"freezing_rain": "Freezing rain"
|
||||
"sleet": "Sleet",
|
||||
"yes": "Yes"
|
||||
}
|
||||
},
|
||||
"wind_direction": {
|
||||
"name": "Wind direction"
|
||||
},
|
||||
"wind_direction_text": {
|
||||
"name": "Wind direction text",
|
||||
"state": {
|
||||
"east": "East",
|
||||
"north_east": "North east",
|
||||
"east_south_east": "East-south east",
|
||||
"north": "North",
|
||||
"north_north_east": "North-north east",
|
||||
"north_north_west": "North-north west",
|
||||
"north_west": "North west",
|
||||
"south": "South",
|
||||
"south_east": "South east",
|
||||
"south_south_west": "South-south west",
|
||||
"south_west": "South west",
|
||||
"west": "West"
|
||||
}
|
||||
},
|
||||
"wind_speed_max": {
|
||||
"name": "Wind speed max"
|
||||
},
|
||||
"precipitation_amountname": {
|
||||
"name": "Precipitation name",
|
||||
"state": {
|
||||
"error": "Error",
|
||||
"mild_rain": "Mild rain",
|
||||
"moderate_rain": "Moderate rain",
|
||||
"heavy_rain": "Heavy rain",
|
||||
"mild_snow_rain": "Mild rain and snow mixed",
|
||||
"moderate_snow_rain": "Moderate rain and snow mixed",
|
||||
"heavy_snow_rain": "Heavy rain and snow mixed",
|
||||
"mild_snow": "Mild snow",
|
||||
"moderate_snow": "Moderate snow",
|
||||
"heavy_snow": "Heavy snow",
|
||||
"other": "Other",
|
||||
"none": "None",
|
||||
"unknown": "Unknown"
|
||||
}
|
||||
},
|
||||
"measure_time": {
|
||||
"name": "Measure time"
|
||||
}
|
||||
|
@ -2234,7 +2234,7 @@ pytradfri[async]==9.0.1
|
||||
# homeassistant.components.trafikverket_ferry
|
||||
# homeassistant.components.trafikverket_train
|
||||
# homeassistant.components.trafikverket_weatherstation
|
||||
pytrafikverket==0.3.8
|
||||
pytrafikverket==0.3.9.1
|
||||
|
||||
# homeassistant.components.v2c
|
||||
pytrydan==0.4.0
|
||||
|
@ -1664,7 +1664,7 @@ pytradfri[async]==9.0.1
|
||||
# homeassistant.components.trafikverket_ferry
|
||||
# homeassistant.components.trafikverket_train
|
||||
# homeassistant.components.trafikverket_weatherstation
|
||||
pytrafikverket==0.3.8
|
||||
pytrafikverket==0.3.9.1
|
||||
|
||||
# homeassistant.components.v2c
|
||||
pytrydan==0.4.0
|
||||
|
@ -6,7 +6,6 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
from pytrafikverket.exceptions import (
|
||||
InvalidAuthentication,
|
||||
MultipleTrainAnnouncementFound,
|
||||
MultipleTrainStationsFound,
|
||||
NoTrainAnnouncementFound,
|
||||
NoTrainStationFound,
|
||||
@ -177,10 +176,6 @@ async def test_flow_fails(
|
||||
NoTrainAnnouncementFound,
|
||||
"no_trains",
|
||||
),
|
||||
(
|
||||
MultipleTrainAnnouncementFound,
|
||||
"multiple_trains",
|
||||
),
|
||||
(
|
||||
UnknownError,
|
||||
"cannot_connect",
|
||||
@ -371,10 +366,6 @@ async def test_reauth_flow_error(
|
||||
NoTrainAnnouncementFound,
|
||||
"no_trains",
|
||||
),
|
||||
(
|
||||
MultipleTrainAnnouncementFound,
|
||||
"multiple_trains",
|
||||
),
|
||||
(
|
||||
UnknownError,
|
||||
"cannot_connect",
|
||||
|
Loading…
x
Reference in New Issue
Block a user