From 8aa02ca00a1f6306fa9090d546df77aec56575c3 Mon Sep 17 00:00:00 2001 From: firstof9 Date: Wed, 16 Jun 2021 09:11:32 -0700 Subject: [PATCH 1/3] fix: config flow not loading new config --- custom_components/mail_and_packages/config_flow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/mail_and_packages/config_flow.py b/custom_components/mail_and_packages/config_flow.py index ba0ec104..3cfff287 100644 --- a/custom_components/mail_and_packages/config_flow.py +++ b/custom_components/mail_and_packages/config_flow.py @@ -409,6 +409,7 @@ async def _show_step_options_2(self, user_input): CONF_GENERATE_MP4: self._data.get(CONF_GENERATE_MP4), CONF_ALLOW_EXTERNAL: self._data.get(CONF_ALLOW_EXTERNAL), CONF_RESOURCES: self._data.get(CONF_RESOURCES), + CONF_CUSTOM_IMG: self._data.get(CONF_CUSTOM_IMG) or DEFAULT_CUSTOM_IMG, } return self.async_show_form( @@ -434,7 +435,8 @@ async def _show_step_options_3(self, user_input): # Defaults defaults = { - CONF_CUSTOM_IMG_FILE: DEFAULT_CUSTOM_IMG_FILE, + CONF_CUSTOM_IMG_FILE: self._data.get(CONF_CUSTOM_IMG_FILE) + or DEFAULT_CUSTOM_IMG_FILE, } return self.async_show_form( From 5e901e6a2b635b0bfb5cdea76570fce8cae475cf Mon Sep 17 00:00:00 2001 From: firstof9 Date: Wed, 16 Jun 2021 09:39:28 -0700 Subject: [PATCH 2/3] fix: adjust file path generation for new option * Fix/adjust tests to properly test new option * Add a more debugging to camera.py --- custom_components/mail_and_packages/camera.py | 6 +++- .../mail_and_packages/helpers.py | 5 ++-- tests/test_camera.py | 29 +++++++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/custom_components/mail_and_packages/camera.py b/custom_components/mail_and_packages/camera.py index 252c86c6..6dee4ae4 100644 --- a/custom_components/mail_and_packages/camera.py +++ b/custom_components/mail_and_packages/camera.py @@ -32,7 +32,10 @@ async def async_setup_entry(hass, config, async_add_entities): coordinator = hass.data[DOMAIN][config.entry_id][COORDINATOR] camera = [] - file_path = f"{os.path.dirname(__file__)}/mail_none.gif" + if not config.data.get(CONF_CUSTOM_IMG): + file_path = f"{os.path.dirname(__file__)}/mail_none.gif" + else: + file_path = config.data.get(CONF_CUSTOM_IMG_FILE) for variable in CAMERA_DATA: temp_cam = MailCam(hass, variable, config, coordinator, file_path) @@ -124,6 +127,7 @@ def update_file_path(self) -> None: """Update the file_path.""" _LOGGER.debug("Camera Update: %s", self._type) + _LOGGER.debug("Custom No Mail: %s", self._no_mail) if self._type == "usps_camera": # Update camera image for USPS informed delivery imgages diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 0fb8bdcc..0f5c7986 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -192,10 +192,11 @@ def image_file_name( else: if config.get(const.CONF_CUSTOM_IMG): mail_none = config.get(const.CONF_CUSTOM_IMG_FILE) + path, image_name = os.path.split(mail_none) else: mail_none = f"{os.path.dirname(__file__)}/mail_none.gif" - image_name = "mail_none.gif" - path = f"{hass.config.path()}/{config.get(const.CONF_PATH)}" + image_name = "mail_none.gif" + path = f"{hass.config.path()}/{config.get(const.CONF_PATH)}" # Path check path_check = os.path.exists(path) diff --git a/tests/test_camera.py b/tests/test_camera.py index 7faa1db6..f7f51ffd 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -5,7 +5,7 @@ from pytest_homeassistant_custom_component.common import MockConfigEntry from custom_components.mail_and_packages.const import CAMERA, DOMAIN -from tests.const import FAKE_CONFIG_DATA +from tests.const import FAKE_CONFIG_DATA, FAKE_CONFIG_DATA_CUSTOM_IMG _LOGGER = logging.getLogger(__name__) @@ -33,6 +33,7 @@ async def test_update_file_path( entry.add_to_hass(hass) assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() + entries = hass.config_entries.async_entries(DOMAIN) with patch("os.path.isfile", return_value=True), patch( "os.access", return_value=True @@ -61,7 +62,31 @@ async def test_update_file_path( in state.attributes.get("file_path") ) - # TODO: Add process_mail and check camera file path + # Unload the config + await hass.config_entries.async_unload(entries[0].entry_id) + await hass.async_block_till_done() + await hass.config_entries.async_remove(entries[0].entry_id) + await hass.async_block_till_done() + + # Load new config with custom img settings + entry = MockConfigEntry( + domain=DOMAIN, + title="imap.test.email", + data=FAKE_CONFIG_DATA_CUSTOM_IMG, + ) + + entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + with patch("os.path.isfile", return_value=True), patch( + "os.access", return_value=True + ): + state = hass.states.get("camera.mail_usps_camera") + assert state.attributes.get("friendly_name") == "Mail USPS Camera" + assert "images/test.gif" in state.attributes.get("file_path") + + # TODO: Add process_mail and check camera file path async def test_check_file_path_access( From 1c9e8e0895938adf9eccfcd62c8829d0451c22cf Mon Sep 17 00:00:00 2001 From: firstof9 Date: Wed, 16 Jun 2021 10:10:15 -0700 Subject: [PATCH 3/3] fix(translations): adjust wording on new option --- custom_components/mail_and_packages/strings.json | 4 ++-- custom_components/mail_and_packages/translations/en.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/mail_and_packages/strings.json b/custom_components/mail_and_packages/strings.json index a0363840..81084071 100644 --- a/custom_components/mail_and_packages/strings.json +++ b/custom_components/mail_and_packages/strings.json @@ -34,7 +34,7 @@ "generate_mp4": "Create mp4 from images", "amazon_fwds": "Amazon fowarded email addresses", "allow_external": "Create image for notification apps", - "custom_img": "Use custom 'no image' file?" + "custom_img": "Use custom 'no image' image?" }, "description": "Finish the configuration by customizing the following based on your email structure and Home Assistant installation.\n\nFor details on the [Mail and Packages integration](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) options review the [configuration, templates, and automations section](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) on GitHub.\n\nIf using Amazon forwarded emails please seperate each address with a comma.", "title": "Mail and Packages (Step 2 of 2)" @@ -79,7 +79,7 @@ "generate_mp4": "Create mp4 from images", "amazon_fwds": "Amazon fowarded email addresses", "allow_external": "Create image for notification apps", - "custom_img": "Use custom 'no image' file?" + "custom_img": "Use custom 'no image' image?" }, "description": "Finish the configuration by customizing the following based on your email structure and Home Assistant installation.\n\nFor details on the [Mail and Packages integration](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) options review the [configuration, templates, and automations section](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) on GitHub.\n\nIf using Amazon forwarded emails please seperate each address with a comma.", "title": "Mail and Packages (Step 2 of 2)" diff --git a/custom_components/mail_and_packages/translations/en.json b/custom_components/mail_and_packages/translations/en.json index a0363840..81084071 100644 --- a/custom_components/mail_and_packages/translations/en.json +++ b/custom_components/mail_and_packages/translations/en.json @@ -34,7 +34,7 @@ "generate_mp4": "Create mp4 from images", "amazon_fwds": "Amazon fowarded email addresses", "allow_external": "Create image for notification apps", - "custom_img": "Use custom 'no image' file?" + "custom_img": "Use custom 'no image' image?" }, "description": "Finish the configuration by customizing the following based on your email structure and Home Assistant installation.\n\nFor details on the [Mail and Packages integration](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) options review the [configuration, templates, and automations section](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) on GitHub.\n\nIf using Amazon forwarded emails please seperate each address with a comma.", "title": "Mail and Packages (Step 2 of 2)" @@ -79,7 +79,7 @@ "generate_mp4": "Create mp4 from images", "amazon_fwds": "Amazon fowarded email addresses", "allow_external": "Create image for notification apps", - "custom_img": "Use custom 'no image' file?" + "custom_img": "Use custom 'no image' image?" }, "description": "Finish the configuration by customizing the following based on your email structure and Home Assistant installation.\n\nFor details on the [Mail and Packages integration](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) options review the [configuration, templates, and automations section](https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#configuration) on GitHub.\n\nIf using Amazon forwarded emails please seperate each address with a comma.", "title": "Mail and Packages (Step 2 of 2)"