Skip to content
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

Feature: Add PublishValue and Subscribe from kuksa.val.v2 #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1261aee
.gitmodules
lukasmittag Sep 2, 2024
fae987d
Extend building documentation
lukasmittag Sep 2, 2024
41726d9
Make subscribe call and set_current_values call using the kuksa.val.v…
lukasmittag Sep 5, 2024
c6ade4f
Fix Dockerfile and build process
lukasmittag Sep 10, 2024
1ce2b2d
Fix tests
lukasmittag Sep 10, 2024
48edfae
Another fix
lukasmittag Sep 10, 2024
3f44b36
Exclude proto copy and initialization to separate script
lukasmittag Sep 12, 2024
3139d64
Initiate submodule before checking out branch
lukasmittag Sep 13, 2024
7815a36
Initiate in same call as updating submodule
lukasmittag Sep 13, 2024
b090388
Debug enable for submodules
lukasmittag Sep 13, 2024
db15536
Debug enable for submodules
lukasmittag Sep 13, 2024
5bc4768
Fetch repository
lukasmittag Sep 13, 2024
6c26c35
Show repo structure
lukasmittag Sep 13, 2024
a25920d
Complete sumodule structure
lukasmittag Sep 13, 2024
4fedc61
Fetch remote refs
lukasmittag Sep 13, 2024
40d9447
Fetch remote refs
lukasmittag Sep 13, 2024
89a43f1
Update fetch-depth
lukasmittag Sep 13, 2024
cc19d2c
Finish fixing tests
lukasmittag Sep 25, 2024
e31ef8a
Backwards compatibility if v2 is not present
lukasmittag Sep 30, 2024
445a5da
Update grpcio dependencies
lukasmittag Sep 30, 2024
3ac17a4
Change to eclips kuksa branch again
lukasmittag Oct 1, 2024
3563fc3
Adapt to failure value removal in proto file
lukasmittag Oct 1, 2024
0232a52
Rename version flag
lukasmittag Oct 4, 2024
210f71d
Rename flag part 2
lukasmittag Oct 4, 2024
a0f88c7
Rename flag part 3
lukasmittag Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/kuksa-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ jobs:
- name: Checkout kuksa-python-sdk
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'true'
- name: Install pip
run: |
python -m pip --quiet --no-input install --upgrade pip
- name: Initiate submodules
run: |
git submodule update --remote
- name: Install dependencies with pip
run: |
cd kuksa-client
python3 -m proto
pip install -r requirements.txt -e .
pip install -r test-requirements.txt
- name: Run tests
Expand Down
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "submodules/kuksa-databroker"]


[submodule "kuksa-databroker"]
path = submodules/kuksa-databroker
url = https://github.com/eclipse-kuksa/kuksa-databroker
url = https://github.com/eclipse-kuksa/kuksa-databroker.git
branch = feature/databroker-api-v2
12 changes: 12 additions & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ git submodule update --init
cd kuksa-client
```

Hint: If you want to use another branch than master exchange the first command with

```console
git submodule update --recursive --remote --init
```

First we suggest you create a dedicated [python virtual environment](https://docs.python.org/3/library/venv.html) for kuksa-client:

```console
Expand All @@ -15,6 +21,12 @@ python3 -m venv ~/.venv/kuksa-client
source ~/.venv/kuksa-client/bin/activate # Run this every time you want to activate kuksa-client's virtual environment
```

To use the right api interfaces of databroker run the following:
```console
python3 -m proto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but I am thinking if we should add

proto/**/*.py

to the .gitignore of kuksa-databroker so that the submodule isn't reported as dirty after this command

```
This should copy the corresponding proto files to the kuksa-client directory.

Your prompt should change to somehting indicating you are in the virutal environment now, e.g.

```console
Expand Down
3 changes: 3 additions & 0 deletions kuksa-client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ RUN pip install --upgrade pip build pyinstaller
# We must copy the whole repository otherwise version lookup by tag would not work
COPY . /kuksa-python-sdk/
WORKDIR /kuksa-python-sdk/kuksa-client
RUN git submodule update --recursive --remote --init
# install files from submodules to kuksa-client repo to generate protos out of it
RUN python3 -m proto

RUN python3 -m build
# We install globally on build container, so pyinstaller can easily gather all files
Expand Down
12 changes: 0 additions & 12 deletions kuksa-client/kuksa/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions kuksa-client/kuksa/val/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion kuksa-client/kuksa/val/v1/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions kuksa-client/kuksa/val/v1/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion kuksa-client/kuksa/val/v1/types.proto

This file was deleted.

1 change: 0 additions & 1 deletion kuksa-client/kuksa/val/v1/val.proto

This file was deleted.

13 changes: 7 additions & 6 deletions kuksa-client/kuksa_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ def path_completer(self, text, line, begidx, endidx):

def subscribeCallback(self, logPath, resp):
if logPath is None:
self.async_alert(
highlight(
json.dumps(json.loads(resp), indent=2),
lexers.JsonLexer(),
formatters.TerminalFormatter(),
with self.terminal_lock:
self.async_alert(
highlight(
json.dumps(json.loads(resp), indent=2),
lexers.JsonLexer(),
formatters.TerminalFormatter(),
)
)
)
else:
with logPath.open("a", encoding="utf-8") as logFile:
logFile.write(resp + "\n")
Expand Down
62 changes: 41 additions & 21 deletions kuksa-client/kuksa_client/cli_backend/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,18 @@ def __init__(self, config):
self.run = False

self.AttrDict = {
"value": (kuksa_client.grpc.Field.VALUE, kuksa_client.grpc.View.CURRENT_VALUE),
"targetValue": (kuksa_client.grpc.Field.ACTUATOR_TARGET, kuksa_client.grpc.View.TARGET_VALUE),
"metadata": (kuksa_client.grpc.Field.METADATA, kuksa_client.grpc.View.METADATA),
"value": (
kuksa_client.grpc.Field.VALUE,
kuksa_client.grpc.View.CURRENT_VALUE,
),
"targetValue": (
kuksa_client.grpc.Field.ACTUATOR_TARGET,
kuksa_client.grpc.View.TARGET_VALUE,
),
"metadata": (
kuksa_client.grpc.Field.METADATA,
kuksa_client.grpc.View.METADATA,
),
}

def connection_established(self) -> bool:
Expand Down Expand Up @@ -112,8 +121,10 @@ def getValue(self, path: str, attribute="value", timeout=5):
def getValues(self, paths: Iterable[str], attribute="value", timeout=5):
if attribute in self.AttrDict:
field, view = self.AttrDict[attribute]
entries = [kuksa_client.grpc.EntryRequest(
path=path, view=view, fields=(field,)) for path in paths]
entries = [
kuksa_client.grpc.EntryRequest(path=path, view=view, fields=(field,))
for path in paths
]
requestArgs = {'entries': entries}
return self._sendReceiveMsg(("get", requestArgs), timeout)

Expand All @@ -127,28 +138,33 @@ def setValues(self, updates: Dict[str, Any], attribute="value", timeout=5):
if attribute in self.AttrDict:
field, _ = self.AttrDict[attribute]
entry_updates = []
try_v2 = False
for path, value in updates.items():

if field is kuksa_client.grpc.Field.VALUE:
entry = kuksa_client.grpc.DataEntry(
path=path, value=kuksa_client.grpc.Datapoint(value=value))
path=path,
value=kuksa_client.grpc.Datapoint(value=value),
)
try_v2 = True
elif field is kuksa_client.grpc.Field.ACTUATOR_TARGET:
entry = kuksa_client.grpc.DataEntry(
path=path, actuator_target=kuksa_client.grpc.Datapoint(
value=value),
path=path,
actuator_target=kuksa_client.grpc.Datapoint(value=value),
)
elif field is kuksa_client.grpc.Field.METADATA:
try:
metadata_dict = json.loads(value)
except json.JSONDecodeError:
return json.dumps({"error": "Metadata value needs to be a valid JSON object"})
entry = kuksa_client.grpc.DataEntry(
path=path, metadata=kuksa_client.grpc.Metadata.from_dict(
metadata_dict),
path=path,
metadata=kuksa_client.grpc.Metadata.from_dict(metadata_dict),
)
entry_updates.append(kuksa_client.grpc.EntryUpdate(
entry=entry, fields=(field,)))
requestArgs = {'updates': entry_updates}
entry_updates.append(
kuksa_client.grpc.EntryUpdate(entry=entry, fields=(field,))
)
requestArgs = {"updates": entry_updates, "try_v2": try_v2}
return self._sendReceiveMsg(("set", requestArgs), timeout)
return json.dumps({"error": "Invalid Attribute"})

Expand All @@ -175,11 +191,14 @@ def subscribe(self, path: str, callback, attribute="value", timeout=5):
def subscribeMultiple(self, paths: Iterable[str], callback, attribute="value", timeout=5):
if attribute in self.AttrDict:
field, view = self.AttrDict[attribute]
entries = [kuksa_client.grpc.SubscribeEntry(
path=path, view=view, fields=(field,)) for path in paths]
entries = [
kuksa_client.grpc.SubscribeEntry(path=path, view=view, fields=(field,))
for path in paths
]
requestArgs = {
'entries': entries,
'callback': callback_wrapper(callback),
"entries": entries,
"try_v2": True,
"callback": callback_wrapper(callback),
}
return self._sendReceiveMsg(("subscribe", requestArgs), timeout)

Expand Down Expand Up @@ -222,8 +241,7 @@ def _sendReceiveMsg(self, req, timeout):
# Async function to handle the gRPC calls
async def _grpcHandler(self, vss_client: kuksa_client.grpc.aio.VSSClient):
self.run = True
subscriber_manager = kuksa_client.grpc.aio.SubscriberManager(
vss_client)
subscriber_manager = kuksa_client.grpc.aio.SubscriberManager(vss_client)
self.grpc_connection_established = True
while self.run:
try:
Expand Down Expand Up @@ -273,7 +291,9 @@ def updateVSSTree(self, jsonStr, timeout=5):
async def mainLoop(self):
if self.insecure:

async with kuksa_client.grpc.aio.VSSClient(self.serverIP, self.serverPort, token=self.token) as vss_client:
async with kuksa_client.grpc.aio.VSSClient(
self.serverIP, self.serverPort, token=self.token
) as vss_client:
logger.info("gRPC channel connected.")
await self._grpcHandler(vss_client)
else:
Expand All @@ -282,7 +302,7 @@ async def mainLoop(self):
self.serverPort,
root_certificates=self.cacertificate,
tls_server_name=self.tls_server_name,
token=self.token
token=self.token,
) as vss_client:
logger.info("Secure gRPC channel connected.")
await self._grpcHandler(vss_client)
Loading