Skip to content

Commit

Permalink
Merge pull request #137 from tykeal/generic_calendars
Browse files Browse the repository at this point in the history
Feat: Support more generic calendar entries
  • Loading branch information
tykeal authored Oct 6, 2022
2 parents 1c888da + 06ecb88 commit 6522e10
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions custom_components/rental_control/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import re
import uuid
from typing import Any
from typing import List

from homeassistant.components.automation import DOMAIN as AUTO_DOMAIN
Expand Down Expand Up @@ -173,28 +174,44 @@ def get_slot_name(summary: str, description: str, prefix: str) -> str | None:
# Airbnb
if name == "Reserved":
p = re.compile(r"([A-Z][A-Z0-9]{9})")
ret = p.search(description)
if ret is not None:
return ret[0]
if description:
ret = p.search(description) # type: Any
if ret is not None:
return str(ret[0])
else:
return None
else:
return None
else:
p = re.compile(r" - (.*)$")
return str(p.findall(name)[0])
ret = p.findall(name)
if len(ret):
return str(ret[0])

# Tripadvisor
if "Tripadvisor" in name:
p = re.compile(r"Tripadvisor.*: (.*)")
return str(p.findall(name)[0])
ret = p.findall(name)
if len(ret):
return str(ret[0])

# Booking.com
if "CLOSED" in name:
p = re.compile(r"\s*CLOSED - (.*)")
return str(p.findall(name)[0])
ret = p.findall(name)
if len(ret):
return str(ret[0])

# Guesty
p = re.compile(r"-(.*)-.*-")
return str(p.findall(name)[0])
ret = p.findall(name)
if len(ret):
return str(ret[0])

# Degenerative case, we can't figure it out at all, we'll just use the
# name as is, this could cause duplicate slot names but this is likely
# a custom calendar anyway
return str(name)


def write_template_config(
Expand Down

0 comments on commit 6522e10

Please sign in to comment.