-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dahua profile setting #246
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
89edb14
refactor: rename jovision_profile to substream
NiklasNeugebauer aaab564
feat: add deprecation decorator
NiklasNeugebauer e097f24
refactor: rename jovision_profile to substream
NiklasNeugebauer 67087b5
style: add explicit stacklevel argument
NiklasNeugebauer f8b51b7
fix: remove `DeprecationWarning` class to make sure users see it
NiklasNeugebauer cb8a308
warn when using parameter getter and setter
NiklasNeugebauer dfb00d7
improve type annotation and docstring
falkoschindler e5040a4
add filter to show deprecation warnings
falkoschindler 07010c6
logging: add `DeprecationWarning` category to other warnings
NiklasNeugebauer 776b9a3
logging: add deprecation warning to provider
NiklasNeugebauer 3a91cc4
add version to deprecation warning
NiklasNeugebauer 6b7b876
remove `get_jovision_profile`
NiklasNeugebauer fa21f67
text: add "Rosys" to deprecation warning
NiklasNeugebauer 560d0f1
docs: add DEPRECATED comment
NiklasNeugebauer d180ffd
refactor: add `deprecated_function` decorator
NiklasNeugebauer e83d9b9
feat: ensure substream is updated with jovision_profile
NiklasNeugebauer 1539366
fix: get profile first and also set in in setter
NiklasNeugebauer cd28bba
style: remove unused import
NiklasNeugebauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import warnings | ||
from collections.abc import Callable | ||
from functools import wraps | ||
|
||
|
||
def deprecated_param(param_name: str, *, remove_in_version: str | None = None) -> Callable: | ||
"""Mark a function parameter as deprecated.""" | ||
def decorator(func: Callable) -> Callable: | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
if param_name in kwargs: | ||
warnings.warn( | ||
f'The parameter "{param_name}" is deprecated and will be removed in {"Rosys " + remove_in_version if remove_in_version else "a future version"}.', | ||
category=DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return func(*args, **kwargs) | ||
return wrapper | ||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import logging | ||
import warnings | ||
from typing import Any | ||
|
||
from typing_extensions import Self | ||
|
||
from ... import rosys | ||
from ...helpers.deprecation import deprecated_param | ||
from ..camera.configurable_camera import ConfigurableCamera | ||
from ..camera.transformable_camera import TransformableCamera | ||
from ..image import Image | ||
|
@@ -13,13 +15,15 @@ | |
|
||
class RtspCamera(ConfigurableCamera, TransformableCamera): | ||
|
||
@deprecated_param('jovision_profile', remove_in_version='0.27.0') | ||
def __init__(self, | ||
*, | ||
id: str, # pylint: disable=redefined-builtin | ||
name: str | None = None, | ||
connect_after_init: bool = True, | ||
fps: int = 5, | ||
jovision_profile: int = 1, | ||
substream: int = 1, | ||
jovision_profile: int | None = None, | ||
bitrate: int = 4096, | ||
ip: str | None = None, | ||
**kwargs, | ||
|
@@ -34,22 +38,31 @@ def __init__(self, | |
self.device: RtspDevice | None = None | ||
self.ip: str | None = ip | ||
|
||
self._register_parameter('jovision_profile', self.get_jovision_profile, self.set_jovision_profile, | ||
min_value=0, max_value=1, step=1, default_value=jovision_profile) | ||
self.substream = jovision_profile or substream | ||
self._register_parameter('jovision_profile', self.get_substream, self.set_jovision_profile, | ||
min_value=0, max_value=1, step=1, default_value=substream) | ||
self._register_parameter('substream', self.get_substream, self.set_substream, | ||
min_value=0, max_value=1, step=1, default_value=substream) | ||
self._register_parameter('fps', self.get_fps, self.set_fps, | ||
min_value=1, max_value=30, step=1, default_value=fps) | ||
self._register_parameter('bitrate', self.get_bitrate, self.set_bitrate, | ||
min_value=32, max_value=8192, step=1, default_value=bitrate) | ||
|
||
def to_dict(self) -> dict[str, Any]: | ||
return super().to_dict() | { | ||
parameters = { | ||
name: param.value for name, param in self._parameters.items() | ||
} | { | ||
} | ||
if 'jovision_profile' in parameters: | ||
parameters['substream'] = parameters['jovision_profile'] | ||
del parameters['jovision_profile'] | ||
return super().to_dict() | parameters | { | ||
'ip': self.ip, | ||
} | ||
|
||
@classmethod | ||
def from_dict(cls, data: dict[str, Any]) -> Self: | ||
if 'jovision_profile' in data: | ||
data['substream'] = data['jovision_profile'] | ||
return cls(**data) | ||
|
||
@property | ||
|
@@ -73,7 +86,7 @@ async def connect(self) -> None: | |
return | ||
|
||
self.device = RtspDevice(mac=self.id, ip=self.ip, | ||
jovision_profile=self.parameters['jovision_profile'], | ||
substream=self.parameters['jovision_profile'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it correct to access |
||
fps=self.parameters['fps'], | ||
on_new_image_data=self._handle_new_image_data) | ||
|
||
|
@@ -113,15 +126,24 @@ async def get_fps(self) -> int | None: | |
|
||
return await self.device.get_fps() | ||
|
||
# DEPRECATED: 0.27.0 | ||
def set_jovision_profile(self, profile: int) -> None: | ||
assert self.device is not None | ||
warnings.warn('setting jovision_profile is deprecated, use "substream" instead', | ||
category=DeprecationWarning, | ||
stacklevel=3) | ||
|
||
self.device.set_substream(profile) | ||
|
||
def set_substream(self, index: int) -> None: | ||
assert self.device is not None | ||
|
||
self.device.set_jovision_profile(profile) | ||
self.device.set_substream(index) | ||
|
||
def get_jovision_profile(self) -> int | None: | ||
def get_substream(self) -> int | None: | ||
assert self.device is not None | ||
|
||
return self.device.get_jovision_profile() | ||
return self.device.get_substream() | ||
|
||
async def set_bitrate(self, bitrate: int) -> None: | ||
assert self.device is not None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will look funny if
remove_in_version
isNone
:"...and will be removed in Rosys a future version."
By the way, it's "RoSys" with an uppercase "S".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, that should have parentheses. Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm wrong.
if
has higher precedence, so it should already work correctly.