add latitude and longitude configuration to darksky sensor (#6191)
* Optional latitude and longitude to darksky sensor allow configuration of latitude and longitude in the darksky sensor. falls back to home assistant coordinates if latitude/longitude not specified. * lat/long as inclusive on schema. removed None check for lat/long in setup_platorm altered schema to require latitude and longitude configured as a pair. removed None check on latitude and longitude since values will fall back to hass config if not present * adhere to line limit of 79 characters adhere to line limit of 79 characters
This commit is contained in:
parent
c8e1ffad89
commit
7050236a61
1 changed files with 11 additions and 7 deletions
|
@ -13,7 +13,8 @@ from requests.exceptions import ConnectionError as ConnectError, \
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION)
|
||||
CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION,
|
||||
CONF_LATITUDE, CONF_LONGITUDE)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -117,6 +118,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_UNITS): vol.In(['auto', 'si', 'us', 'ca', 'uk', 'uk2']),
|
||||
vol.Inclusive(CONF_LATITUDE, 'coordinates',
|
||||
'Latitude and longitude must exist together'): cv.latitude,
|
||||
vol.Inclusive(CONF_LONGITUDE, 'coordinates',
|
||||
'Latitude and longitude must exist together'): cv.longitude,
|
||||
vol.Optional(CONF_UPDATE_INTERVAL, default=timedelta(seconds=120)): (
|
||||
vol.All(cv.time_period, cv.positive_timedelta)),
|
||||
vol.Optional(CONF_FORECAST):
|
||||
|
@ -126,10 +131,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Dark Sky sensor."""
|
||||
# Validate the configuration
|
||||
if None in (hass.config.latitude, hass.config.longitude):
|
||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
||||
return False
|
||||
# latitude and longitude are inclusive on config
|
||||
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
||||
longitude = config.get(CONF_LONGITUDE, hass.config.latitude)
|
||||
|
||||
if CONF_UNITS in config:
|
||||
units = config[CONF_UNITS]
|
||||
|
@ -140,8 +144,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
forecast_data = DarkSkyData(
|
||||
api_key=config.get(CONF_API_KEY, None),
|
||||
latitude=hass.config.latitude,
|
||||
longitude=hass.config.longitude,
|
||||
latitude=latitude,
|
||||
longitude=longitude,
|
||||
units=units,
|
||||
interval=config.get(CONF_UPDATE_INTERVAL))
|
||||
forecast_data.update()
|
||||
|
|
Loading…
Add table
Reference in a new issue