1313from homeassistant .core import HomeAssistant
1414from homeassistant .helpers .entity_platform import AddEntitiesCallback
1515from homeassistant .helpers .typing import ConfigType , DiscoveryInfoType
16+ import homeassistant .util .dt as dt
1617
1718import feedparser
1819
2425
2526CONF_FEED_URL = "feed_url"
2627CONF_DATE_FORMAT = "date_format"
28+ CONF_LOCAL_TIME = "local_time"
2729CONF_INCLUSIONS = "inclusions"
2830CONF_EXCLUSIONS = "exclusions"
2931CONF_SHOW_TOPN = "show_topn"
3537 vol .Required (CONF_NAME ): cv .string ,
3638 vol .Required (CONF_FEED_URL ): cv .string ,
3739 vol .Required (CONF_DATE_FORMAT , default = "%a, %b %d %I:%M %p" ): cv .string ,
40+ vol .Optional (CONF_LOCAL_TIME , default = False ): cv .boolean ,
3841 vol .Optional (CONF_SHOW_TOPN , default = 9999 ): cv .positive_int ,
3942 vol .Optional (CONF_INCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
4043 vol .Optional (CONF_EXCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
4346)
4447
4548
46- @asyncio .coroutine
47- def async_setup_platform (
49+ """ @asyncio.coroutine"""
50+ async def async_setup_platform (
4851 hass : HomeAssistant ,
4952 config : ConfigType ,
5053 async_add_devices : AddEntitiesCallback ,
@@ -56,6 +59,7 @@ def async_setup_platform(
5659 feed = config [CONF_FEED_URL ],
5760 name = config [CONF_NAME ],
5861 date_format = config [CONF_DATE_FORMAT ],
62+ local_time = config [CONF_LOCAL_TIME ],
5963 show_topn = config [CONF_SHOW_TOPN ],
6064 inclusions = config [CONF_INCLUSIONS ],
6165 exclusions = config [CONF_EXCLUSIONS ],
@@ -72,6 +76,7 @@ def __init__(
7276 feed : str ,
7377 name : str ,
7478 date_format : str ,
79+ local_time : bool ,
7580 show_topn : str ,
7681 exclusions : str ,
7782 inclusions : str ,
@@ -82,6 +87,7 @@ def __init__(
8287 self ._attr_icon = "mdi:rss"
8388 self ._date_format = date_format
8489 self ._show_topn = show_topn
90+ self ._local_time = local_time
8591 self ._inclusions = inclusions
8692 self ._exclusions = exclusions
8793 self ._scan_interval = scan_interval
@@ -113,7 +119,10 @@ def update(self):
113119 ):
114120 continue
115121 if key in ["published" , "updated" , "created" , "expired" ]:
116- value = parser .parse (value ).strftime (self ._date_format )
122+ value = parser .parse (value )
123+ if self ._local_time :
124+ value = dt .as_local (value )
125+ value = value .strftime (self ._date_format )
117126
118127 entry_value [key ] = value
119128
0 commit comments