77Following spec from https://validator.w3.org/feed/docs/rss2.html
88"""
99
10+ import feedparser
1011import logging
1112import voluptuous as vol
1213from datetime import timedelta
1617from homeassistant .helpers .entity import Entity
1718import homeassistant .helpers .config_validation as cv
1819from homeassistant .components .sensor import (PLATFORM_SCHEMA )
20+ from homeassistant .const import (CONF_NAME )
1921
2022__version__ = '0.0.6'
2123_LOGGER = logging .getLogger (__name__ )
2224
2325REQUIREMENTS = ['feedparser' ]
2426
25- CONF_NAME = 'name'
2627CONF_FEED_URL = 'feed_url'
2728CONF_DATE_FORMAT = 'date_format'
2829CONF_INCLUSIONS = 'inclusions'
@@ -54,35 +55,31 @@ def __init__(self, hass, config):
5455 self ._inclusions = config [CONF_INCLUSIONS ]
5556 self ._exclusions = config [CONF_EXCLUSIONS ]
5657 self ._state = None
57- self .hass . data [ self . _name ] = {}
58+ self ._entries = []
5859 self .update ()
5960
6061 def update (self ):
61- import feedparser
6262 parsedFeed = feedparser .parse (self ._feed )
6363
64- if not parsedFeed :
64+ if not parsedFeed :
6565 return False
6666 else :
6767 self ._state = len (parsedFeed .entries )
68- self .hass . data [ self . _name ] = {}
69-
68+ self ._entries = []
69+
7070 for entry in parsedFeed .entries :
71- title = entry ['title' ] if entry ['title' ] else entry ['description' ]
72-
73- if not title :
74- continue
75-
76- self .hass .data [self ._name ][title ] = {}
71+ entryValue = {}
7772
7873 for key , value in entry .items ():
79- if (self ._inclusions and key not in self ._inclusions ) or ('parsed' in key ) or (key in self ._exclusions ):
80- continue
74+ if (self ._inclusions and key not in self ._inclusions ) or ('parsed' in key ) or (key in self ._exclusions ):
75+ continue
76+
77+ if key in ['published' , 'updated' , 'created' , 'expired' ]:
78+ value = parser .parse (value ).strftime (self ._date_format )
8179
82- if key in ['published' , 'updated' , 'created' , 'expired' ]:
83- value = parser .parse (value ).strftime (self ._date_format )
80+ entryValue [key ] = value
8481
85- self .hass . data [ self . _name ][ title ][ key ] = value
82+ self ._entries . append ( entryValue )
8683
8784 @property
8885 def name (self ):
@@ -98,4 +95,6 @@ def icon(self):
9895
9996 @property
10097 def device_state_attributes (self ):
101- return self .hass .data [self ._name ]
98+ return {
99+ 'entries' : self ._entries
100+ }
0 commit comments