Address late review comments on image entity URL support (#95338)
parent
968bc25259
commit
723f6d35b0
|
@ -167,10 +167,7 @@ class ImageEntity(Entity):
|
||||||
"""Return bytes of image."""
|
"""Return bytes of image."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_image(self) -> bytes | None:
|
async def _async_load_image_from_url(self, url: str) -> Image | None:
|
||||||
"""Return bytes of image."""
|
|
||||||
|
|
||||||
async def _async_load_image_from_url(url: str) -> Image | None:
|
|
||||||
"""Load an image by url."""
|
"""Load an image by url."""
|
||||||
try:
|
try:
|
||||||
response = await self._client.get(
|
response = await self._client.get(
|
||||||
|
@ -193,10 +190,13 @@ class ImageEntity(Entity):
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
async def async_image(self) -> bytes | None:
|
||||||
|
"""Return bytes of image."""
|
||||||
|
|
||||||
if self._cached_image:
|
if self._cached_image:
|
||||||
return self._cached_image.content
|
return self._cached_image.content
|
||||||
if (url := self.image_url) is not UNDEFINED:
|
if (url := self.image_url) is not UNDEFINED:
|
||||||
if not url or (image := await _async_load_image_from_url(url)) is None:
|
if not url or (image := await self._async_load_image_from_url(url)) is None:
|
||||||
return None
|
return None
|
||||||
self._cached_image = image
|
self._cached_image = image
|
||||||
self._attr_content_type = image.content_type
|
self._attr_content_type = image.content_type
|
||||||
|
|
Loading…
Reference in New Issue