mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Update ordering (#3149)
This commit is contained in:
parent
6ae4e5cb6c
commit
795121d5a8
@ -6,20 +6,28 @@ https://home-assistant.io/components/sensor.forecast/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from requests.exceptions import ConnectionError as ConnectError, \
|
from requests.exceptions import ConnectionError as ConnectError, \
|
||||||
HTTPError, Timeout
|
HTTPError, Timeout
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (CONF_API_KEY, CONF_NAME,
|
from homeassistant.const import (
|
||||||
CONF_MONITORED_CONDITIONS)
|
CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['python-forecastio==1.3.4']
|
REQUIREMENTS = ['python-forecastio==1.3.4']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_UNITS = 'units'
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'Forecast.io'
|
||||||
|
|
||||||
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||||
|
|
||||||
# Sensor types are defined like so:
|
# Sensor types are defined like so:
|
||||||
# Name, si unit, us unit, ca unit, uk unit, uk2 unit
|
# Name, si unit, us unit, ca unit, uk unit, uk2 unit
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
@ -57,22 +65,16 @@ SENSOR_TYPES = {
|
|||||||
'precip_intensity_max': ['Daily Max Precip Intensity',
|
'precip_intensity_max': ['Daily Max Precip Intensity',
|
||||||
'mm', 'in', 'mm', 'mm', 'mm'],
|
'mm', 'in', 'mm', 'mm', 'mm'],
|
||||||
}
|
}
|
||||||
DEFAULT_NAME = "Forecast.io"
|
|
||||||
CONF_UNITS = 'units'
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_MONITORED_CONDITIONS):
|
vol.Required(CONF_MONITORED_CONDITIONS):
|
||||||
vol.All(cv.ensure_list, [vol.In(list(SENSOR_TYPES))]),
|
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
vol.Optional(CONF_UNITS): vol.In(['auto', 'si', 'us', 'ca', 'uk', 'uk2'])
|
vol.Optional(CONF_UNITS): vol.In(['auto', 'si', 'us', 'ca', 'uk', 'uk2'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago.
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Forecast.io sensor."""
|
"""Setup the Forecast.io sensor."""
|
||||||
# Validate the configuration
|
# Validate the configuration
|
||||||
@ -100,7 +102,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
# Initialize and add all of the sensors.
|
|
||||||
sensors = []
|
sensors = []
|
||||||
for variable in config[CONF_MONITORED_CONDITIONS]:
|
for variable in config[CONF_MONITORED_CONDITIONS]:
|
||||||
sensors.append(ForeCastSensor(forecast_data, variable, name))
|
sensors.append(ForeCastSensor(forecast_data, variable, name))
|
||||||
@ -249,10 +250,8 @@ class ForeCastData(object):
|
|||||||
import forecastio
|
import forecastio
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.data = forecastio.load_forecast(self._api_key,
|
self.data = forecastio.load_forecast(
|
||||||
self.latitude,
|
self._api_key, self.latitude, self.longitude, units=self.units)
|
||||||
self.longitude,
|
|
||||||
units=self.units)
|
|
||||||
except (ConnectError, HTTPError, Timeout, ValueError) as error:
|
except (ConnectError, HTTPError, Timeout, ValueError) as error:
|
||||||
raise ValueError("Unable to init Forecast.io. - %s", error)
|
raise ValueError("Unable to init Forecast.io. - %s", error)
|
||||||
self.unit_system = self.data.json['flags']['units']
|
self.unit_system = self.data.json['flags']['units']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user