|
2 | 2 | from collections.abc import Callable |
3 | 3 | import logging |
4 | 4 |
|
5 | | -from homeassistant.components.camera import ENTITY_ID_FORMAT, Camera |
| 5 | +from homeassistant.components.camera import ( |
| 6 | + ENTITY_ID_FORMAT, |
| 7 | + Camera, |
| 8 | + CameraEntityFeature, |
| 9 | +) |
6 | 10 | from homeassistant.config_entries import ConfigEntry |
7 | 11 | from homeassistant.core import HomeAssistant |
8 | 12 | from homeassistant.helpers import entity_platform |
|
16 | 20 | ATTR_PTZ_VERTICAL, |
17 | 21 | ATTR_PTZ_ZOOM, |
18 | 22 | DOMAIN, |
| 23 | + ENABLED_CAMERAS, |
19 | 24 | SERVIZE_PTZ_LOCATION, |
20 | 25 | SERVIZE_PTZ_MOVE, |
21 | 26 | ) |
@@ -70,12 +75,35 @@ async def async_setup_entry( |
70 | 75 | class ImouCamera(ImouEntity, Camera): |
71 | 76 | """imou camera class.""" |
72 | 77 |
|
| 78 | + _attr_supported_features = CameraEntityFeature.STREAM |
| 79 | + |
73 | 80 | def __init__(self, coordinator, config_entry, sensor_instance, entity_format): |
74 | 81 | """Initialize.""" |
| 82 | + Camera.__init__(self) |
75 | 83 | ImouEntity.__init__( |
76 | 84 | self, coordinator, config_entry, sensor_instance, entity_format |
77 | 85 | ) |
78 | | - Camera.__init__(self) |
| 86 | + |
| 87 | + @property |
| 88 | + def entity_registry_enabled_default(self) -> bool: |
| 89 | + """If the entity is enabled by default.""" |
| 90 | + return self.sensor_instance.get_name() in ENABLED_CAMERAS |
| 91 | + |
| 92 | + async def async_camera_image(self, width=None, height=None) -> bytes: |
| 93 | + """Return bytes of camera image.""" |
| 94 | + _LOGGER.debug( |
| 95 | + "[%s] requested camera image", |
| 96 | + self.device.get_name(), |
| 97 | + ) |
| 98 | + return await self.sensor_instance.async_get_image() |
| 99 | + |
| 100 | + async def stream_source(self) -> str: |
| 101 | + """Return the source of the stream.""" |
| 102 | + _LOGGER.debug( |
| 103 | + "[%s] requested camera stream url", |
| 104 | + self.device.get_name(), |
| 105 | + ) |
| 106 | + return await self.sensor_instance.async_get_stream_url() |
79 | 107 |
|
80 | 108 | async def async_service_ptz_location(self, horizontal, vertical, zoom): |
81 | 109 | """Perform PTZ location action.""" |
@@ -104,7 +132,3 @@ async def async_service_ptz_move(self, operation, duration): |
104 | 132 | operation, |
105 | 133 | duration, |
106 | 134 | ) |
107 | | - |
108 | | - async def async_camera_image(self, width=None, height=None): |
109 | | - """Return bytes of camera image.""" |
110 | | - return None |
|
0 commit comments