Enforce CameraEntityFeature (#82325)

This commit is contained in:
epenet 2022-11-22 07:08:28 +01:00 committed by GitHub
parent 7df711f1f3
commit 8b54a0679f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 10 deletions

View File

@ -429,7 +429,7 @@ class Camera(Entity):
_attr_motion_detection_enabled: bool = False _attr_motion_detection_enabled: bool = False
_attr_should_poll: bool = False # No need to poll cameras _attr_should_poll: bool = False # No need to poll cameras
_attr_state: None = None # State is determined by is_on _attr_state: None = None # State is determined by is_on
_attr_supported_features: CameraEntityFeature | int = 0 _attr_supported_features: CameraEntityFeature = CameraEntityFeature(0)
def __init__(self) -> None: def __init__(self) -> None:
"""Initialize a camera.""" """Initialize a camera."""
@ -450,7 +450,7 @@ class Camera(Entity):
return ENTITY_IMAGE_URL.format(self.entity_id, self.access_tokens[-1]) return ENTITY_IMAGE_URL.format(self.entity_id, self.access_tokens[-1])
@property @property
def supported_features(self) -> CameraEntityFeature | int: def supported_features(self) -> CameraEntityFeature:
"""Flag supported features.""" """Flag supported features."""
return self._attr_supported_features return self._attr_supported_features

View File

@ -95,9 +95,9 @@ class NestCamera(Camera):
return self._device_info.device_model return self._device_info.device_model
@property @property
def supported_features(self) -> int: def supported_features(self) -> CameraEntityFeature:
"""Flag supported features.""" """Flag supported features."""
supported_features = 0 supported_features = CameraEntityFeature(0)
if CameraLiveStreamTrait.NAME in self._device.traits: if CameraLiveStreamTrait.NAME in self._device.traits:
supported_features |= CameraEntityFeature.STREAM supported_features |= CameraEntityFeature.STREAM
return supported_features return supported_features

View File

@ -175,9 +175,10 @@ class ProtectCamera(ProtectDeviceEntity, Camera):
self._stream_source = ( # pylint: disable=attribute-defined-outside-init self._stream_source = ( # pylint: disable=attribute-defined-outside-init
None if disable_stream else rtsp_url None if disable_stream else rtsp_url
) )
self._attr_supported_features = ( if self._stream_source:
CameraEntityFeature.STREAM if self._stream_source else 0 self._attr_supported_features = CameraEntityFeature.STREAM
) else:
self._attr_supported_features = CameraEntityFeature(0)
@callback @callback
def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None: def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None:

View File

@ -107,14 +107,14 @@ class UnifiVideoCamera(Camera):
return self._name return self._name
@property @property
def supported_features(self) -> CameraEntityFeature | int: def supported_features(self) -> CameraEntityFeature:
"""Return supported features.""" """Return supported features."""
channels = self._caminfo["channels"] channels = self._caminfo["channels"]
for channel in channels: for channel in channels:
if channel["isRtspEnabled"]: if channel["isRtspEnabled"]:
return CameraEntityFeature.STREAM return CameraEntityFeature.STREAM
return 0 return CameraEntityFeature(0)
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):

View File

@ -803,7 +803,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
), ),
TypeHintMatch( TypeHintMatch(
function_name="supported_features", function_name="supported_features",
return_type=["CameraEntityFeature", "int"], return_type="CameraEntityFeature",
), ),
TypeHintMatch( TypeHintMatch(
function_name="is_recording", function_name="is_recording",