From 54c5f18aac1a6df29fbb8b0ca29095932abb2b32 Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Fri, 29 Mar 2024 14:04:24 +0000 Subject: [PATCH] Add `uid` attribute to `imap_content` event data (#114432) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add uid to imap event * Add ´uid´ to tests * Update test_init.py --- homeassistant/components/imap/coordinator.py | 1 + tests/components/imap/test_init.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/homeassistant/components/imap/coordinator.py b/homeassistant/components/imap/coordinator.py index 78b52e06db3..f7f2ef457c7 100644 --- a/homeassistant/components/imap/coordinator.py +++ b/homeassistant/components/imap/coordinator.py @@ -264,6 +264,7 @@ class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]): "sender": message.sender, "subject": message.subject, "headers": message.headers, + "uid": last_message_uid, } if self.custom_event_template is not None: try: diff --git a/tests/components/imap/test_init.py b/tests/components/imap/test_init.py index 8608963413a..aba9bd88c44 100644 --- a/tests/components/imap/test_init.py +++ b/tests/components/imap/test_init.py @@ -164,6 +164,7 @@ async def test_receiving_message_successfully( assert data["folder"] == "INBOX" assert data["sender"] == "john.doe@example.com" assert data["subject"] == "Test subject" + assert data["uid"] == "1" assert "Test body" in data["text"] assert ( valid_date @@ -213,6 +214,7 @@ async def test_receiving_message_with_invalid_encoding( assert data["sender"] == "john.doe@example.com" assert data["subject"] == "Test subject" assert data["text"] == TEST_BADLY_ENCODED_CONTENT + assert data["uid"] == "1" @pytest.mark.parametrize("imap_search", [TEST_SEARCH_RESPONSE]) @@ -251,6 +253,7 @@ async def test_receiving_message_no_subject_to_from( assert data["text"] == "Test body\r\n" assert data["headers"]["Return-Path"] == ("",) assert data["headers"]["Delivered-To"] == ("notify@example.com",) + assert data["uid"] == "1" @pytest.mark.parametrize("imap_has_capability", [True, False], ids=["push", "poll"])