1 """Camera entity for PrusaLink."""
3 from __future__
import annotations
5 from pyprusalink.types
import PrinterState
12 from .const
import DOMAIN
13 from .coordinator
import JobUpdateCoordinator
14 from .entity
import PrusaLinkEntity
20 async_add_entities: AddEntitiesCallback,
22 """Set up PrusaLink camera."""
23 coordinator: JobUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
"job"]
28 """Defines a PrusaLink camera."""
32 _attr_translation_key =
"job_preview"
34 def __init__(self, coordinator: JobUpdateCoordinator) ->
None:
35 """Initialize a PrusaLink camera entity."""
38 self.
_attr_unique_id_attr_unique_id = f
"{self.coordinator.config_entry.entry_id}_job_preview"
42 """Get if camera is available."""
45 and self.coordinator.data.get(
"state") != PrinterState.IDLE.value
46 and (file := self.coordinator.data.get(
"file"))
47 and file.get(
"refs", {}).
get(
"thumbnail")
51 self, width: int |
None =
None, height: int |
None =
None
53 """Return a still image from the camera."""
57 path = self.coordinator.data[
"file"][
"refs"][
"thumbnail"]
62 self.
last_imagelast_image = await self.coordinator.api.get_file(path)
None __init__(self, JobUpdateCoordinator coordinator)
bytes|None async_camera_image(self, int|None width=None, int|None height=None)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)