Skip to content

Commit a7c2824

Browse files
committed
added 'contains' filter
1 parent 2fe0fcf commit a7c2824

5 files changed

Lines changed: 28 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Key | Type | Required | Default | Description
6868
`timeformat` | `string` | `false` | `"%A, %d.%m.%Y"` | The format that is used to display the date see http://strftime.org/ for more infomation
6969
`lookahead` | `int` | `false` | `365` | The number of days that limits the forecast. E.g. 1 will only show the events of today
7070
`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.
71+
`contains` | `string` | `false` | `""` | A filter like startswith, but this will search within the string instead of the start.
7172
`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.
7273
`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
7374
`show_remaining` | `bool` | `false` | `true` | Show the remaining days in the sensor state, close to the date.

custom_components/isc/const.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# generals
1919
DOMAIN = "ics"
2020
PLATFORM = "sensor"
21-
VERSION = "1.1.0"
21+
VERSION = "1.2.0"
2222
ISSUE_URL = "https://github.com/koljawindeler/ics/issues"
2323

2424
# configuration
@@ -29,6 +29,7 @@
2929
CONF_TIMEFORMAT = "timeformat"
3030
CONF_LOOKAHEAD = "lookahead"
3131
CONF_SW = "startswith"
32+
CONF_CONTAINS = "contains"
3233
CONF_SHOW_BLANK = "show_blank"
3334
CONF_FORCE_UPDATE = "force_update"
3435
CONF_SHOW_REMAINING = "show_remaining"
@@ -40,8 +41,9 @@
4041
# defaults
4142
DEFAULT_ICON = 'mdi:calendar'
4243
DEFAULT_NAME = "ics_sensor"
43-
DEFAULT_SW = ""
4444
DEFAULT_ID = 1
45+
DEFAULT_SW = ""
46+
DEFAULT_CONTAINS = ""
4547
DEFAULT_TIMEFORMAT = "%A, %d.%m.%Y"
4648
DEFAULT_LOOKAHEAD = 365
4749
DEFAULT_SHOW_BLANK = ""
@@ -68,6 +70,7 @@
6870
vol.Optional(CONF_ID, default=DEFAULT_ID): vol.Coerce(int),
6971
vol.Optional(CONF_TIMEFORMAT, default=DEFAULT_TIMEFORMAT): cv.string,
7072
vol.Optional(CONF_SW, default=DEFAULT_SW): cv.string,
73+
vol.Optional(CONF_CONTAINS, default=DEFAULT_CONTAINS): cv.string,
7174
vol.Optional(CONF_LOOKAHEAD, default=DEFAULT_LOOKAHEAD): vol.Coerce(int),
7275
vol.Optional(CONF_SHOW_BLANK, default=DEFAULT_SHOW_BLANK): cv.string,
7376
vol.Optional(CONF_FORCE_UPDATE, default=DEFAULT_FORCE_UPDATE): vol.Coerce(int),
@@ -97,6 +100,7 @@ def ensure_config(user_input, hass):
97100
out[CONF_ICS_URL] = ""
98101
out[CONF_TIMEFORMAT] = DEFAULT_TIMEFORMAT
99102
out[CONF_SW] = DEFAULT_SW
103+
out[CONF_CONTAINS] = DEFAULT_CONTAINS
100104
out[CONF_LOOKAHEAD] = DEFAULT_LOOKAHEAD
101105
out[CONF_SHOW_BLANK] = DEFAULT_SHOW_BLANK
102106
out[CONF_FORCE_UPDATE] = DEFAULT_FORCE_UPDATE
@@ -121,6 +125,10 @@ def ensure_config(user_input, hass):
121125
out[CONF_SW] = user_input[CONF_SW]
122126
if(out[CONF_SW] == " "):
123127
out[CONF_SW] = ""
128+
if CONF_CONTAINS in user_input:
129+
out[CONF_CONTAINS] = user_input[CONF_CONTAINS]
130+
if(out[CONF_CONTAINS] == " "):
131+
out[CONF_CONTAINS] = ""
124132
if CONF_LOOKAHEAD in user_input:
125133
out[CONF_LOOKAHEAD] = user_input[CONF_LOOKAHEAD]
126134
if CONF_SHOW_REMAINING in user_input:
@@ -206,6 +214,7 @@ def create_form(page, user_input, hass):
206214
data_schema[vol.Required(CONF_ID, default=user_input[CONF_ID])] = int
207215
data_schema[vol.Optional(CONF_TIMEFORMAT, default=user_input[CONF_TIMEFORMAT])] = str
208216
data_schema[vol.Optional(CONF_SW, default=user_input[CONF_SW])] = str
217+
data_schema[vol.Optional(CONF_CONTAINS, default=user_input[CONF_CONTAINS])] = str
209218
data_schema[vol.Optional(CONF_LOOKAHEAD, default=user_input[CONF_LOOKAHEAD])] = int
210219
data_schema[vol.Optional(CONF_ICON, default=user_input[CONF_ICON])] = str
211220

custom_components/isc/sensor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self, hass, config):
4848
self._url = config.get(CONF_ICS_URL)
4949
self._name = config.get(CONF_NAME)
5050
self._sw = config.get(CONF_SW)
51+
self._contains = config.get(CONF_CONTAINS)
5152
self._timeformat = config.get(CONF_TIMEFORMAT)
5253
self._lookahead = config.get(CONF_LOOKAHEAD)
5354
self._show_blank = config.get(CONF_SHOW_BLANK)
@@ -64,6 +65,7 @@ def __init__(self, hass, config):
6465
_LOGGER.debug("\tID: " + str(config.get(CONF_ID)))
6566
_LOGGER.debug("\turl: " + self._url)
6667
_LOGGER.debug("\tsw: " + self._sw)
68+
_LOGGER.debug("\tcontains: " + self._contains)
6769
_LOGGER.debug("\ttimeformat: " + self._timeformat)
6870
_LOGGER.debug("\tlookahead: " + str(self._lookahead))
6971
_LOGGER.debug("\tshow_blank: " + str(self._show_blank))
@@ -224,7 +226,8 @@ async def get_data(self):
224226
event_summary = self.fix_text(e["SUMMARY"])
225227

226228
if(event_summary):
227-
if(event_summary.lower().startswith(self.fix_text(self._sw).lower())):
229+
if(event_summary.lower().startswith(self.fix_text(self._sw).lower()) and
230+
event_summary.lower().find(self.fix_text(self._contains).lower())>=0 ):
228231
if((event_date > now) or (self._show_ongoing and event_end_date > now)):
229232
# logic to skip events, but save certain details,
230233
# e.g. reload / and timeslot for grouping

custom_components/isc/translations/en.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"url": "The url to the ics file. Usually http://domain/calendar.ics but can also be local file:///tmp/test.ics ",
1111
"id": "Unique number to identify your sensor later on. e.g. id=1 results in sensor.ical_1",
1212
"timeformat": "Timeformat (see http://strftime.org/).",
13-
"startswith": "Filter, see link above for more info" ,
13+
"startswith": "Startswith Filter, see link above for more info" ,
14+
"contains": "Contains Filter, see link above for more info" ,
1415
"lookahead": "Lookahead",
1516
"icon": "Icon (see https://materialdesignicons.com/)."
1617
}
@@ -20,7 +21,7 @@
2021
"description": "Enter the sensor name and configure sensor parameters. More info on https://github.com/koljawindeler/ics#configuration-options.\n Page 2/2",
2122
"data": {
2223
"show_blank": "Show events without title",
23-
"force_update": "Force periodical updates",
24+
"force_update": "Force periodical updates (sec)",
2425
"show_remaining": "Show remaining days",
2526
"show_ongoing": "Show events that are ongoing",
2627
"group_events": "Group events (show multiple)",
@@ -49,7 +50,8 @@
4950
"url": "The url to the ics file. Usually http://domain/calendar.ics but can also be local file:///tmp/test.ics ",
5051
"id": "Unique number to identify your sensor later on. e.g. id=1 results in sensor.ical_1",
5152
"timeformat": "Timeformat (see http://strftime.org/).",
52-
"startswith": "Filter, see link above for more info" ,
53+
"startswith": "Startswith Filter, see link above for more info" ,
54+
"contains": "Contains Filter, see link above for more info" ,
5355
"lookahead": "Lookahead",
5456
"icon": "Icon (see https://materialdesignicons.com/)."
5557
}
@@ -59,7 +61,7 @@
5961
"description": "Enter the sensor name and configure sensor parameters. More info on https://github.com/koljawindeler/ics#configuration-options.\n Page 2/2",
6062
"data": {
6163
"show_blank": "Show events without title",
62-
"force_update": "Force periodical updates",
64+
"force_update": "Force periodical updates (sec)",
6365
"show_remaining": "Show remaining days",
6466
"show_ongoing": "Show events that are ongoing",
6567
"group_events": "Group events (show multiple)",

custom_components/isc/translations/nb.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"url": "URLen til ics-filen. Vanligvis http://domene/kalender.ics, men kan også være lokal fil:///tmp/test.ics ",
1111
"id": "Unikt nummer for å identifisere sensoren din senere. f.eks. id = 1 resulterer i sensor.ical_1",
1212
"timeformat": "Tidsformat (se http://strftime.org/).",
13-
"startswith": "Filter, se lenke over for mer info" ,
13+
"startswith": "Startswith Filter, se lenke over for mer info" ,
14+
"contains": "Contains Filter, se lenke over for mer info" ,
1415
"lookahead": "Lookahead",
1516
"icon": "Ikon (se https://materialdesignicons.com/)."
1617
}
@@ -20,7 +21,7 @@
2021
"description": "Skriv inn sensornavnet og konfigurer sensorparametrene. Mer info på https://github.com/koljawindeler/ics#configuration-options.\n Side 2/2",
2122
"data": {
2223
"show_blank": "Vis hendelser uten tittel",
23-
"force_update": "Tving periodiske oppdateringer",
24+
"force_update": "Tving periodiske oppdateringer (sec)",
2425
"show_remaining": "Vis gjenværende dager",
2526
"show_ongoing": "Vis hendelser som pågå",
2627
"group_events": "Gruppearrangementer (vis flere)",
@@ -49,7 +50,8 @@
4950
"url": "URLen til ics-filen. Vanligvis http://domene/kalender.ics, men kan også være lokal fil:///tmp/test.ics ",
5051
"id": "Unikt nummer for å identifisere sensoren din senere. f.eks. id = 1 resulterer i sensor.ical_1",
5152
"timeformat": "Tidsformat (se http://strftime.org/).",
52-
"startswith": "Filter, se lenke over for mer info" ,
53+
"startswith": "Startswith Filter, se lenke over for mer info" ,
54+
"contains": "Contains Filter, se lenke over for mer info" ,
5355
"lookahead": "Se fremover",
5456
"icon": "Ikon (se https://materialdesignicons.com/)."
5557
}
@@ -59,7 +61,7 @@
5961
"description": "Skriv inn sensornavnet og konfigurer sensorparametrene. Mer info på https://github.com/koljawindeler/ics#configuration-options.\n Side 2/2",
6062
"data": {
6163
"show_blank": "Vis hendelser uten tittel",
62-
"force_update": "Tving periodiske oppdateringer",
64+
"force_update": "Tving periodiske oppdateringer (sec)",
6365
"show_remaining": "Vis gjenværende dager",
6466
"show_ongoing": "Vis hendelser som pågår",
6567
"group_events": "Gruppearrangementer (vis flere)",

0 commit comments

Comments
 (0)