Skip to content

Commit

Permalink
fix: custom no mail image config not loading and not displaying (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Jun 16, 2021
2 parents c21580c + 1c9e8e0 commit 31fed6f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
6 changes: 5 additions & 1 deletion custom_components/mail_and_packages/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion custom_components/mail_and_packages/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/mail_and_packages/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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)"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/mail_and_packages/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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)"
Expand Down
29 changes: 27 additions & 2 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 31fed6f

Please sign in to comment.