platypush/platypush/backend/weather/forecast.py
Fabio Manganiello 284e0638f8 Always define msg so the function doesn't fail on exception
Reverted the previous retry logic for backend - it didn't really work

This reverts commit 4e0e4863a0.
This reverts commit 964c7b5cf0.
This reverts commit 6ce348365f.
2018-10-25 20:46:34 +02:00

47 lines
1.3 KiB
Python

import time
from platypush.backend import Backend
from platypush.context import get_plugin
from platypush.plugins.weather.forecast import WeatherForecastPlugin
from platypush.message.event.weather import NewWeatherConditionEvent
class WeatherForecastBackend(Backend):
"""
Weather forecast backend - listens and propagates new weather events.
Triggers:
* :class:`platypush.message.event.weather.NewWeatherConditionEvent` when there is a weather condition update
Requires:
* The :mod:`platypush.plugins.weather.forecast` plugin configured
"""
def __init__(self, poll_seconds, **kwargs):
super().__init__(**kwargs)
self.poll_seconds = poll_seconds
self.latest_update = {}
def send_message(self, msg):
pass
def run(self):
super().run()
weather = get_plugin('weather.forecast')
self.logger.info('Initialized weather forecast backend')
while not self.should_stop():
current_weather = weather.get_current_weather().output
del current_weather['time']
if current_weather != self.latest_update:
self.bus.post(NewWeatherConditionEvent(**current_weather))
self.latest_update = current_weather
time.sleep(self.poll_seconds)
# vim:sw=4:ts=4:et: