Bump Environment Canada library to 0.10.1 (#142882)
parent
658299ee21
commit
1a1c95af12
|
@ -35,7 +35,7 @@ async def validate_input(data):
|
|||
lon = weather_data.lon
|
||||
|
||||
return {
|
||||
CONF_TITLE: weather_data.metadata.get("location"),
|
||||
CONF_TITLE: weather_data.metadata.location,
|
||||
CONF_STATION: weather_data.station_id,
|
||||
CONF_LATITUDE: lat,
|
||||
CONF_LONGITUDE: lon,
|
||||
|
|
|
@ -7,7 +7,7 @@ from datetime import timedelta
|
|||
import logging
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from env_canada import ECAirQuality, ECRadar, ECWeather, ec_exc
|
||||
from env_canada import ECAirQuality, ECRadar, ECWeather, ECWeatherUpdateFailed, ec_exc
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -65,6 +65,6 @@ class ECDataUpdateCoordinator[DataT: ECDataType](DataUpdateCoordinator[DataT]):
|
|||
"""Fetch data from EC."""
|
||||
try:
|
||||
await self.ec_data.update()
|
||||
except (ET.ParseError, ec_exc.UnknownStationId) as ex:
|
||||
except (ET.ParseError, ECWeatherUpdateFailed, ec_exc.UnknownStationId) as ex:
|
||||
raise UpdateFailed(f"Error fetching {self.name} data: {ex}") from ex
|
||||
return self.ec_data
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/environment_canada",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["env_canada"],
|
||||
"requirements": ["env-canada==0.8.0"]
|
||||
"requirements": ["env-canada==0.10.1"]
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = (
|
|||
key="timestamp",
|
||||
translation_key="timestamp",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
value_fn=lambda data: data.metadata.get("timestamp"),
|
||||
value_fn=lambda data: data.metadata.timestamp,
|
||||
),
|
||||
ECSensorEntityDescription(
|
||||
key="uv_index",
|
||||
|
@ -289,7 +289,7 @@ class ECBaseSensorEntity[DataT: ECDataType](
|
|||
super().__init__(coordinator)
|
||||
self.entity_description = description
|
||||
self._ec_data = coordinator.ec_data
|
||||
self._attr_attribution = self._ec_data.metadata["attribution"]
|
||||
self._attr_attribution = self._ec_data.metadata.attribution
|
||||
self._attr_unique_id = f"{coordinator.config_entry.title}-{description.key}"
|
||||
self._attr_device_info = coordinator.device_info
|
||||
|
||||
|
@ -313,8 +313,8 @@ class ECSensorEntity[DataT: ECDataType](ECBaseSensorEntity[DataT]):
|
|||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, description)
|
||||
self._attr_extra_state_attributes = {
|
||||
ATTR_LOCATION: self._ec_data.metadata.get("location"),
|
||||
ATTR_STATION: self._ec_data.metadata.get("station"),
|
||||
ATTR_LOCATION: self._ec_data.metadata.location,
|
||||
ATTR_STATION: self._ec_data.metadata.station,
|
||||
}
|
||||
|
||||
|
||||
|
@ -329,8 +329,8 @@ class ECAlertSensorEntity(ECBaseSensorEntity[ECWeather]):
|
|||
return None
|
||||
|
||||
extra_state_attrs = {
|
||||
ATTR_LOCATION: self._ec_data.metadata.get("location"),
|
||||
ATTR_STATION: self._ec_data.metadata.get("station"),
|
||||
ATTR_LOCATION: self._ec_data.metadata.location,
|
||||
ATTR_STATION: self._ec_data.metadata.station,
|
||||
}
|
||||
for index, alert in enumerate(value, start=1):
|
||||
extra_state_attrs[f"alert_{index}"] = alert.get("title")
|
||||
|
|
|
@ -115,7 +115,7 @@ class ECWeatherEntity(
|
|||
"""Initialize Environment Canada weather."""
|
||||
super().__init__(coordinator)
|
||||
self.ec_data = coordinator.ec_data
|
||||
self._attr_attribution = self.ec_data.metadata["attribution"]
|
||||
self._attr_attribution = self.ec_data.metadata.attribution
|
||||
self._attr_translation_key = "forecast"
|
||||
self._attr_unique_id = _calculate_unique_id(
|
||||
coordinator.config_entry.unique_id, False
|
||||
|
|
|
@ -871,7 +871,7 @@ enocean==0.50
|
|||
enturclient==0.2.4
|
||||
|
||||
# homeassistant.components.environment_canada
|
||||
env-canada==0.8.0
|
||||
env-canada==0.10.1
|
||||
|
||||
# homeassistant.components.season
|
||||
ephem==4.1.6
|
||||
|
|
|
@ -741,7 +741,7 @@ energyzero==2.1.1
|
|||
enocean==0.50
|
||||
|
||||
# homeassistant.components.environment_canada
|
||||
env-canada==0.8.0
|
||||
env-canada==0.10.1
|
||||
|
||||
# homeassistant.components.season
|
||||
ephem==4.1.6
|
||||
|
|
|
@ -33,7 +33,7 @@ async def init_integration(hass: HomeAssistant, ec_data) -> MockConfigEntry:
|
|||
config_entry.add_to_hass(hass)
|
||||
|
||||
weather_mock = mock_ec()
|
||||
ec_data["metadata"]["timestamp"] = datetime(2022, 10, 4, tzinfo=UTC)
|
||||
ec_data["metadata"].timestamp = datetime(2022, 10, 4, tzinfo=UTC)
|
||||
weather_mock.conditions = ec_data["conditions"]
|
||||
weather_mock.alerts = ec_data["alerts"]
|
||||
weather_mock.daily_forecasts = ec_data["daily_forecasts"]
|
||||
|
|
|
@ -4,6 +4,7 @@ import contextlib
|
|||
from datetime import datetime
|
||||
import json
|
||||
|
||||
from env_canada.ec_weather import MetaData
|
||||
import pytest
|
||||
|
||||
from tests.common import load_fixture
|
||||
|
@ -13,7 +14,7 @@ from tests.common import load_fixture
|
|||
def ec_data():
|
||||
"""Load Environment Canada data."""
|
||||
|
||||
def date_hook(weather):
|
||||
def data_hook(weather):
|
||||
"""Convert timestamp string to datetime."""
|
||||
|
||||
if t := weather.get("timestamp"):
|
||||
|
@ -22,9 +23,11 @@ def ec_data():
|
|||
elif t := weather.get("period"):
|
||||
with contextlib.suppress(ValueError):
|
||||
weather["period"] = datetime.fromisoformat(t)
|
||||
if t := weather.get("metadata"):
|
||||
weather["metadata"] = MetaData(**t)
|
||||
return weather
|
||||
|
||||
return json.loads(
|
||||
load_fixture("environment_canada/current_conditions_data.json"),
|
||||
object_hook=date_hook,
|
||||
object_hook=data_hook,
|
||||
)
|
||||
|
|
|
@ -30,7 +30,7 @@ def mocked_ec():
|
|||
ec_mock.lat = FAKE_CONFIG[CONF_LATITUDE]
|
||||
ec_mock.lon = FAKE_CONFIG[CONF_LONGITUDE]
|
||||
ec_mock.language = FAKE_CONFIG[CONF_LANGUAGE]
|
||||
ec_mock.metadata = {"location": FAKE_TITLE}
|
||||
ec_mock.metadata.location = FAKE_TITLE
|
||||
|
||||
ec_mock.update = AsyncMock()
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Test Environment Canada diagnostics."""
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
@ -11,7 +10,6 @@ from homeassistant.core import HomeAssistant
|
|||
|
||||
from . import init_integration
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
@ -31,10 +29,6 @@ async def test_entry_diagnostics(
|
|||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
|
||||
ec_data = json.loads(
|
||||
load_fixture("environment_canada/current_conditions_data.json")
|
||||
)
|
||||
|
||||
config_entry = await init_integration(hass, ec_data)
|
||||
diagnostics = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
|
|
Loading…
Reference in New Issue