Skip to content

Commit

Permalink
added 'contains' filter
Browse files Browse the repository at this point in the history
  • Loading branch information
KoljaWindeler committed Oct 2, 2020
1 parent 2fe0fcf commit a7c2824
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Key | Type | Required | Default | Description
`timeformat` | `string` | `false` | `"%A, %d.%m.%Y"` | The format that is used to display the date see http://strftime.org/ for more infomation
`lookahead` | `int` | `false` | `365` | The number of days that limits the forecast. E.g. 1 will only show the events of today
`startswith` | `string` | `false` | `""` | A filter that will limit the display of events. E.g. if your file contains multiple entries and you only want to know one type at per sensor, simply create multiple sensors and filter. Have a look at sensor 3 and 4 above. startswith: Bio will ohne show events that start with Bio.
`contains` | `string` | `false` | `""` | A filter like startswith, but this will search within the string instead of the start.
`show_blank` | `string` | `false` | `""` | Indicates whether to show empty events (events without title), and what should be used as title instead. e.g. "Meeting123" would show events with empty title with the string "Meeting123". An empty string (default) or " " will avoid showing blank events.
`force_update` | `int` | `false` | `0` | Force to update the data with given intervall (seconds). This can be useful if the calendar is very dynamic, but pointless for almost static calendars. The calendar will reload at midnight and once the (start/end) of the event is over regardless of this setting. 0 = Disabled
`show_remaining` | `bool` | `false` | `true` | Show the remaining days in the sensor state, close to the date.
Expand Down
13 changes: 11 additions & 2 deletions custom_components/isc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# generals
DOMAIN = "ics"
PLATFORM = "sensor"
VERSION = "1.1.0"
VERSION = "1.2.0"
ISSUE_URL = "https://github.com/koljawindeler/ics/issues"

# configuration
Expand All @@ -29,6 +29,7 @@
CONF_TIMEFORMAT = "timeformat"
CONF_LOOKAHEAD = "lookahead"
CONF_SW = "startswith"
CONF_CONTAINS = "contains"
CONF_SHOW_BLANK = "show_blank"
CONF_FORCE_UPDATE = "force_update"
CONF_SHOW_REMAINING = "show_remaining"
Expand All @@ -40,8 +41,9 @@
# defaults
DEFAULT_ICON = 'mdi:calendar'
DEFAULT_NAME = "ics_sensor"
DEFAULT_SW = ""
DEFAULT_ID = 1
DEFAULT_SW = ""
DEFAULT_CONTAINS = ""
DEFAULT_TIMEFORMAT = "%A, %d.%m.%Y"
DEFAULT_LOOKAHEAD = 365
DEFAULT_SHOW_BLANK = ""
Expand All @@ -68,6 +70,7 @@
vol.Optional(CONF_ID, default=DEFAULT_ID): vol.Coerce(int),
vol.Optional(CONF_TIMEFORMAT, default=DEFAULT_TIMEFORMAT): cv.string,
vol.Optional(CONF_SW, default=DEFAULT_SW): cv.string,
vol.Optional(CONF_CONTAINS, default=DEFAULT_CONTAINS): cv.string,
vol.Optional(CONF_LOOKAHEAD, default=DEFAULT_LOOKAHEAD): vol.Coerce(int),
vol.Optional(CONF_SHOW_BLANK, default=DEFAULT_SHOW_BLANK): cv.string,
vol.Optional(CONF_FORCE_UPDATE, default=DEFAULT_FORCE_UPDATE): vol.Coerce(int),
Expand Down Expand Up @@ -97,6 +100,7 @@ def ensure_config(user_input, hass):
out[CONF_ICS_URL] = ""
out[CONF_TIMEFORMAT] = DEFAULT_TIMEFORMAT
out[CONF_SW] = DEFAULT_SW
out[CONF_CONTAINS] = DEFAULT_CONTAINS
out[CONF_LOOKAHEAD] = DEFAULT_LOOKAHEAD
out[CONF_SHOW_BLANK] = DEFAULT_SHOW_BLANK
out[CONF_FORCE_UPDATE] = DEFAULT_FORCE_UPDATE
Expand All @@ -121,6 +125,10 @@ def ensure_config(user_input, hass):
out[CONF_SW] = user_input[CONF_SW]
if(out[CONF_SW] == " "):
out[CONF_SW] = ""
if CONF_CONTAINS in user_input:
out[CONF_CONTAINS] = user_input[CONF_CONTAINS]
if(out[CONF_CONTAINS] == " "):
out[CONF_CONTAINS] = ""
if CONF_LOOKAHEAD in user_input:
out[CONF_LOOKAHEAD] = user_input[CONF_LOOKAHEAD]
if CONF_SHOW_REMAINING in user_input:
Expand Down Expand Up @@ -206,6 +214,7 @@ def create_form(page, user_input, hass):
data_schema[vol.Required(CONF_ID, default=user_input[CONF_ID])] = int
data_schema[vol.Optional(CONF_TIMEFORMAT, default=user_input[CONF_TIMEFORMAT])] = str
data_schema[vol.Optional(CONF_SW, default=user_input[CONF_SW])] = str
data_schema[vol.Optional(CONF_CONTAINS, default=user_input[CONF_CONTAINS])] = str
data_schema[vol.Optional(CONF_LOOKAHEAD, default=user_input[CONF_LOOKAHEAD])] = int
data_schema[vol.Optional(CONF_ICON, default=user_input[CONF_ICON])] = str

Expand Down
5 changes: 4 additions & 1 deletion custom_components/isc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, hass, config):
self._url = config.get(CONF_ICS_URL)
self._name = config.get(CONF_NAME)
self._sw = config.get(CONF_SW)
self._contains = config.get(CONF_CONTAINS)
self._timeformat = config.get(CONF_TIMEFORMAT)
self._lookahead = config.get(CONF_LOOKAHEAD)
self._show_blank = config.get(CONF_SHOW_BLANK)
Expand All @@ -64,6 +65,7 @@ def __init__(self, hass, config):
_LOGGER.debug("\tID: " + str(config.get(CONF_ID)))
_LOGGER.debug("\turl: " + self._url)
_LOGGER.debug("\tsw: " + self._sw)
_LOGGER.debug("\tcontains: " + self._contains)
_LOGGER.debug("\ttimeformat: " + self._timeformat)
_LOGGER.debug("\tlookahead: " + str(self._lookahead))
_LOGGER.debug("\tshow_blank: " + str(self._show_blank))
Expand Down Expand Up @@ -224,7 +226,8 @@ async def get_data(self):
event_summary = self.fix_text(e["SUMMARY"])

if(event_summary):
if(event_summary.lower().startswith(self.fix_text(self._sw).lower())):
if(event_summary.lower().startswith(self.fix_text(self._sw).lower()) and
event_summary.lower().find(self.fix_text(self._contains).lower())>=0 ):
if((event_date > now) or (self._show_ongoing and event_end_date > now)):
# logic to skip events, but save certain details,
# e.g. reload / and timeslot for grouping
Expand Down
10 changes: 6 additions & 4 deletions custom_components/isc/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"url": "The url to the ics file. Usually http://domain/calendar.ics but can also be local file:///tmp/test.ics ",
"id": "Unique number to identify your sensor later on. e.g. id=1 results in sensor.ical_1",
"timeformat": "Timeformat (see http://strftime.org/).",
"startswith": "Filter, see link above for more info" ,
"startswith": "Startswith Filter, see link above for more info" ,
"contains": "Contains Filter, see link above for more info" ,
"lookahead": "Lookahead",
"icon": "Icon (see https://materialdesignicons.com/)."
}
Expand All @@ -20,7 +21,7 @@
"description": "Enter the sensor name and configure sensor parameters. More info on https://github.com/koljawindeler/ics#configuration-options.\n Page 2/2",
"data": {
"show_blank": "Show events without title",
"force_update": "Force periodical updates",
"force_update": "Force periodical updates (sec)",
"show_remaining": "Show remaining days",
"show_ongoing": "Show events that are ongoing",
"group_events": "Group events (show multiple)",
Expand Down Expand Up @@ -49,7 +50,8 @@
"url": "The url to the ics file. Usually http://domain/calendar.ics but can also be local file:///tmp/test.ics ",
"id": "Unique number to identify your sensor later on. e.g. id=1 results in sensor.ical_1",
"timeformat": "Timeformat (see http://strftime.org/).",
"startswith": "Filter, see link above for more info" ,
"startswith": "Startswith Filter, see link above for more info" ,
"contains": "Contains Filter, see link above for more info" ,
"lookahead": "Lookahead",
"icon": "Icon (see https://materialdesignicons.com/)."
}
Expand All @@ -59,7 +61,7 @@
"description": "Enter the sensor name and configure sensor parameters. More info on https://github.com/koljawindeler/ics#configuration-options.\n Page 2/2",
"data": {
"show_blank": "Show events without title",
"force_update": "Force periodical updates",
"force_update": "Force periodical updates (sec)",
"show_remaining": "Show remaining days",
"show_ongoing": "Show events that are ongoing",
"group_events": "Group events (show multiple)",
Expand Down
10 changes: 6 additions & 4 deletions custom_components/isc/translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"url": "URLen til ics-filen. Vanligvis http://domene/kalender.ics, men kan også være lokal fil:///tmp/test.ics ",
"id": "Unikt nummer for å identifisere sensoren din senere. f.eks. id = 1 resulterer i sensor.ical_1",
"timeformat": "Tidsformat (se http://strftime.org/).",
"startswith": "Filter, se lenke over for mer info" ,
"startswith": "Startswith Filter, se lenke over for mer info" ,
"contains": "Contains Filter, se lenke over for mer info" ,
"lookahead": "Lookahead",
"icon": "Ikon (se https://materialdesignicons.com/)."
}
Expand All @@ -20,7 +21,7 @@
"description": "Skriv inn sensornavnet og konfigurer sensorparametrene. Mer info på https://github.com/koljawindeler/ics#configuration-options.\n Side 2/2",
"data": {
"show_blank": "Vis hendelser uten tittel",
"force_update": "Tving periodiske oppdateringer",
"force_update": "Tving periodiske oppdateringer (sec)",
"show_remaining": "Vis gjenværende dager",
"show_ongoing": "Vis hendelser som pågå",
"group_events": "Gruppearrangementer (vis flere)",
Expand Down Expand Up @@ -49,7 +50,8 @@
"url": "URLen til ics-filen. Vanligvis http://domene/kalender.ics, men kan også være lokal fil:///tmp/test.ics ",
"id": "Unikt nummer for å identifisere sensoren din senere. f.eks. id = 1 resulterer i sensor.ical_1",
"timeformat": "Tidsformat (se http://strftime.org/).",
"startswith": "Filter, se lenke over for mer info" ,
"startswith": "Startswith Filter, se lenke over for mer info" ,
"contains": "Contains Filter, se lenke over for mer info" ,
"lookahead": "Se fremover",
"icon": "Ikon (se https://materialdesignicons.com/)."
}
Expand All @@ -59,7 +61,7 @@
"description": "Skriv inn sensornavnet og konfigurer sensorparametrene. Mer info på https://github.com/koljawindeler/ics#configuration-options.\n Side 2/2",
"data": {
"show_blank": "Vis hendelser uten tittel",
"force_update": "Tving periodiske oppdateringer",
"force_update": "Tving periodiske oppdateringer (sec)",
"show_remaining": "Vis gjenværende dager",
"show_ongoing": "Vis hendelser som pågår",
"group_events": "Gruppearrangementer (vis flere)",
Expand Down

0 comments on commit a7c2824

Please sign in to comment.