From 9e7886b909e95a0fe6fe2147d37b667de5311d94 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 28 Jan 2016 17:16:02 +0100 Subject: [PATCH] allow monitoring weather at other location than home (such as summer house) --- homeassistant/components/sensor/yr.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/sensor/yr.py b/homeassistant/components/sensor/yr.py index 66d334cb17d..5b0f55e1730 100644 --- a/homeassistant/components/sensor/yr.py +++ b/homeassistant/components/sensor/yr.py @@ -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)