Update image entity documentation (#1821)

This commit is contained in:
Erik Montnemery 2023-06-28 10:41:23 +02:00 committed by GitHub
parent 9d61a2d9fd
commit a06dab27d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,8 @@ An image entity can display a static image. Derive a platform entity from [`home
The image entity is a simplified version of the [`camera`](/docs/core/entity/camera) entity, and supports serving a static image or an image URL that can be fetched.
An implementation can provide either a URL from where an image will automatically be fetched or image data as `bytes`. When providing a URL, the fetched image will be cached in `self._cached_image`, set `self._cached_image` to `None` to invalidate the cache.
To make frontend refetch the image, bump the `image_last_updated` property.
## Properties
@ -16,14 +18,16 @@ Properties should always only return information from memory and not do I/O (lik
:::
| Name | Type | Default | Description |
| ------------------------ | ----- | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| ------------------------ | --------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| content_type | str | `image/jpeg` | The content-type of the image, set automatically if the image entity provides a URL. |
| image_last_updated | datetime | `None` | Timestamp of when the image was last updated. Used to determine `state`. |
| image_url | str or None | `UNDEFINED` | Optional URL from where the image should be fetched. |
## Methods
### Image
Return bytes of the image.
Implement if your entity returns bytes of the image instead of providing a URL.
```python
class MyImage(ImageEntity):
@ -35,18 +39,3 @@ class MyImage(ImageEntity):
async def async_image(self) -> bytes | None:
"""Return bytes of image."""
```
Return the URL of an image to be fetched.
```python
class MyImage(ImageEntity):
# Implement one of these methods.
def image_url(self) -> str | None:
"""Return URL of image."""
async def async_image_url(self) -> str | None:
"""Return URL of image."""
```
By default `image_url` or `async_image_url` return `None`, and `async_image` or `image` will be called expecting to return the bytes of the image.