Skip to content

Commit

Permalink
Fix: Make last 4 digit check more lenient
Browse files Browse the repository at this point in the history
The documentation and regex for getting door codes that are the last 4
digits of a phone number are to be made more clear and lenient.

Issue: Fixes #141
Signed-off-by: Andrew Grimberg <[email protected]>
  • Loading branch information
tykeal committed Nov 9, 2022
1 parent 273a946 commit 57fa71b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ calendars and sensors to go with them related to managing rental properties.
another generator fails to produce a code)
- A random 4 digit (or greater) code based on the event description
- The last 4 digits of the phone number. This only works properly if the
event description contains 'Last 4 Digits' followed quickly by a 4 digit
number. This is the most stable, but only works if the event
descriptions have the needed data. The previous two methods can have the
codes change if the event makes changes to length or to the description.
event description contains '(Last 4 Digits): ' or 'Last 4 Digits: '
followed quickly by a 4 digit number. This is the most stable, but only
works if the event descriptions have the needed data. The previous two
methods can have the codes change if the event makes changes to length
or to the description.
- All events will get a code associated with it. In the case that the criteria
to create the code are not fulfilled, then the check-in/out date based
method will be used as a fallback
Expand Down
2 changes: 1 addition & 1 deletion custom_components/rental_control/sensors/calsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _extract_last_four(self) -> str | None:
"""Extract the last 4 digits from a description."""
if self._event_attributes["description"] is None:
return None
p = re.compile(r"""\(Last 4 Digits\):\s+(\d{4})""")
p = re.compile(r"""\(?Last 4 Digits\)?:\s+(\d{4})""")
ret = p.findall(self._event_attributes["description"])
if ret:
return str(ret[0])
Expand Down
9 changes: 5 additions & 4 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ calendars and sensors to go with them related to managing rental properties.
another generator fails to produce a code)
- A random 4 digit (or greater) code based on the event description
- The last 4 digits of the phone number. This only works properly if the
event description contains 'Last 4 Digits' followed quickly by a 4 digit
number. This is the most stable, but only works if the event
descriptions have the needed data. The previous two methods can have the
codes change if the event makes changes to length or to the description.
event description contains '(Last 4 Digits): ' or 'Last 4 Digits: '
followed quickly by a 4 digit number. This is the most stable, but only
works if the event descriptions have the needed data. The previous two
methods can have the codes change if the event makes changes to length
or to the description.
- All events will get a code associated with it. In the case that the criteria
to create the code are not fulfilled, then the check-in/out date based
method will be used as a fallback
Expand Down

0 comments on commit 57fa71b

Please sign in to comment.