mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
commit
b6b9da7e6e
@ -14,7 +14,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||||
from homeassistant.helpers.discovery import load_platform, discover
|
from homeassistant.helpers.discovery import load_platform, discover
|
||||||
|
|
||||||
REQUIREMENTS = ['netdisco==0.7.6']
|
REQUIREMENTS = ['netdisco==0.7.7']
|
||||||
|
|
||||||
DOMAIN = 'discovery'
|
DOMAIN = 'discovery'
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ from homeassistant.const import (
|
|||||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_ELEVATION, CONF_MONITORED_CONDITIONS,
|
CONF_LATITUDE, CONF_LONGITUDE, CONF_ELEVATION, CONF_MONITORED_CONDITIONS,
|
||||||
ATTR_ATTRIBUTION)
|
ATTR_ATTRIBUTION)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
from homeassistant.helpers.event import (
|
||||||
|
async_track_point_in_utc_time, async_track_utc_time_change)
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
|
||||||
@ -76,6 +77,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
yield from async_add_devices(dev)
|
yield from async_add_devices(dev)
|
||||||
|
|
||||||
weather = YrData(hass, coordinates, dev)
|
weather = YrData(hass, coordinates, dev)
|
||||||
|
# Update weather on the hour
|
||||||
|
async_track_utc_time_change(hass, weather.async_update, minute=0, second=0)
|
||||||
yield from weather.async_update()
|
yield from weather.async_update()
|
||||||
|
|
||||||
|
|
||||||
@ -139,40 +142,41 @@ class YrData(object):
|
|||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_update(self):
|
def async_update(self, *_):
|
||||||
"""Get the latest data from yr.no."""
|
"""Get the latest data from yr.no."""
|
||||||
def try_again(err: str):
|
def try_again(err: str):
|
||||||
"""Schedule again later."""
|
"""Retry in 15 minutes."""
|
||||||
_LOGGER.warning('Retrying in 15 minutes: %s', err)
|
_LOGGER.warning('Retrying in 15 minutes: %s', err)
|
||||||
|
self._nextrun = None
|
||||||
nxt = dt_util.utcnow() + timedelta(minutes=15)
|
nxt = dt_util.utcnow() + timedelta(minutes=15)
|
||||||
async_track_point_in_utc_time(self.hass, self.async_update, nxt)
|
if nxt.minute >= 15:
|
||||||
|
async_track_point_in_utc_time(self.hass, self.async_update,
|
||||||
|
nxt)
|
||||||
|
|
||||||
try:
|
if self._nextrun is None or dt_util.utcnow() >= self._nextrun:
|
||||||
with async_timeout.timeout(10, loop=self.hass.loop):
|
try:
|
||||||
resp = yield from self.hass.websession.get(self._url)
|
with async_timeout.timeout(10, loop=self.hass.loop):
|
||||||
if resp.status != 200:
|
resp = yield from self.hass.websession.get(self._url)
|
||||||
try_again('{} returned {}'.format(self._url, resp.status))
|
if resp.status != 200:
|
||||||
|
try_again('{} returned {}'.format(self._url, resp.status))
|
||||||
|
return
|
||||||
|
text = yield from resp.text()
|
||||||
|
self.hass.async_add_job(resp.release())
|
||||||
|
except (asyncio.TimeoutError, aiohttp.errors.ClientError,
|
||||||
|
aiohttp.errors.ClientDisconnectedError) as err:
|
||||||
|
try_again(err)
|
||||||
return
|
return
|
||||||
text = yield from resp.text()
|
|
||||||
self.hass.async_add_job(resp.release())
|
|
||||||
except (asyncio.TimeoutError, aiohttp.errors.ClientError,
|
|
||||||
aiohttp.errors.ClientDisconnectedError) as err:
|
|
||||||
try_again(err)
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import xmltodict
|
import xmltodict
|
||||||
self.data = xmltodict.parse(text)['weatherdata']
|
self.data = xmltodict.parse(text)['weatherdata']
|
||||||
model = self.data['meta']['model']
|
model = self.data['meta']['model']
|
||||||
if '@nextrun' not in model:
|
if '@nextrun' not in model:
|
||||||
model = model[0]
|
model = model[0]
|
||||||
next_run = dt_util.parse_datetime(model['@nextrun'])
|
self._nextrun = dt_util.parse_datetime(model['@nextrun'])
|
||||||
except (ExpatError, IndexError) as err:
|
except (ExpatError, IndexError) as err:
|
||||||
try_again(err)
|
try_again(err)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Schedule next execution
|
|
||||||
async_track_point_in_utc_time(self.hass, self.async_update, next_run)
|
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 33
|
MINOR_VERSION = 33
|
||||||
PATCH_VERSION = '2'
|
PATCH_VERSION = '3'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
REQUIRED_PYTHON_VER = (3, 4, 2)
|
REQUIRED_PYTHON_VER = (3, 4, 2)
|
||||||
|
@ -151,11 +151,10 @@ def async_load_platform(hass, component, platform, discovered=None,
|
|||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
"""
|
"""
|
||||||
did_lock = False
|
did_lock = False
|
||||||
if component not in hass.config.components:
|
setup_lock = hass.data.get('setup_lock')
|
||||||
setup_lock = hass.data.get('setup_lock')
|
if setup_lock and setup_lock.locked():
|
||||||
if setup_lock and setup_lock.locked():
|
did_lock = True
|
||||||
did_lock = True
|
yield from setup_lock.acquire()
|
||||||
yield from setup_lock.acquire()
|
|
||||||
|
|
||||||
setup_success = True
|
setup_success = True
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ mficlient==0.3.0
|
|||||||
miflora==0.1.12
|
miflora==0.1.12
|
||||||
|
|
||||||
# homeassistant.components.discovery
|
# homeassistant.components.discovery
|
||||||
netdisco==0.7.6
|
netdisco==0.7.7
|
||||||
|
|
||||||
# homeassistant.components.sensor.neurio_energy
|
# homeassistant.components.sensor.neurio_energy
|
||||||
neurio==0.2.10
|
neurio==0.2.10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user