Skip to content

Commit

Permalink
feat(shipper): add evri carrier (#720)
Browse files Browse the repository at this point in the history
* feat(shipper): add evri carrier

* linting
  • Loading branch information
firstof9 authored Sep 16, 2022
1 parent 6f319a7 commit 772b0fc
Show file tree
Hide file tree
Showing 6 changed files with 552 additions and 22 deletions.
30 changes: 30 additions & 0 deletions custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@
},
"auspost_packages": {},
"auspost_tracking": {"pattern": ["\\d{7,10,12}|[A-Za-z]{2}[0-9]{9}AU "]},
# Evri
"evri_delivered": {
"email": ["[email protected]"],
"subject": ["successfully delivered"],
},
"evri_delivering": {
"email": ["[email protected]"],
"subject": ["is now with your local Evri courier for delivery"],
},
"evri_packages": {},
"evri_tracking": {"pattern": ["H[0-9A-Z]{15}"]},
}

# Sensor definitions
Expand Down Expand Up @@ -670,6 +681,25 @@
icon="mdi:package-variant-closed",
key="gls_packages",
),
# Evri
"evri_delivered": SensorEntityDescription(
name="Mail Evri Delivered",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="evri_delivered",
),
"evri_delivering": SensorEntityDescription(
name="Mail Evri Delivering",
native_unit_of_measurement="package(s)",
icon="mdi:truck-delivery",
key="evri_delivering",
),
"evri_packages": SensorEntityDescription(
name="Mail Evri Packages",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="evri_packages",
),
###
# !!! Insert new sensors above these two !!!
###
Expand Down
32 changes: 31 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ def mock_image_excpetion():
mock_image_excpetion.open.side_effect = Exception("SystemError")
yield mock_image_excpetion


@pytest.fixture
def mock_image_save_excpetion():
"""Fixture to mock Image."""
Expand All @@ -946,12 +947,15 @@ def mock_image_save_excpetion():
mock_image_save_excpetion.Image.save.side_effect = Exception("ValueError")
yield mock_image_save_excpetion


@pytest.fixture
def mock_resizeimage():
"""Fixture to mock splitext."""
with patch(
"custom_components.mail_and_packages.helpers.Image"
) as mock_resizeimage, patch("custom_components.mail_and_packages.helpers.ImageOps"):
) as mock_resizeimage, patch(
"custom_components.mail_and_packages.helpers.ImageOps"
):

yield mock_resizeimage

Expand Down Expand Up @@ -1034,6 +1038,32 @@ def mock_imap_hermes_out_for_delivery():
yield mock_conn


@pytest.fixture()
def mock_imap_evri_out_for_delivery():
"""Mock imap class values."""
with patch(
"custom_components.mail_and_packages.helpers.imaplib"
) as mock_imap_evri_out_for_delivery:
mock_conn = mock.Mock(spec=imaplib.IMAP4_SSL)
mock_imap_evri_out_for_delivery.IMAP4_SSL.return_value = mock_conn

mock_conn.login.return_value = (
"OK",
[b"[email protected] authenticated (Success)"],
)
mock_conn.list.return_value = (
"OK",
[b'(\\HasNoChildren) "/" "INBOX"'],
)
mock_conn.search.return_value = ("OK", [b"1"])
mock_conn.uid.return_value = ("OK", [b"1"])
f = open("tests/test_emails/evri_out_for_delivery.eml", "r")
email_file = f.read()
mock_conn.fetch.return_value = ("OK", [(b"", email_file.encode("utf-8"))])
mock_conn.select.return_value = ("OK", [])
yield mock_conn


@pytest.fixture()
def mock_imap_royal_out_for_delivery():
"""Mock imap class values."""
Expand Down
Loading

0 comments on commit 772b0fc

Please sign in to comment.