diff --git a/custom_components/pirateweather/__init__.py b/custom_components/pirateweather/__init__.py index 3c81687..1376aaf 100644 --- a/custom_components/pirateweather/__init__.py +++ b/custom_components/pirateweather/__init__.py @@ -61,7 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # _LOGGER.warning(forecast_days) if isinstance(forecast_days, str): # If empty, set to none - if forecast_days == "" or forecast_days == "None": + if forecast_days in {"", "None"}: forecast_days = None else: if forecast_days[0] == "[": @@ -72,7 +72,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if isinstance(forecast_hours, str): # If empty, set to none - if forecast_hours == "" or forecast_hours == "None": + if forecast_hours in {"", "None"}: forecast_hours = None else: if forecast_hours[0] == "[": diff --git a/custom_components/pirateweather/config_flow.py b/custom_components/pirateweather/config_flow.py index 5f563c4..9eeb51e 100644 --- a/custom_components/pirateweather/config_flow.py +++ b/custom_components/pirateweather/config_flow.py @@ -5,7 +5,6 @@ import aiohttp import homeassistant.helpers.config_validation as cv -from httpx import HTTPError import voluptuous as vol from homeassistant import config_entries from homeassistant.const import ( @@ -18,6 +17,7 @@ CONF_SCAN_INTERVAL, ) from homeassistant.core import callback +from httpx import HTTPError from .const import ( ALL_CONDITIONS, @@ -298,6 +298,4 @@ async def _is_pw_api_online(hass, api_key, lat, lon): aiohttp.ClientSession(raise_for_status=False) as session, session.get(forecastString) as resp, ): - status = resp.status - - return status + return resp.status diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index df835a3..9ea9628 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -882,7 +882,6 @@ def __init__( """Initialize the sensor.""" self.client_name = name - description = description self.entity_description = description self.description = description @@ -976,10 +975,9 @@ def extra_state_attributes(self): if self.type == "alerts": extraATTR = self._alerts extraATTR[ATTR_ATTRIBUTION] = ATTRIBUTION - - return extraATTR else: - return {ATTR_ATTRIBUTION: ATTRIBUTION} + extraATTR = {ATTR_ATTRIBUTION: ATTRIBUTION} + return extraATTR @property def native_value(self) -> StateType: @@ -1125,25 +1123,6 @@ def get_state(self, data): ]: state = state * 3.6 - if self.type in [ - "uv_index", - ]: - if state < 0 or state > 20: - _LOGGER.warning( - "UV Index is reporting %s which is outside the expected range! Setting UV Index to -1! Please report this issue to https://github.com/Pirate-Weather/pirateweather if not already reported.", - state, - ) - state = -1 - if self.type in [ - "cloud_cover", - ]: - if state > 100: - _LOGGER.warning( - "Cloud cover is reporting %s which is above 100%! Please report this issue to https://github.com/Pirate-Weather/pirateweather if not already reported.", - state, - ) - state = 100 - if self.type in [ "dew_point", "temperature", diff --git a/custom_components/pirateweather/weather_update_coordinator.py b/custom_components/pirateweather/weather_update_coordinator.py index dd563fd..0e6ecd4 100644 --- a/custom_components/pirateweather/weather_update_coordinator.py +++ b/custom_components/pirateweather/weather_update_coordinator.py @@ -2,6 +2,7 @@ import json import logging +from http.client import HTTPException import aiohttp import async_timeout @@ -43,13 +44,12 @@ async def _async_update_data(self): try: data = await self._get_pw_weather() _LOGGER.debug( - "Pirate Weather data update for " - + str(self.latitude) - + "," - + str(self.longitude) + "Pirate Weather data update for %s, %s", + str(self.latitude), + str(self.longitude), ) - except Exception as err: - raise UpdateFailed(f"Error communicating with API: {err}") + except HTTPException as err: + raise UpdateFailed(f"Error communicating with API: {err}") from err return data async def _get_pw_weather(self): @@ -76,5 +76,4 @@ async def _get_pw_weather(self): headers = resp.headers status = resp.raise_for_status() - data = Forecast(jsonText, status, headers) - return data + return Forecast(jsonText, status, headers)