From d6c4c0c340bfe0b3952fc3368ffe27242d4d245b Mon Sep 17 00:00:00 2001 From: ruz4fe Date: Wed, 6 Mar 2024 16:15:28 +0100 Subject: [PATCH] Continuous subscription at a specific frequency --- kuksa-client/kuksa_client/grpc/__init__.py | 7 ++++--- kuksa-client/kuksa_client/grpc/aio.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kuksa-client/kuksa_client/grpc/__init__.py b/kuksa-client/kuksa_client/grpc/__init__.py index 7799592..22bf7ae 100644 --- a/kuksa-client/kuksa_client/grpc/__init__.py +++ b/kuksa-client/kuksa_client/grpc/__init__.py @@ -136,7 +136,6 @@ def from_grpc_error(cls, error: RpcError): def to_dict(self) -> Dict[str, Any]: return {'error': self.error, 'errors': self.errors} - @dataclasses.dataclass class ValueRestriction: min: Optional[Any] = None @@ -959,7 +958,7 @@ def set(self, updates: Collection[EntryUpdate], **rpc_kwargs) -> None: self._process_set_response(resp) @check_connected - def subscribe(self, entries: Iterable[SubscribeEntry], **rpc_kwargs) -> Iterator[List[EntryUpdate]]: + def subscribe(self, entries: Iterable[SubscribeEntry], frequency: Optional[int], **rpc_kwargs) -> Iterator[List[EntryUpdate]]: """ Parameters: rpc_kwargs @@ -969,6 +968,8 @@ def subscribe(self, entries: Iterable[SubscribeEntry], **rpc_kwargs) -> Iterator rpc_kwargs["metadata"] = self.generate_metadata_header( rpc_kwargs.get("metadata")) req = self._prepare_subscribe_request(entries) + if frequency is not None: + req.frequency_hertz = frequency resp_stream = self.client_stub.Subscribe(req, **rpc_kwargs) try: for resp in resp_stream: @@ -1034,4 +1035,4 @@ def get_value_types(self, paths: Collection[str], **rpc_kwargs) -> Dict[str, Dat ) for path in paths) entries = self.get(entries=entry_requests, **rpc_kwargs) return {entry.path: DataType(entry.metadata.data_type) for entry in entries} - return {} + return {} \ No newline at end of file diff --git a/kuksa-client/kuksa_client/grpc/aio.py b/kuksa-client/kuksa_client/grpc/aio.py index 6661aab..cd61123 100644 --- a/kuksa-client/kuksa_client/grpc/aio.py +++ b/kuksa-client/kuksa_client/grpc/aio.py @@ -333,6 +333,7 @@ async def set(self, updates: Collection[EntryUpdate], **rpc_kwargs) -> None: @check_connected_async_iter async def subscribe(self, entries: Iterable[SubscribeEntry], + frequency: Optional[int], **rpc_kwargs, ) -> AsyncIterator[List[EntryUpdate]]: """ @@ -343,6 +344,8 @@ async def subscribe(self, rpc_kwargs["metadata"] = self.generate_metadata_header( rpc_kwargs.get("metadata")) req = self._prepare_subscribe_request(entries) + if frequency is not None: + req.frequency_hertz = frequency resp_stream = self.client_stub.Subscribe(req, **rpc_kwargs) try: async for resp in resp_stream: