Skip to content

Commit

Permalink
Feat: Capture guest name
Browse files Browse the repository at this point in the history
Teach the sensor how to determine a unique (short) name for each guest

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
  • Loading branch information
tykeal committed Mar 21, 2022
1 parent bbdf601 commit be858f8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions custom_components/rental_control/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self, hass, rental_control_events, sensor_name, event_number):
"start": None,
"end": None,
"eta": None,
"slot_name": None,
"slot_code": None,
}
self._state = summary
Expand Down Expand Up @@ -139,6 +140,40 @@ def _generate_door_code(self) -> str:
else:
return ret

def _get_slot_name(self) -> str:
"""Determine the name for a door slot."""

# strip off any prefix if it's being used
if self.rental_control_events.event_prefix:
p = re.compile(f"{self.rental_control_events.event_prefix} (.*)")
summary = p.findall(self._event_attributes["summary"])[0]
else:
summary = self._event_attributes["summary"]

# Blocked and Unavailable should not have a slot
p = re.compile("Not available|Blocked")
if p.search(summary):
return None

# AirBnB & VRBO
if re.search("Reserved", summary):
# AirBnB
if summary == "Reserved":
p = re.compile("([A-Z][A-Z0-9]{9})")
return p.search(self._event_attributes["description"])[0]
else:
p = re.compile(" - (.*)$")
return p.findall(summary)[0]

# Tripadvisor
if re.search("Tripadvisor", summary):
p = re.compile("Tripadvisor.*: (.*)")
return p.findall(summary)[0]

# Guesty
p = re.compile("-(.*)-.*-")
return p.findall(summary)[0]

@property
def entity_id(self):
"""Return the entity_id of the sensor."""
Expand Down Expand Up @@ -203,6 +238,7 @@ async def async_update(self):
self._state = f"{name} - {start.strftime('%-d %B %Y')}"
if not val.get("all_day"):
self._state += f" {start.strftime('%H:%M')}"
self._event_attributes["slot_name"] = self._get_slot_name()
self._event_attributes["slot_code"] = self._generate_door_code()
else:
# No reservations
Expand All @@ -222,6 +258,7 @@ async def async_update(self):
"start": None,
"end": None,
"eta": None,
"slot_name": None,
"slot_code": None,
}
self._state = summary

0 comments on commit be858f8

Please sign in to comment.