Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use homeassistant network helper to set image url sensor #1046

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions custom_components/mail_and_packages/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_RESOURCES
from homeassistant.core import HomeAssistant
from homeassistant.helpers.network import get_url
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import (
Expand Down Expand Up @@ -195,21 +196,12 @@ def native_value(self) -> Optional[str]:
path = self._config.data[CONF_PATH]

if self.type == "usps_mail_image_system_path":
_LOGGER.debug("Updating system image path to: %s", path)
the_path = f"{self.hass.config.path()}/{path}{image}"
_LOGGER.debug("Updating system image path to: %s", the_path)
elif self.type == "usps_mail_image_url":
if (
self.hass.config.external_url is None
and self.hass.config.internal_url is None
):
the_path = None
elif self.hass.config.external_url is None:
_LOGGER.debug("External URL not set in configuration.")
url = self.hass.config.internal_url
the_path = f"{url.rstrip('/')}/local/mail_and_packages/{image}"
else:
url = self.hass.config.external_url
the_path = f"{url.rstrip('/')}/local/mail_and_packages/{image}"
url = get_url(self.hass, prefer_external=True)
the_path = f"{url.rstrip('/')}/local/mail_and_packages/{image}"
_LOGGER.debug("Updating image url to: %s", the_path)
return the_path

@property
Expand Down
Loading