Use short hand attributes in onvif camera (#100319)

see #95315
This commit is contained in:
J. Nick Koston 2023-09-13 13:19:01 -05:00 committed by GitHub
parent 7b00265cfe
commit 9631c0ba2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,29 +113,20 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera):
)
self._stream_uri: str | None = None
self._stream_uri_future: asyncio.Future[str] | None = None
self._attr_entity_registry_enabled_default = (
device.max_resolution == profile.video.resolution.width
)
if profile.index:
self._attr_unique_id = f"{self.mac_or_serial}_{profile.index}"
else:
self._attr_unique_id = self.mac_or_serial
self._attr_name = f"{device.name} {profile.name}"
@property
def use_stream_for_stills(self) -> bool:
"""Whether or not to use stream to generate stills."""
return bool(self.stream and self.stream.dynamic_stream_settings.preload_stream)
@property
def name(self) -> str:
"""Return the name of this camera."""
return f"{self.device.name} {self.profile.name}"
@property
def unique_id(self) -> str:
"""Return a unique ID."""
if self.profile.index:
return f"{self.mac_or_serial}_{self.profile.index}"
return self.mac_or_serial
@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return self.device.max_resolution == self.profile.video.resolution.width
async def stream_source(self):
"""Return the stream source."""
return await self._async_get_stream_uri()