Skip to content

Commit

Permalink
Merge pull request #203 from tykeal/allow_short_events
Browse files Browse the repository at this point in the history
Feat: Add support for short events
  • Loading branch information
tykeal authored Jun 15, 2024
2 parents 0839aa2 + f64240e commit 1a702b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions custom_components/rental_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from homeassistant.util import dt
from icalendar import Calendar
import voluptuous as vol
import x_wr_timezone

from .config_flow import _lock_entry_convert as lock_entry_convert
from .const import ATTR_NAME
Expand Down Expand Up @@ -635,8 +636,14 @@ async def _ical_parser(
checkin: time = override["start_time"].time()
checkout: time = override["end_time"].time()
else:
checkin = self.checkin
checkout = self.checkout
try:
# If the event has a time, use that, otherwise use the
# default checkin/checkout times
checkin = event["DTSTART"].dt.time()
checkout = event["DTEND"].dt.time()
except AttributeError:
checkin = self.checkin
checkout = self.checkout

_LOGGER.debug("DTSTART in event: %s", event["DTSTART"].dt)
dtstart = datetime.combine(event["DTSTART"].dt, checkin, self.timezone)
Expand Down Expand Up @@ -730,6 +737,14 @@ async def _refresh_calendar(self) -> None:
# Some calendars are for some reason filled with NULL-bytes.
# They break the parsing, so we get rid of them
event_list = Calendar.from_ical(text.replace("\x00", ""))

# If the calendar is using a non-standard timezone definition,
# convert it to a standard one
if "X-WR-TIMEZONE" in event_list:
event_list = await self.hass.async_add_executor_job(
x_wr_timezone.to_standard, event_list
)

start_of_events = dt.start_of_local_day()
end_of_events = dt.start_of_local_day() + timedelta(days=self.days)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/rental_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"integration_type": "service",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/tykeal/homeassistant-rental-control/issues",
"requirements": ["icalendar==5.0.7"],
"requirements": ["icalendar==5.0.7", "x-wr-timezone==0.0.7"],
"version": "v0.0.0"
}

0 comments on commit 1a702b9

Please sign in to comment.