-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add a new weather integration - Met Éireann #39429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9f1847a
Added a new weather integration - Met Éireann
DylanGore 7b5dfca
Fix codespell error
DylanGore 4360776
Update met_eireann to use CoordinatorEntity
DylanGore 2b0d85e
Remove deprecated platform setup
DylanGore 8343d16
Fix merge conflict
DylanGore f18999a
Remove unnecessary onboarding/home tracking code
DylanGore 86e207c
Use common strings for config flow
DylanGore 5e9602f
Remove unnecessary code
DylanGore 385a093
Switch to using unique IDs in config flow
DylanGore a4b90f8
Use constants where possible
DylanGore f2f5e0d
Fix failing tests
DylanGore b5a0b38
Fix isort errors
DylanGore c872ec8
Remove unnecessary DataUpdateCoordinator class
DylanGore 0509fd6
Add device info
DylanGore a91b24d
Explicitly define forecast data
DylanGore 9f11d0a
Disable hourly forecast entity by default
DylanGore d4946a2
Update config flow to reflect requested changes
DylanGore 42e6818
Cleanup code
DylanGore bade202
Update entity naming to match other similar components
DylanGore 76fd2b8
Convert forecast time to UTC
DylanGore a485fa7
Fix test coverage
DylanGore 979cc40
Update test coverage
DylanGore 0691ec4
Remove elevation conversion
DylanGore 042bf58
Update translations for additional clarity
DylanGore 350c1b3
Remove en-GB translation
DylanGore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """The met_eireann component.""" | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| import meteireann | ||
|
|
||
| from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE | ||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
| from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed | ||
| import homeassistant.util.dt as dt_util | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| UPDATE_INTERVAL = timedelta(minutes=60) | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, config_entry): | ||
| """Set up Met Éireann as config entry.""" | ||
| hass.data.setdefault(DOMAIN, {}) | ||
|
|
||
| raw_weather_data = meteireann.WeatherData( | ||
| async_get_clientsession(hass), | ||
| latitude=config_entry.data[CONF_LATITUDE], | ||
| longitude=config_entry.data[CONF_LONGITUDE], | ||
| altitude=config_entry.data[CONF_ELEVATION], | ||
| ) | ||
|
|
||
| weather_data = MetEireannWeatherData(hass, config_entry.data, raw_weather_data) | ||
|
|
||
| async def _async_update_data(): | ||
| """Fetch data from Met Éireann.""" | ||
| try: | ||
| return await weather_data.fetch_data() | ||
| except Exception as err: | ||
| raise UpdateFailed(f"Update failed: {err}") from err | ||
|
|
||
| coordinator = DataUpdateCoordinator( | ||
| hass, | ||
| _LOGGER, | ||
| name=DOMAIN, | ||
| update_method=_async_update_data, | ||
| update_interval=UPDATE_INTERVAL, | ||
| ) | ||
| await coordinator.async_refresh() | ||
|
|
||
| hass.data[DOMAIN][config_entry.entry_id] = coordinator | ||
|
|
||
| hass.async_create_task( | ||
| hass.config_entries.async_forward_entry_setup(config_entry, "weather") | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass, config_entry): | ||
| """Unload a config entry.""" | ||
| await hass.config_entries.async_forward_entry_unload(config_entry, "weather") | ||
| hass.data[DOMAIN].pop(config_entry.entry_id) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| class MetEireannWeatherData: | ||
| """Keep data for Met Éireann weather entities.""" | ||
|
|
||
| def __init__(self, hass, config, weather_data): | ||
| """Initialise the weather entity data.""" | ||
| self.hass = hass | ||
| self._config = config | ||
| self._weather_data = weather_data | ||
| self.current_weather_data = {} | ||
| self.daily_forecast = None | ||
| self.hourly_forecast = None | ||
|
|
||
| async def fetch_data(self): | ||
| """Fetch data from API - (current weather and forecast).""" | ||
| await self._weather_data.fetching_data() | ||
| self.current_weather_data = self._weather_data.get_current_weather() | ||
| time_zone = dt_util.DEFAULT_TIME_ZONE | ||
| self.daily_forecast = self._weather_data.get_forecast(time_zone, False) | ||
| self.hourly_forecast = self._weather_data.get_forecast(time_zone, True) | ||
| return self | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Config flow to configure Met Éireann component.""" | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant import config_entries | ||
| from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| # pylint:disable=unused-import | ||
| from .const import DOMAIN, HOME_LOCATION_NAME | ||
|
|
||
|
|
||
| class MetEireannFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
| """Config flow for Met Eireann component.""" | ||
|
|
||
| VERSION = 1 | ||
| CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL | ||
|
|
||
| async def async_step_user(self, user_input=None): | ||
| """Handle a flow initialized by the user.""" | ||
| errors = {} | ||
|
|
||
| if user_input is not None: | ||
| # Check if an identical entity is already configured | ||
| await self.async_set_unique_id( | ||
| f"{user_input.get(CONF_LATITUDE)},{user_input.get(CONF_LONGITUDE)}" | ||
| ) | ||
| self._abort_if_unique_id_configured() | ||
| else: | ||
| return self.async_show_form( | ||
| step_id="user", | ||
| data_schema=vol.Schema( | ||
| { | ||
| vol.Required(CONF_NAME, default=HOME_LOCATION_NAME): str, | ||
| vol.Required( | ||
| CONF_LATITUDE, default=self.hass.config.latitude | ||
| ): cv.latitude, | ||
| vol.Required( | ||
| CONF_LONGITUDE, default=self.hass.config.longitude | ||
| ): cv.longitude, | ||
| vol.Required( | ||
| CONF_ELEVATION, default=self.hass.config.elevation | ||
| ): int, | ||
| } | ||
| ), | ||
| errors=errors, | ||
| ) | ||
| return self.async_create_entry(title=user_input[CONF_NAME], data=user_input) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| """Constants for Met Éireann component.""" | ||
| import logging | ||
|
|
||
| from homeassistant.components.weather import ( | ||
| ATTR_CONDITION_CLEAR_NIGHT, | ||
| ATTR_CONDITION_CLOUDY, | ||
| ATTR_CONDITION_FOG, | ||
| ATTR_CONDITION_LIGHTNING_RAINY, | ||
| ATTR_CONDITION_PARTLYCLOUDY, | ||
| ATTR_CONDITION_RAINY, | ||
| ATTR_CONDITION_SNOWY, | ||
| ATTR_CONDITION_SNOWY_RAINY, | ||
| ATTR_CONDITION_SUNNY, | ||
| ATTR_FORECAST_CONDITION, | ||
| ATTR_FORECAST_PRECIPITATION, | ||
| ATTR_FORECAST_PRESSURE, | ||
| ATTR_FORECAST_TEMP, | ||
| ATTR_FORECAST_TEMP_LOW, | ||
| ATTR_FORECAST_TIME, | ||
| ATTR_FORECAST_WIND_BEARING, | ||
| ATTR_FORECAST_WIND_SPEED, | ||
| DOMAIN as WEATHER_DOMAIN, | ||
| ) | ||
|
|
||
| ATTRIBUTION = "Data provided by Met Éireann" | ||
|
|
||
| DEFAULT_NAME = "Met Éireann" | ||
|
|
||
| DOMAIN = "met_eireann" | ||
|
|
||
| HOME_LOCATION_NAME = "Home" | ||
|
|
||
| ENTITY_ID_SENSOR_FORMAT_HOME = f"{WEATHER_DOMAIN}.met_eireann_{HOME_LOCATION_NAME}" | ||
|
|
||
| _LOGGER = logging.getLogger(".") | ||
|
|
||
| FORECAST_MAP = { | ||
| ATTR_FORECAST_CONDITION: "condition", | ||
| ATTR_FORECAST_PRESSURE: "pressure", | ||
| ATTR_FORECAST_PRECIPITATION: "precipitation", | ||
| ATTR_FORECAST_TEMP: "temperature", | ||
| ATTR_FORECAST_TEMP_LOW: "templow", | ||
| ATTR_FORECAST_TIME: "datetime", | ||
| ATTR_FORECAST_WIND_BEARING: "wind_bearing", | ||
| ATTR_FORECAST_WIND_SPEED: "wind_speed", | ||
| } | ||
|
|
||
| CONDITION_MAP = { | ||
| ATTR_CONDITION_CLEAR_NIGHT: ["Dark_Sun"], | ||
| ATTR_CONDITION_CLOUDY: ["Cloud"], | ||
| ATTR_CONDITION_FOG: ["Fog"], | ||
| ATTR_CONDITION_LIGHTNING_RAINY: [ | ||
| "LightRainThunderSun", | ||
| "LightRainThunderSun", | ||
| "RainThunder", | ||
| "SnowThunder", | ||
| "SleetSunThunder", | ||
| "Dark_SleetSunThunder", | ||
| "SnowSunThunder", | ||
| "Dark_SnowSunThunder", | ||
| "LightRainThunder", | ||
| "SleetThunder", | ||
| "DrizzleThunderSun", | ||
| "Dark_DrizzleThunderSun", | ||
| "RainThunderSun", | ||
| "Dark_RainThunderSun", | ||
| "LightSleetThunderSun", | ||
| "Dark_LightSleetThunderSun", | ||
| "HeavySleetThunderSun", | ||
| "Dark_HeavySleetThunderSun", | ||
| "LightSnowThunderSun", | ||
| "Dark_LightSnowThunderSun", | ||
| "HeavySnowThunderSun", | ||
| "Dark_HeavySnowThunderSun", | ||
| "DrizzleThunder", | ||
| "LightSleetThunder", | ||
| "HeavySleetThunder", | ||
| "LightSnowThunder", | ||
| "HeavySnowThunder", | ||
| ], | ||
| ATTR_CONDITION_PARTLYCLOUDY: [ | ||
| "LightCloud", | ||
| "Dark_LightCloud", | ||
| "PartlyCloud", | ||
| "Dark_PartlyCloud", | ||
| ], | ||
| ATTR_CONDITION_RAINY: [ | ||
| "LightRainSun", | ||
| "Dark_LightRainSun", | ||
| "LightRain", | ||
| "Rain", | ||
| "DrizzleSun", | ||
| "Dark_DrizzleSun", | ||
| "RainSun", | ||
| "Dark_RainSun", | ||
| "Drizzle", | ||
| ], | ||
| ATTR_CONDITION_SNOWY: [ | ||
| "SnowSun", | ||
| "Dark_SnowSun", | ||
| "Snow", | ||
| "LightSnowSun", | ||
| "Dark_LightSnowSun", | ||
| "HeavySnowSun", | ||
| "Dark_HeavySnowSun", | ||
| "LightSnow", | ||
| "HeavySnow", | ||
| ], | ||
| ATTR_CONDITION_SNOWY_RAINY: [ | ||
| "SleetSun", | ||
| "Dark_SleetSun", | ||
| "Sleet", | ||
| "LightSleetSun", | ||
| "Dark_LightSleetSun", | ||
| "HeavySleetSun", | ||
| "Dark_HeavySleetSun", | ||
| "LightSleet", | ||
| "HeavySleet", | ||
| ], | ||
| ATTR_CONDITION_SUNNY: "Sun", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "domain": "met_eireann", | ||
| "name": "Met Éireann", | ||
| "config_flow": true, | ||
| "documentation": "https://www.home-assistant.io/integrations/met_eireann", | ||
| "requirements": ["pyMetEireann==0.2"], | ||
| "codeowners": ["@DylanGore"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "config": { | ||
| "step": { | ||
| "user": { | ||
| "title": "[%key:common::config_flow::data::location%]", | ||
| "description": "Enter your location to use weather data from the Met Éireann Public Weather Forecast API", | ||
| "data": { | ||
| "name": "[%key:common::config_flow::data::name%]", | ||
| "latitude": "[%key:common::config_flow::data::latitude%]", | ||
| "longitude": "[%key:common::config_flow::data::longitude%]", | ||
| "elevation": "[%key:common::config_flow::data::elevation%]" | ||
| } | ||
| } | ||
| }, | ||
| "error": { "already_configured": "[%key:common::config_flow::abort::already_configured_service%]" } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "config": { | ||
| "step": { | ||
| "user": { | ||
| "title": "Met Éireann", | ||
| "description": "Enter your location to use weather data from the Met Éireann Public Weather Forecast API", | ||
| "data": { | ||
| "name": "Name", | ||
| "latitude": "Latitude", | ||
| "longitude": "Longitude", | ||
| "elevation": "Elevation (in meters)" | ||
| } | ||
| } | ||
| }, | ||
| "error": { | ||
| "name_exists": "Location already exists" | ||
| }, | ||
| "abort": { | ||
| "already_configured": "Location is already configured", | ||
| "unknown": "Unexpected error" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.