1010import homeassistant .helpers .config_validation as cv
1111from homeassistant .components .sensor import PLATFORM_SCHEMA
1212from homeassistant .const import CONF_NAME
13+ import homeassistant .util .dt as dt
1314
1415__version__ = "0.1.2"
1516
2021CONF_INCLUSIONS = "inclusions"
2122CONF_EXCLUSIONS = "exclusions"
2223CONF_SHOW_TOPN = "show_topn"
24+ CONF_LOCAL_TIME = 'local_time'
2325
2426DEFAULT_SCAN_INTERVAL = timedelta (hours = 1 )
2527
3537 vol .Optional (CONF_SHOW_TOPN , default = 9999 ): cv .positive_int ,
3638 vol .Optional (CONF_INCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
3739 vol .Optional (CONF_EXCLUSIONS , default = []): vol .All (cv .ensure_list , [cv .string ]),
40+ vol .Optional (CONF_LOCAL_TIME , default = False ): cv .boolean ,
3841 }
3942)
4043
@@ -47,6 +50,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
4750 feed = config [CONF_FEED_URL ],
4851 name = config [CONF_NAME ],
4952 date_format = config [CONF_DATE_FORMAT ],
53+ local_time = config [CONF_LOCAL_TIME ],
5054 show_topn = config [CONF_SHOW_TOPN ],
5155 inclusions = config [CONF_INCLUSIONS ],
5256 exclusions = config [CONF_EXCLUSIONS ],
@@ -63,12 +67,14 @@ def __init__(
6367 name : str ,
6468 date_format : str ,
6569 show_topn : str ,
70+ local_time : bool ,
6671 exclusions : str ,
6772 inclusions : str ,
6873 ):
6974 self ._feed = feed
7075 self ._name = name
7176 self ._date_format = date_format
77+ self ._local_time = local_time
7278 self ._show_topn = show_topn
7379 self ._inclusions = inclusions
7480 self ._exclusions = exclusions
@@ -99,7 +105,11 @@ def update(self):
99105 ):
100106 continue
101107 if key in ["published" , "updated" , "created" , "expired" ]:
102- value = parser .parse (value ).strftime (self ._date_format )
108+ value = parser .parse (value )
109+ if self ._local_time :
110+ value = dt .as_local (value )
111+ value = value .strftime (self ._date_format )
112+
103113
104114 entryValue [key ] = value
105115
0 commit comments