Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ key | description
**name (Required)** | Name your feed
**feed_url (Required)** | The RSS feed URL
**date_format (Optional)** | strftime date format for date strings **Default** `%a, %b %d %I:%M %p`
**local_time (Optional)** | Whether to convert date into local time **Default** false
**show_topn (Optional)** | fetch how many entres from rss source,if not set then fetch all
**inclusions (Optional)** | List of fields to include from populating the list
**exclusions (Optional)** | List of fields to exclude from populating the list
Expand Down
12 changes: 11 additions & 1 deletion custom_components/feedparser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
import homeassistant.util.dt as dt

__version__ = "0.1.2"

Expand All @@ -20,6 +21,7 @@
CONF_INCLUSIONS = "inclusions"
CONF_EXCLUSIONS = "exclusions"
CONF_SHOW_TOPN = "show_topn"
CONF_LOCAL_TIME = 'local_time'

DEFAULT_SCAN_INTERVAL = timedelta(hours=1)

Expand All @@ -35,6 +37,7 @@
vol.Optional(CONF_SHOW_TOPN, default=9999): cv.positive_int,
vol.Optional(CONF_INCLUSIONS, default=[]): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_EXCLUSIONS, default=[]): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_LOCAL_TIME, default=False): cv.boolean,
}
)

Expand All @@ -47,6 +50,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
feed=config[CONF_FEED_URL],
name=config[CONF_NAME],
date_format=config[CONF_DATE_FORMAT],
local_time=config[CONF_LOCAL_TIME],
show_topn=config[CONF_SHOW_TOPN],
inclusions=config[CONF_INCLUSIONS],
exclusions=config[CONF_EXCLUSIONS],
Expand All @@ -63,12 +67,14 @@ def __init__(
name: str,
date_format: str,
show_topn: str,
local_time: bool,
exclusions: str,
inclusions: str,
):
self._feed = feed
self._name = name
self._date_format = date_format
self._local_time = local_time
self._show_topn = show_topn
self._inclusions = inclusions
self._exclusions = exclusions
Expand Down Expand Up @@ -99,7 +105,11 @@ def update(self):
):
continue
if key in ["published", "updated", "created", "expired"]:
value = parser.parse(value).strftime(self._date_format)
value = parser.parse(value)
if self._local_time:
value = dt.as_local(value)
value = value.strftime(self._date_format)


entryValue[key] = value

Expand Down