Skip to content

Commit 6318e28

Browse files
fix: updated parsing for new Ocado emails (#18)
* fix: updated regex for the new style of receipt pdf * fix: added some new constants * fix: updated to reflect the new Ocado emails. * chore: disable the receipt parsing since the PDF is no longer included in receipt emails. * chore: disabling BBD sensor by default for the time being to avoid confusion. * chore: updated dependencies for tests. * chore: updating versioning according to the bot's wishes * chore: appeasing the rust bot.
1 parent c071e4c commit 6318e28

File tree

5 files changed

+150
-108
lines changed

5 files changed

+150
-108
lines changed

custom_components/ocado/const.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
DOMAIN = "ocado"
77

88
OCADO_ADDRESS = "customerservices@ocado.com"
9+
NEW_OCADO_ADDRESS = "noreply@email.ocado.com"
910
OCADO_CANCELLATION_SUBJECT = "Order cancellation confirmation"
1011
OCADO_CONFIRMATION_SUBJECT = "Confirmation of your order"
1112
OCADO_CUTOFF_SUBJECT = "Don't miss the cut-off time for editing your order"
1213
OCADO_NEW_TOTAL_SUBJECT = "What you returned, and your new total"
1314
OCADO_RECEIPT_SUBJECT = "Your receipt for today's Ocado delivery"
15+
OCADO_NEW_NEW_TOTAL_SUBJECT = "Your receipt and updates for today’s delivery"
1416
OCADO_SMARTPASS_SUBJECT = "Payment successful: Smart Pass membership"
1517
OCADO_SUBJECT_DICT = {
1618
OCADO_CANCELLATION_SUBJECT: "cancellation",
1719
OCADO_CONFIRMATION_SUBJECT: "confirmation",
1820
OCADO_NEW_TOTAL_SUBJECT: "new_total",
19-
OCADO_RECEIPT_SUBJECT: "receipt"
21+
OCADO_RECEIPT_SUBJECT: "receipt",
22+
OCADO_NEW_NEW_TOTAL_SUBJECT:"new_total"
2023
}
2124

2225
CONF_IMAP_DAYS = 'imap_days'
@@ -52,6 +55,7 @@
5255
# If this eventually fails due to other formats being used, python-dateutil should be used
5356
REGEX_DATE_FULL = r"((?:" + REGEX_DATE + r")\/(?:" + REGEX_MONTH + r")\/(?:" + REGEX_YEAR + r"))"
5457
REGEX_TIME = r"([01][0-9]|2[0-3]):([0-5][0-9])([AaPp][Mm])?"
58+
REGEX_NOT_ISO_TIME = r"([0-9]|2[0-3]):([0-5][0-9])([AaPp][Mm])?"
5559
REGEX_ORDINALS = r"st|nd|rd|th"
5660

5761
REGEX_AMOUNT = r"(?:\d+x)?\d+k?(?:g|l|ml)"
@@ -244,11 +248,12 @@ def __init__(self,
244248
def update_bbds(self, receipt_list: list):
245249
if self.index_start is None or self.index_end is None:
246250
raise ValueError
247-
delivery_date_raw = re.search(self.regex_date, receipt_list[6])
251+
delivery_date_raw = re.search(self.regex_date, receipt_list[11])
248252
if delivery_date_raw is not None:
249253
delivery_date_raw = delivery_date_raw.group()
250254
else:
251-
delivery_date_raw = re.search(self.regex_date, receipt_list[7])
255+
delivery_date_regex = r"Delivery date:\s(?:" + REGEX_DAY_FULL + r")\s" + REGEX_DATE_FULL
256+
delivery_date_raw = re.search(delivery_date_regex, "\n".join(receipt_list))
252257
if delivery_date_raw is not None:
253258
delivery_date_raw = delivery_date_raw.group()
254259
if delivery_date_raw is None:

custom_components/ocado/manifest.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
"iot_class": "cloud_polling",
1212
"issue_tracker": "https://github.com/PineappleEmperor/ocado-ha/issues",
1313
"requirements": [
14-
"python-dateutil==2.9.0",
15-
"pypdf==5.5.0"
14+
"python-dateutil>=2.9.0",
15+
"pypdf>=5.5.0",
16+
"BeautifulSoup4>=4.10.0"
1617
],
1718
"single_config_entry": true,
18-
"version": "1.1.0"
19+
"version": "1.1.1"
1920
}

custom_components/ocado/sensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ class OcadoBBDs(CoordinatorEntity, SensorEntity): # type: ignore
598598

599599
_attr_device_class = DEVICE_CLASS # type: ignore
600600

601+
# Disabled by default
602+
_attr_entity_registry_enabled_default = False
603+
601604
def __init__(self, coordinator: OcadoUpdateCoordinator, day: str, context: Any = None,) -> None:
602605
"""Initialise the sensor."""
603606
super().__init__(coordinator, context=context) # type: ignore

0 commit comments

Comments
 (0)