Skip to content

Commit

Permalink
Issue148 (#155)
Browse files Browse the repository at this point in the history
Fixes #148

Description of change:

## Formatting, testing, and code coverage
Please note your pull request won't be accepted if you haven't properly
formatted your source code, and ensured the unit tests are appropriate.
Please note if you are not running on Windows, you can either run the
scripts via a bash installation (like git-bash).

- [X] formatstyle.sh reports no errors
- [X] All unit tests pass (test.sh)
- [X] Code coverage has not decreased (test.sh)
  • Loading branch information
franc6 authored Sep 11, 2024
2 parents cccad8a + 2842c7b commit 477efad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 5.0.1 2024/09/11
- Fixed #149 Thanks, @jpbede!
- Added German Translation by @mbenecke
- Fixed #148

## 5.0.0 2024/09/10
- Fixed #117 Made sure the global download lock blocks and ensures min_update_time. (@agroszer)
- Add UI configuration support
Expand Down
22 changes: 7 additions & 15 deletions custom_components/ics_calendar/calendardata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
)
from threading import Lock
from urllib.error import ContentTooShortError, HTTPError, URLError
from urllib.parse import quote
from urllib.request import (
HTTPBasicAuthHandler,
HTTPDigestAuthHandler,
Expand Down Expand Up @@ -79,12 +78,13 @@ def download_calendar(self) -> bool:
or (hanow() - self._last_download) > self._min_update_time
):
self._calendar_data = None
next_url: str = self._make_url()
self.logger.debug(
"%s: Downloading calendar data from: %s",
self.name,
self.url,
next_url,
)
self._download_data()
self._download_data(next_url)
self._last_download = hanow()
self.logger.debug("%s: download_calendar done", self.name)
return self._calendar_data is not None
Expand Down Expand Up @@ -186,15 +186,13 @@ def _decode_stream(self, strm):
continue
return None

def _download_data(self):
def _download_data(self, url):
"""Download the calendar data."""
self.logger.debug("%s: _download_data start", self.name)
try:
if self._opener is not None:
install_opener(self._opener)
with urlopen(
self._make_url(), timeout=self.connection_timeout
) as conn:
with urlopen(url, timeout=self.connection_timeout) as conn:
self._calendar_data = self._decode_data(conn)
self.logger.debug("%s: _download_data done", self.name)
except HTTPError as http_error:
Expand Down Expand Up @@ -222,12 +220,6 @@ def _download_data(self):
def _make_url(self):
"""Replace templates in url and encode."""
now = hanow()
# Encode the URL to ensure it only contains ASCII characters
self.url = quote(
self.url.replace("{year}", f"{now.year:04}").replace(
"{month}", f"{now.month:02}"
),
safe=":/?&=@",
return self.url.replace("{year}", f"{now.year:04}").replace(
"{month}", f"{now.month:02}"
)
self.logger.debug("%s: URL: %s", self.name, self.url)
return self.url
4 changes: 4 additions & 0 deletions custom_components/ics_calendar/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from typing import Any, Dict, Optional
from urllib.parse import quote

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -175,6 +176,9 @@ async def async_step_connect_opts(
errors[CONF_URL] = "empty_url"

if not errors:
user_input[CONF_URL] = quote(
user_input[CONF_URL], safe=":/?&="
)
self.data.update(user_input)
if user_input.get(CONF_REQUIRES_AUTH, False):
return await self.async_step_auth_opts()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ics_calendar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/franc6/ics_calendar/issues",
"requirements": ["ics>=0.7.2", "recurring_ical_events>=2.0.2", "icalendar>=5.0.4"],
"version": "5.0.0"
"version": "5.0.1"
}

0 comments on commit 477efad

Please sign in to comment.