aboutsummaryrefslogtreecommitdiffstats
path: root/agl_service_voiceagent/utils/kuksa_interface.py
diff options
context:
space:
mode:
authorMalik Talha <talhamalik727x@gmail.com>2023-11-02 03:11:43 +0500
committerMalik Talha <talhamalik727x@gmail.com>2023-11-02 03:11:43 +0500
commita644c90d7409f48c49fbd5ddca7ecfe35de15953 (patch)
treec513e46850dc6a58ac200ea20a467a23248ac63b /agl_service_voiceagent/utils/kuksa_interface.py
parent42a03d2550f60a8064078f19a743afb944f9ff69 (diff)
Update voice agent service
Modify default configuration, add detailed file based logging functionality, and use placeholders instead of fixed values in default config. Bug-AGL: SPEC-4906 Signed-off-by: Malik Talha <talhamalik727x@gmail.com> Change-Id: Ib75af153555e7cdde38c67414df8326799e22c8d
Diffstat (limited to 'agl_service_voiceagent/utils/kuksa_interface.py')
-rw-r--r--agl_service_voiceagent/utils/kuksa_interface.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/agl_service_voiceagent/utils/kuksa_interface.py b/agl_service_voiceagent/utils/kuksa_interface.py
index 9270379..0881660 100644
--- a/agl_service_voiceagent/utils/kuksa_interface.py
+++ b/agl_service_voiceagent/utils/kuksa_interface.py
@@ -18,7 +18,7 @@ import time
import json
import threading
from kuksa_client import KuksaClientThread
-from agl_service_voiceagent.utils.config import get_config_value
+from agl_service_voiceagent.utils.config import get_config_value, get_logger
class KuksaInterface:
"""
@@ -55,6 +55,7 @@ class KuksaInterface:
self.insecure = get_config_value("insecure", "Kuksa")
self.protocol = get_config_value("protocol", "Kuksa")
self.token = get_config_value("token", "Kuksa")
+ self.logger = get_logger()
print(self.ip, self.port, self.insecure, self.protocol, self.token)
@@ -102,11 +103,14 @@ class KuksaInterface:
if not self.get_kuksa_status():
print("[-] Error: Connection to Kuksa server failed.")
+ self.logger.error("Connection to Kuksa server failed.")
else:
print("[+] Connection to Kuksa established.")
+ self.logger.info("Connection to Kuksa established.")
except Exception as e:
print("[-] Error: Connection to Kuksa server failed. ", str(e))
+ self.logger.error(f"Connection to Kuksa server failed. {str(e)}")
def authorize_kuksa_client(self):
@@ -119,10 +123,13 @@ class KuksaInterface:
if "error" in response:
error_message = response.get("error", "Unknown error")
print(f"[-] Error: Authorization failed. {error_message}")
+ self.logger.error(f"Authorization failed. {error_message}")
else:
print("[+] Kuksa client authorized successfully.")
+ self.logger.info("Kuksa client authorized successfully.")
else:
print("[-] Error: Kuksa client is not initialized. Call `connect_kuksa_client` first.")
+ self.logger.error("Kuksa client is not initialized. Call `connect_kuksa_client` first.")
def send_values(self, path=None, value=None):
@@ -137,7 +144,8 @@ class KuksaInterface:
"""
result = False
if self.kuksa_client is None:
- print("[-] Error: Kuksa client is not initialized.")
+ print(f"[-] Error: Failed to send value '{value}' to Kuksa. Kuksa client is not initialized.")
+ self.logger.error(f"Failed to send value '{value}' to Kuksa. Kuksa client is not initialized.")
return
if self.get_kuksa_status():
@@ -150,12 +158,15 @@ class KuksaInterface:
else:
error_message = response.get("error", "Unknown error")
print(f"[-] Error: Failed to send value '{value}' to Kuksa. {error_message}")
+ self.logger.error(f"Failed to send value '{value}' to Kuksa. {error_message}")
except Exception as e:
- print("[-] Error: Failed to send values to Kuksa. ", str(e))
+ print(f"[-] Error: Failed to send value '{value}' to Kuksa. ", str(e))
+ self.logger.error(f"Failed to send value '{value}' to Kuksa. {str(e)}")
else:
- print("[-] Error: Connection to Kuksa failed.")
+ print(f"[-] Error: Failed to send value '{value}' to Kuksa. Connection to Kuksa failed.")
+ self.logger.error(f"Failed to send value '{value}' to Kuksa. Connection to Kuksa failed.")
return result
@@ -171,7 +182,8 @@ class KuksaInterface:
"""
result = None
if self.kuksa_client is None:
- print("[-] Error: Kuksa client is not initialized.")
+ print(f"[-] Error: Failed to get value at path '{path}' from Kuksa. Kuksa client is not initialized.")
+ self.logger.error(f"Failed to get value at path '{path}' from Kuksa. Kuksa client is not initialized.")
return
if self.get_kuksa_status():
@@ -185,13 +197,16 @@ class KuksaInterface:
else:
error_message = response.get("error", "Unknown error")
- print(f"[-] Error: Failed to get value from Kuksa. {error_message}")
+ print(f"[-] Error: Failed to get value at path '{path}' from Kuksa. {error_message}")
+ self.logger.error(f"Failed to get value at path '{path}' from Kuksa. {error_message}")
except Exception as e:
- print("[-] Error: Failed to get values from Kuksa. ", str(e))
+ print(f"[-] Error: Failed to get value at path '{path}' from Kuksa. ", str(e))
+ self.logger.error(f"Failed to get value at path '{path}' from Kuksa. {str(e)}")
else:
- print("[-] Error: Connection to Kuksa failed.")
+ print(f"[-] Error: Failed to get value at path '{path}' from Kuksa. Connection to Kuksa failed.")
+ self.logger.error(f"Failed to get value at path '{path}' from Kuksa. Connection to Kuksa failed.")
return result
@@ -206,5 +221,7 @@ class KuksaInterface:
self.kuksa_client.stop()
self.kuksa_client = None
print("[+] Kuksa client stopped.")
+ self.logger.info("Kuksa client stopped.")
except Exception as e:
- print("[-] Error: Failed to close Kuksa client. ", str(e)) \ No newline at end of file
+ print("[-] Error: Failed to close Kuksa client. ", str(e))
+ self.logger.error(f"Failed to close Kuksa client. {str(e)}") \ No newline at end of file