From 6b21032fc91b679353a53073f5570a25a4fd0991 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 22 May 2024 15:02:15 -0400 Subject: Add ability to disable HVAC and steering wheel pages Add configuration file options to disable the HVAC and steering wheel pages. Also includes a bit of refactoring around the KUKSA.val databroker client mostly focused on cleaning up naming for now. If significant development continues on this application the KuksaClient class should be used as the place where more refactoring occurs. Bug-AGL: SPEC-5142 Change-Id: I986c7cac4e6543e2a1ad40ebf436fd40e2ae2300 Signed-off-by: Scott Murray --- extras/FeedKuksa.py | 113 ------------------------------------------ extras/KuksaClient.py | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++ extras/config.ini | 2 + 3 files changed, 137 insertions(+), 113 deletions(-) delete mode 100644 extras/FeedKuksa.py create mode 100644 extras/KuksaClient.py (limited to 'extras') diff --git a/extras/FeedKuksa.py b/extras/FeedKuksa.py deleted file mode 100644 index 955361d..0000000 --- a/extras/FeedKuksa.py +++ /dev/null @@ -1,113 +0,0 @@ -""" - Copyright 2023 Suchinton Chakravarty - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import logging -from PyQt5.QtCore import QThread -from PyQt5.QtCore import pyqtSignal -from . import Kuksa_Instance as kuksa_instance -import threading - -class FeedKuksa(QThread): - """ - A class to handle sending values to Kuksa. - - Attributes: - ----------- - stop_flag : bool - A flag to stop the thread. - kuksa : kuksa_instance.KuksaClientSingleton.instance() - An instance of the Kuksa client. - client : kuksa_instance.KuksaClientSingleton.instance().client - A client object to interact with the Kuksa server. - """ - - sending_values = pyqtSignal() - finished_sending_values = pyqtSignal() - - def __init__(self, parent=None): - """ - Constructs all the necessary attributes for the FeedKuksa object. - - Parameters: - ----------- - parent : QObject - The parent object of the FeedKuksa object. - """ - QThread.__init__(self, parent) - self.stop_flag = False - - def run(self): - """ - Starts the thread and sets the instance of the Kuksa client. - """ - logging.info("Starting thread") - self.set_instance() - - def stop(self): - """ - Stops the thread. - """ - self.stop_flag = True - - logging.info("Stopping thread") - - def set_instance(self): - """ - Sets the instance of the Kuksa client. - """ - self.kuksa = kuksa_instance.KuksaClientSingleton.instance() - self.client = self.kuksa.get_client() - - def send_values(self, path=None, value=None, attribute=None): - """ - Sends values to Kuksa. - - Parameters: - ----------- - path : str - The path to the value in Kuksa. - value : str - The value to be sent to Kuksa. - attribute : str - The attribute of the value in Kuksa. - - Raises: - ------- - Exception - If there is an error sending values to Kuksa. - """ - - if self.client is None: - logging.error("Kuksa client is None, try reconnecting") - return - - if not self.client.checkConnection(): - logging.error("Kuksa client is not connected, try reconnecting") - threading.Thread(target=self.set_instance).start() - return - - try: - if attribute is not None: - self.sending_values.emit() - self.client.setValue(path, value, attribute) - self.finished_sending_values.emit() - else: - self.sending_values.emit() - self.client.setValue(path, value) - self.finished_sending_values.emit() - except Exception as e: - logging.error(f"Error sending values to kuksa {e}") - threading.Thread(target=self.set_instance).start() diff --git a/extras/KuksaClient.py b/extras/KuksaClient.py new file mode 100644 index 0000000..504e21c --- /dev/null +++ b/extras/KuksaClient.py @@ -0,0 +1,135 @@ +# Copyright (C) 2023 Suchinton Chakravarty +# Copyright (C) 2024 Konsulko Group +# +# SPDX-License-Identifier: Apache-2.0 + +import logging +from PyQt5.QtCore import QThread +from PyQt5.QtCore import pyqtSignal +from . import Kuksa_Instance as kuksa_instance +import threading + +class KuksaClient(QThread): + """ + A class to handle sending values to Kuksa. + + Attributes: + ----------- + stop_flag : bool + A flag to stop the thread. + kuksa : kuksa_instance.KuksaClientSingleton.instance() + An instance of the Kuksa client. + client : kuksa_instance.KuksaClientSingleton.instance().client + A client object to interact with the Kuksa server. + """ + + sending_values = pyqtSignal() + finished_sending_values = pyqtSignal() + + def __init__(self, parent=None): + """ + Constructs all the necessary attributes for the FeedKuksa object. + + Parameters: + ----------- + parent : QObject + The parent object of the FeedKuksa object. + """ + QThread.__init__(self, parent) + self.stop_flag = False + self.kuksa = None + self.client = None + + def run(self): + """ + Starts the thread and sets the instance of the Kuksa client. + """ + logging.info("Starting thread") + self.set_instance() + + def stop(self): + """ + Stops the thread. + """ + self.stop_flag = True + + logging.info("Stopping thread") + + def set_instance(self): + """ + Sets the instance of the Kuksa client. + """ + self.kuksa = kuksa_instance.KuksaClientSingleton.instance() + self.client = self.kuksa.get_client() + + def set(self, path=None, value=None, attribute=None): + """ + Sets VSS value. + + Parameters: + ----------- + path : str + The VSS signal path. + value : str + The value to be set. + attribute : str + The value attribute ("value" or "targetValue" (for actuators)). + + Raises: + ------- + Exception + If there is an error setting the value. + """ + + if self.client is None: + #logging.error("Kuksa client is None, try reconnecting") + return + + if not self.client.checkConnection(): + logging.error("Client is not connected, try reconnecting") + threading.Thread(target=self.set_instance).start() + return + + try: + if attribute is not None: + self.sending_values.emit() + self.client.setValue(path, value, attribute) + self.finished_sending_values.emit() + else: + self.sending_values.emit() + self.client.setValue(path, value) + self.finished_sending_values.emit() + except Exception as e: + logging.error(f"Error sending values to kuksa {e}") + threading.Thread(target=self.set_instance).start() + + def setValues(self, values : dict[str, any] = None): + """ + Sets VSS values. + + Parameters: + ----------- + values : Dict[str, Any] + The values to be set. + + Raises: + ------- + Exception + If there is an error setting the values. + """ + + if self.client is None: + #logging.error("Kuksa client is None, try reconnecting") + return + + if not self.client.checkConnection(): + logging.error("Client is not connected, try reconnecting") + threading.Thread(target=self.set_instance).start() + return + + try: + self.sending_values.emit() + self.client.setValues(values) + except Exception as e: + logging.error(f"Error sending values to kuksa {e}") + threading.Thread(target=self.set_instance).start() diff --git a/extras/config.ini b/extras/config.ini index 6619900..36306cc 100644 --- a/extras/config.ini +++ b/extras/config.ini @@ -1,5 +1,7 @@ [default] fullscreen-mode = true +hvac-enabled = true +steering-wheel-enabled = true [vss-server] ip = localhost -- cgit 1.2.3-korg