Skip to content
Merged
Show file tree
Hide file tree
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 Aug 30, 2020
7b5dfca
Fix codespell error
DylanGore Aug 30, 2020
4360776
Update met_eireann to use CoordinatorEntity
DylanGore Aug 30, 2020
2b0d85e
Remove deprecated platform setup
DylanGore Aug 31, 2020
8343d16
Fix merge conflict
DylanGore Sep 2, 2020
f18999a
Remove unnecessary onboarding/home tracking code
DylanGore Sep 8, 2020
86e207c
Use common strings for config flow
DylanGore Oct 1, 2020
5e9602f
Remove unnecessary code
DylanGore Feb 17, 2021
385a093
Switch to using unique IDs in config flow
DylanGore Feb 17, 2021
a4b90f8
Use constants where possible
DylanGore Feb 17, 2021
f2f5e0d
Fix failing tests
DylanGore Feb 17, 2021
b5a0b38
Fix isort errors
DylanGore Feb 17, 2021
c872ec8
Remove unnecessary DataUpdateCoordinator class
DylanGore Feb 17, 2021
0509fd6
Add device info
DylanGore Feb 17, 2021
a91b24d
Explicitly define forecast data
DylanGore Apr 5, 2021
9f11d0a
Disable hourly forecast entity by default
DylanGore Apr 5, 2021
d4946a2
Update config flow to reflect requested changes
DylanGore Apr 5, 2021
42e6818
Cleanup code
DylanGore Apr 5, 2021
bade202
Update entity naming to match other similar components
DylanGore Apr 5, 2021
76fd2b8
Convert forecast time to UTC
DylanGore Apr 5, 2021
a485fa7
Fix test coverage
DylanGore Apr 5, 2021
979cc40
Update test coverage
DylanGore Apr 5, 2021
0691ec4
Remove elevation conversion
DylanGore Apr 5, 2021
042bf58
Update translations for additional clarity
DylanGore Apr 5, 2021
350c1b3
Remove en-GB translation
DylanGore Apr 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ omit =
homeassistant/components/melcloud/water_heater.py
homeassistant/components/message_bird/notify.py
homeassistant/components/met/weather.py
homeassistant/components/met_eireann/__init__.py
homeassistant/components/met_eireann/weather.py
homeassistant/components/meteo_france/__init__.py
homeassistant/components/meteo_france/const.py
homeassistant/components/meteo_france/sensor.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ homeassistant/components/mediaroom/* @dgomes
homeassistant/components/melcloud/* @vilppuvuorinen
homeassistant/components/melissa/* @kennedyshead
homeassistant/components/met/* @danielhiversen @thimic
homeassistant/components/met_eireann/* @DylanGore
homeassistant/components/meteo_france/* @hacf-fr @oncleben31 @Quentame
homeassistant/components/meteoalarm/* @rolfberkenbosch
homeassistant/components/metoffice/* @MrHarcombe
Expand Down
84 changes: 84 additions & 0 deletions homeassistant/components/met_eireann/__init__.py
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, {})
Comment thread
DylanGore marked this conversation as resolved.
Outdated

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
48 changes: 48 additions & 0 deletions homeassistant/components/met_eireann/config_flow.py
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)
121 changes: 121 additions & 0 deletions homeassistant/components/met_eireann/const.py
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",
}
8 changes: 8 additions & 0 deletions homeassistant/components/met_eireann/manifest.json
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"]
}
17 changes: 17 additions & 0 deletions homeassistant/components/met_eireann/strings.json
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%]" }
}
}
23 changes: 23 additions & 0 deletions homeassistant/components/met_eireann/translations/en.json
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"
}
}
}
Loading