mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move imports in openweathermap component (#27779)
This commit is contained in:
parent
7ec8384fa6
commit
5cb145f588
@ -2,6 +2,8 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pyowm import OWM
|
||||||
|
from pyowm.exceptions.api_call_error import APICallError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
@ -56,7 +58,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the OpenWeatherMap sensor."""
|
"""Set up the OpenWeatherMap sensor."""
|
||||||
from pyowm import OWM
|
|
||||||
|
|
||||||
if None in (hass.config.latitude, hass.config.longitude):
|
if None in (hass.config.latitude, hass.config.longitude):
|
||||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
||||||
@ -127,8 +128,6 @@ class OpenWeatherMapSensor(Entity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from OWM and updates the states."""
|
"""Get the latest data from OWM and updates the states."""
|
||||||
from pyowm.exceptions.api_call_error import APICallError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.owa_client.update()
|
self.owa_client.update()
|
||||||
except APICallError:
|
except APICallError:
|
||||||
@ -201,8 +200,6 @@ class WeatherData:
|
|||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from OpenWeatherMap."""
|
"""Get the latest data from OpenWeatherMap."""
|
||||||
from pyowm.exceptions.api_call_error import APICallError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
|
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
|
||||||
except (APICallError, TypeError):
|
except (APICallError, TypeError):
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pyowm import OWM
|
||||||
|
from pyowm.exceptions.api_call_error import APICallError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
@ -71,7 +73,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the OpenWeatherMap weather platform."""
|
"""Set up the OpenWeatherMap weather platform."""
|
||||||
import pyowm
|
|
||||||
|
|
||||||
longitude = config.get(CONF_LONGITUDE, round(hass.config.longitude, 5))
|
longitude = config.get(CONF_LONGITUDE, round(hass.config.longitude, 5))
|
||||||
latitude = config.get(CONF_LATITUDE, round(hass.config.latitude, 5))
|
latitude = config.get(CONF_LATITUDE, round(hass.config.latitude, 5))
|
||||||
@ -79,8 +80,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
mode = config.get(CONF_MODE)
|
mode = config.get(CONF_MODE)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
owm = pyowm.OWM(config.get(CONF_API_KEY))
|
owm = OWM(config.get(CONF_API_KEY))
|
||||||
except pyowm.exceptions.api_call_error.APICallError:
|
except APICallError:
|
||||||
_LOGGER.error("Error while connecting to OpenWeatherMap")
|
_LOGGER.error("Error while connecting to OpenWeatherMap")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -225,8 +226,6 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from OWM and updates the states."""
|
"""Get the latest data from OWM and updates the states."""
|
||||||
from pyowm.exceptions.api_call_error import APICallError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._owm.update()
|
self._owm.update()
|
||||||
self._owm.update_forecast()
|
self._owm.update_forecast()
|
||||||
@ -263,8 +262,6 @@ class WeatherData:
|
|||||||
@Throttle(MIN_TIME_BETWEEN_FORECAST_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_FORECAST_UPDATES)
|
||||||
def update_forecast(self):
|
def update_forecast(self):
|
||||||
"""Get the latest forecast from OpenWeatherMap."""
|
"""Get the latest forecast from OpenWeatherMap."""
|
||||||
from pyowm.exceptions.api_call_error import APICallError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self._mode == "daily":
|
if self._mode == "daily":
|
||||||
fcd = self.owm.daily_forecast_at_coords(
|
fcd = self.owm.daily_forecast_at_coords(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user