99import voluptuous as vol
1010from dateutil import parser
1111from homeassistant .components .sensor import PLATFORM_SCHEMA , SensorEntity
12- from homeassistant .const import CONF_NAME
13- import homeassistant .util .dt as dt
12+ from homeassistant .const import CONF_NAME , CONF_SCAN_INTERVAL
13+ from homeassistant .core import HomeAssistant
14+ from homeassistant .helpers .entity_platform import AddEntitiesCallback
15+ from homeassistant .helpers .typing import ConfigType , DiscoveryInfoType
1416
1517import feedparser
1618
17- __version__ = "0.1.7"
19+ __version__ = "0.1.6"
20+
21+ COMPONENT_REPO = "https://github.com/custom-components/sensor.feedparser/"
1822
1923REQUIREMENTS = ["feedparser" ]
2024
2327CONF_INCLUSIONS = "inclusions"
2428CONF_EXCLUSIONS = "exclusions"
2529CONF_SHOW_TOPN = "show_topn"
26- CONF_LOCAL_TIME = 'local_time'
2730
2831DEFAULT_SCAN_INTERVAL = timedelta (hours = 1 )
2932
30- COMPONENT_REPO = "https://github.com/custom-components/sensor.feedparser/"
31- SCAN_INTERVAL = timedelta (hours = 1 )
32-
3333PLATFORM_SCHEMA = PLATFORM_SCHEMA .extend (
3434 {
3535 vol .Required (CONF_NAME ): cv .string ,
3838 vol .Optional (CONF_SHOW_TOPN , default = 9999 ): cv .positive_int ,
3939 vol .Optional (CONF_INCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
4040 vol .Optional (CONF_EXCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
41- vol .Optional (CONF_LOCAL_TIME , default = False ): cv .boolean ,
41+ vol .Optional (CONF_SCAN_INTERVAL , default = DEFAULT_SCAN_INTERVAL ): cv .time_period ,
4242 }
4343)
4444
4545
4646@asyncio .coroutine
47- def async_setup_platform (hass , config , async_add_devices , discovery_info = None ):
47+ def async_setup_platform (
48+ hass : HomeAssistant ,
49+ config : ConfigType ,
50+ async_add_devices : AddEntitiesCallback ,
51+ discovery_info : DiscoveryInfoType | None = None ,
52+ ) -> None :
4853 async_add_devices (
4954 [
5055 FeedParserSensor (
5156 feed = config [CONF_FEED_URL ],
5257 name = config [CONF_NAME ],
5358 date_format = config [CONF_DATE_FORMAT ],
54- local_time = config [CONF_LOCAL_TIME ],
5559 show_topn = config [CONF_SHOW_TOPN ],
5660 inclusions = config [CONF_INCLUSIONS ],
5761 exclusions = config [CONF_EXCLUSIONS ],
62+ scan_interval = config [CONF_SCAN_INTERVAL ],
5863 )
5964 ],
6065 True ,
@@ -68,20 +73,21 @@ def __init__(
6873 name : str ,
6974 date_format : str ,
7075 show_topn : str ,
71- local_time : bool ,
7276 exclusions : str ,
7377 inclusions : str ,
78+ scan_interval : int ,
7479 ) -> None :
7580 self ._feed = feed
7681 self ._attr_name = name
7782 self ._attr_icon = "mdi:rss"
7883 self ._date_format = date_format
79- self ._local_time = local_time
8084 self ._show_topn = show_topn
8185 self ._inclusions = inclusions
8286 self ._exclusions = exclusions
87+ self ._scan_interval = scan_interval
8388 self ._attr_state = None
8489 self ._entries = []
90+ self ._attr_extra_state_attributes = {"entries" : self ._entries }
8591
8692 def update (self ):
8793 parsed_feed = feedparser .parse (self ._feed )
@@ -107,11 +113,7 @@ def update(self):
107113 ):
108114 continue
109115 if key in ["published" , "updated" , "created" , "expired" ]:
110- value = parser .parse (value )
111- if self ._local_time :
112- value = dt .as_local (value )
113- value = value .strftime (self ._date_format )
114-
116+ value = parser .parse (value ).strftime (self ._date_format )
115117
116118 entry_value [key ] = value
117119
@@ -129,7 +131,3 @@ def update(self):
129131 ] = "https://www.home-assistant.io/images/favicon-192x192-full.png"
130132
131133 self ._entries .append (entry_value )
132-
133- @property
134- def device_state_attributes (self ):
135- return {"entries" : self ._entries }
0 commit comments