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