Merge pull request #1025 from molobrakos/yr-position

allow monitoring weather at other location than home
pull/960/merge
Paulus Schoutsen 2016-01-28 08:49:48 -08:00
commit 1de7dcdb5f
1 changed files with 13 additions and 8 deletions

View File

@ -10,7 +10,9 @@ import logging
import requests
from homeassistant.const import ATTR_ENTITY_PICTURE
from homeassistant.const import (ATTR_ENTITY_PICTURE,
CONF_LATITUDE,
CONF_LONGITUDE)
from homeassistant.helpers.entity import Entity
from homeassistant.util import location, dt as dt_util
@ -41,18 +43,21 @@ SENSOR_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Get the Yr.no sensor. """
if None in (hass.config.latitude, hass.config.longitude):
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
elevation = config.get('elevation')
if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False
elevation = config.get('elevation')
if elevation is None:
elevation = location.elevation(hass.config.latitude,
hass.config.longitude)
elevation = location.elevation(latitude,
longitude)
coordinates = dict(lat=hass.config.latitude,
lon=hass.config.longitude, msl=elevation)
coordinates = dict(lat=latitude,
lon=longitude,
msl=elevation)
weather = YrData(coordinates)