Skip to content

Commit

Permalink
changed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dummyuser committed Sep 28, 2023
1 parent 9846e87 commit a565b72
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/src/vapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

"""A sample Velocitas vehicle app for adjusting seat position."""

import logging
import json
import logging

from vehicle import Vehicle # type: ignore
from velocitas_sdk.util.log import ( # type: ignore
Expand Down Expand Up @@ -56,17 +56,21 @@ async def on_start(self):
"""Run when the vehicle app starts"""
# TODO subscribe to Vehicle.Cabin.Seat.Row1.Pos1.Position and provide
# on_seat_position_changed as callback.
await self.Vehicle.Cabin.Seat.Row1.Pos1.Position.subscribe(self.on_seat_position_changed)
await self.Vehicle.Cabin.Seat.Row1.Pos1.Position.subscribe(
self.on_seat_position_changed
)

async def on_seat_position_changed(self, data: DataPointReply):
# TODO publish the current position as MQTT message to CURRENT_POSITION_TOPIC.
# self.on_set_position_request_received(CURRENT_POSITION_TOPIC)
position = str(data.get(self.Vehicle.Cabin.Seat.Row1.Pos1.Position).value)
await self.publish_mqtt_event(CURRENT_POSITION_TOPIC, json.dumps({"position": position}))
await self.publish_mqtt_event(
CURRENT_POSITION_TOPIC, json.dumps({"position": position})
)

@subscribe_topic(SET_POSITION_REQUEST_TOPIC)
async def on_set_position_request_received(self, data_str: str) -> None:
# TODO react on the position request and publish a MQTT message to
# SET_POSITION_RESPONSE_TOPIC with the result of the action.
dic = json.loads(data_str)
await self.Vehicle.Cabin.Seat.Row1.Pos1.Position.set(dic["position"])
await self.Vehicle.Cabin.Seat.Row1.Pos1.Position.set(dic["position"])

0 comments on commit a565b72

Please sign in to comment.