Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
fix lint
  • Loading branch information
wilds authored Oct 2, 2023
1 parent cb460fd commit 930a9e2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 53 deletions.
59 changes: 30 additions & 29 deletions custom_components/meteoam/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""The met component."""
from __future__ import annotations

from collections.abc import Callable
from datetime import datetime, timedelta
from dateutil.parser import parser
import logging
from collections.abc import Callable
from datetime import timedelta
from random import randrange
from types import MappingProxyType
from typing import Any, Self

from dateutil.parser import parser
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_LATITUDE,
Expand All @@ -31,7 +31,7 @@

# Dedicated Home Assistant endpoint - do not change!
URL = "https://api.meteoam.it/deda-meteograms/api/GetMeteogram/preset1/{lat},{lon}"
#URL = "https://api.meteoam.it/deda-meteograms/meteograms?request=GetMeteogram&layers=preset1&latlon={lat},{lon}"
# URL = "https://api.meteoam.it/deda-meteograms/meteograms?request=GetMeteogram&layers=preset1&latlon={lat},{lon}"

PLATFORMS = [Platform.WEATHER]

Expand All @@ -40,7 +40,7 @@

async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Set up MeteoAM as config entry."""
# Don't setup if tracking home location and latitude or longitude isn't set.
# Don"t setup if tracking home location and latitude or longitude isn"t set.
# Also, filters out our onboarding default location.
if config_entry.data.get(CONF_TRACK_HOME, False) and (
(not hass.config.latitude and not hass.config.longitude)
Expand Down Expand Up @@ -167,54 +167,55 @@ def set_coordinates(self) -> bool:

async def fetch_data(self) -> Self:
"""Fetch data from API - (current weather and forecast)."""
_LOGGER.warning(URL.format(
lat=self._coordinates["lat"],
lon=self._coordinates["lon"],
))
_LOGGER.debug(
URL.format(
lat=self._coordinates["lat"],
lon=self._coordinates["lon"],
)
)
resp = await self._weather_data.get(
URL.format(
lat=self._coordinates["lat"],
lon=self._coordinates["lon"],
), timeout=60
lat=self._coordinates["lat"],
lon=self._coordinates["lon"],
),
timeout=60,
)
if not resp or resp.status != 200:
raise CannotConnect()

try:
data = await resp.json()
self.daily_forecast = []
for tidx, t in enumerate(data['extrainfo']['stats']):
dt = parser().parse(t['localDate'])
for tidx, t in enumerate(data["extrainfo"]["stats"]):
dt = parser().parse(t["localDate"])
element = {
'localDateTime': dt,
'2t': t['maxCelsius'],
'2t_min': t['minCelsius'],
'2tf': t['maxFahrenheit'],
'2tf_min': t['minFahrenheit'],
'icon': t['icon']
"localDateTime": dt,
"2t": t["maxCelsius"],
"2t_min": t["minCelsius"],
"2tf": t["maxFahrenheit"],
"2tf_min": t["minFahrenheit"],
"icon": t["icon"],
}
self.daily_forecast.append(element)

hourly_forecast = []
timeseries_data = data['timeseries']
paramlist_data = data['paramlist']
timeseries_data = data["timeseries"]
paramlist_data = data["paramlist"]
for tidx, t in enumerate(timeseries_data):
dt = dt_util.as_local(parser().parse(t).replace(tzinfo=None))
now = dt_util.as_local(dt_util.utcnow())
element = {
'localDateTime': dt.isoformat()
}
element = {"localDateTime": dt.isoformat()}
for pidx, p in enumerate(paramlist_data):
element[p] = data['datasets']['0'][str(pidx)][str(tidx)]
element[p] = data["datasets"]["0"][str(pidx)][str(tidx)]
if dt >= now:
hourly_forecast.append(element)
if dt <= now:
self.current_weather_data = element
self.hourly_forecast = hourly_forecast

#_LOGGER.warning(self.current_weather_data)
#_LOGGER.warning(self.daily_forecast)
#_LOGGER.warning(self.hourly_forecast)
# _LOGGER.warning(self.current_weather_data)
# _LOGGER.warning(self.daily_forecast)
# _LOGGER.warning(self.hourly_forecast)

except Exception as exc:
_LOGGER.error(exc)
Expand Down
28 changes: 11 additions & 17 deletions custom_components/meteoam/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@

from typing import Any

import homeassistant.helpers.config_validation as cv
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import (
CONF_LATITUDE,
CONF_LONGITUDE,
CONF_NAME,
UnitOfLength,
)
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.selector import (
NumberSelector,
NumberSelectorConfig,
NumberSelectorMode,
)

from .const import (
CONF_TRACK_HOME,
Expand Down Expand Up @@ -54,16 +43,21 @@ def _get_data_schema(
{
vol.Required(CONF_NAME, default=HOME_LOCATION_NAME): str,
vol.Required(CONF_LATITUDE, default=hass.config.latitude): cv.latitude,
vol.Required(CONF_LONGITUDE, default=hass.config.longitude): cv.longitude,
vol.Required(
CONF_LONGITUDE, default=hass.config.longitude
): cv.longitude,
}
)
# Not tracking home, default values come from config entry
return vol.Schema(
{
vol.Required(CONF_NAME, default=config_entry.data.get(CONF_NAME)): str,
vol.Required(CONF_LATITUDE, default=config_entry.data.get(CONF_LATITUDE)): cv.latitude,
vol.Required(CONF_LONGITUDE, default=config_entry.data.get(CONF_LONGITUDE)): cv.longitude,

vol.Required(
CONF_LATITUDE, default=config_entry.data.get(CONF_LATITUDE)
): cv.latitude,
vol.Required(
CONF_LONGITUDE, default=config_entry.data.get(CONF_LONGITUDE)
): cv.longitude,
}
)

Expand Down
10 changes: 5 additions & 5 deletions custom_components/meteoam/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
ATTR_WEATHER_WIND_BEARING,
ATTR_WEATHER_WIND_GUST_SPEED,
ATTR_WEATHER_WIND_SPEED,
DOMAIN as WEATHER_DOMAIN,
)
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN

DOMAIN = "meteoam"

Expand All @@ -46,7 +46,7 @@

CONDITIONS_MAP = {
ATTR_CONDITION_SUNNY: {"01", "02"},
ATTR_CONDITION_PARTLYCLOUDY: { "04", "34", "35"},
ATTR_CONDITION_PARTLYCLOUDY: {"04", "34", "35"},
ATTR_CONDITION_CLEAR_NIGHT: {"31"},
ATTR_CONDITION_CLOUDY: {"05", "06", "07"},
ATTR_CONDITION_FOG: {"03", "13", "14", "32"},
Expand All @@ -55,9 +55,9 @@
ATTR_CONDITION_LIGHTNING_RAINY: {"10"},
ATTR_CONDITION_SNOWY_RAINY: {"11", "12"},
ATTR_CONDITION_SNOWY: {"16"},
#"17" #storm
#"18"
#"19" #sand storm
# "17" #storm
# "18"
# "19" #sand storm
}

FORECAST_MAP = {
Expand Down
5 changes: 3 additions & 2 deletions custom_components/meteoam/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from homeassistant.components.weather import (
ATTR_FORECAST_CONDITION,
ATTR_FORECAST_TIME,
ATTR_WEATHER_CLOUD_COVERAGE,
ATTR_WEATHER_DEW_POINT,
ATTR_WEATHER_HUMIDITY,
Expand All @@ -15,7 +14,9 @@
ATTR_WEATHER_WIND_BEARING,
ATTR_WEATHER_WIND_GUST_SPEED,
ATTR_WEATHER_WIND_SPEED,
DOMAIN as WEATHER_DOMAIN,
)
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
from homeassistant.components.weather import (
Forecast,
SingleCoordinatorWeatherEntity,
WeatherEntityFeature,
Expand Down

0 comments on commit 930a9e2

Please sign in to comment.