|
6 | 6 |
|
7 | 7 | Following spec from https://validator.w3.org/feed/docs/rss2.html |
8 | 8 | """ |
| 9 | +import asyncio |
9 | 10 | import re |
10 | 11 | import feedparser |
11 | 12 | import logging |
12 | 13 | import voluptuous as vol |
13 | 14 | from datetime import timedelta |
14 | 15 | from dateutil import parser |
15 | | -from time import strftime |
16 | | -from subprocess import check_output |
17 | 16 | from homeassistant.helpers.entity import Entity |
18 | 17 | import homeassistant.helpers.config_validation as cv |
19 | 18 | from homeassistant.components.sensor import (PLATFORM_SCHEMA) |
|
45 | 44 | vol.Optional(CONF_EXCLUSIONS, default=[]): vol.All(cv.ensure_list, [cv.string]), |
46 | 45 | }) |
47 | 46 |
|
48 | | -def setup_platform(hass, config, add_devices, discovery_info=None): |
49 | | - add_devices([FeedParserSensor(hass, config)]) |
| 47 | + |
| 48 | +@asyncio.coroutine |
| 49 | +def async_setup_platform(hass, config, async_add_devices, discovery_info=None): |
| 50 | + async_add_devices([FeedParserSensor( |
| 51 | + feed=config[CONF_FEED_URL], |
| 52 | + name=config[CONF_NAME], |
| 53 | + date_format=config[CONF_DATE_FORMAT], |
| 54 | + show_topn=config[CONF_SHOW_TOPN], |
| 55 | + inclusions=config[CONF_INCLUSIONS], |
| 56 | + exclusions=config[CONF_EXCLUSIONS] |
| 57 | + )], True) |
| 58 | + |
50 | 59 |
|
51 | 60 | class FeedParserSensor(Entity): |
52 | | - def __init__(self, hass, config): |
53 | | - self.hass = hass |
54 | | - self._feed = config[CONF_FEED_URL] |
55 | | - self._name = config[CONF_NAME] |
56 | | - self._date_format = config[CONF_DATE_FORMAT] |
57 | | - self._show_topn = config[CONF_SHOW_TOPN] |
58 | | - self._inclusions = config[CONF_INCLUSIONS] |
59 | | - self._exclusions = config[CONF_EXCLUSIONS] |
| 61 | + def __init__(self, feed: str, name: str, date_format: str, show_topn: str, exclusions: str, inclusions:str): |
| 62 | + self._feed = feed |
| 63 | + self._name = name |
| 64 | + self._date_format = date_format |
| 65 | + self._show_topn = show_topn |
| 66 | + self._inclusions = inclusions |
| 67 | + self._exclusions = exclusions |
60 | 68 | self._state = None |
61 | 69 | self._entries = [] |
62 | | - self.update() |
63 | 70 |
|
64 | 71 | def update(self): |
65 | 72 | parsedFeed = feedparser.parse(self._feed) |
|
0 commit comments