From 2c682eac440f2d2b7e6f1e9a4c9f221959b52065 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sat, 2 Jan 2021 03:16:49 +0530 Subject: [PATCH] Generalize the manual system onto a json file --- car-manual-skill/.gitignore | 2 +- car-manual-skill/__init__.py | 37 ++++++-- .../locale/en-us/manual.car.childlock.dialog | 1 - .../locale/en-us/manual.car.childlock.intent | 1 - car-manual-skill/questions.json | 84 +++++++++++++++++++ 5 files changed, 117 insertions(+), 8 deletions(-) delete mode 100644 car-manual-skill/locale/en-us/manual.car.childlock.dialog delete mode 100644 car-manual-skill/locale/en-us/manual.car.childlock.intent create mode 100644 car-manual-skill/questions.json diff --git a/car-manual-skill/.gitignore b/car-manual-skill/.gitignore index 4eb3651..aeae5a8 100644 --- a/car-manual-skill/.gitignore +++ b/car-manual-skill/.gitignore @@ -1,4 +1,4 @@ __pycache__/ *.qmlc settings.json - +locale/en-us diff --git a/car-manual-skill/__init__.py b/car-manual-skill/__init__.py index a2bb45b..c62ab1b 100644 --- a/car-manual-skill/__init__.py +++ b/car-manual-skill/__init__.py @@ -1,3 +1,6 @@ +import json +from pathlib import Path + from mycroft import MycroftSkill, intent_file_handler import requests @@ -13,18 +16,42 @@ def emit(osd_url, event, data): class CarManual(MycroftSkill): def __init__(self): MycroftSkill.__init__(self) + # Generate the files + root_path = str(Path(__file__).absolute().parent) + root_locale_path = root_path + "/locale/en-us" + with open(root_path + "/questions.json") as questions_file: + questions = json.load(questions_file) + self.questions = questions - @intent_file_handler('manual.car.childlock.intent') - def handle_manual_car(self, message): - dialog = self.dialog_renderer.render("manual.car.childlock", {}) + for qid, question in questions.items(): + with open(f"{root_locale_path}/{qid}.intent", "w") as intent_file: + for intent in question["questions"]: + intent_file.write(intent) + intent_file.write("\n") + + with open(f"{root_locale_path}/{qid}.dialog", "w") as dialog_file: + for dialog in question["answers"]: + dialog_file.write(dialog) + dialog_file.write("\n") + + def initialize(self): + for key in self.questions: + self.register_intent( + f"{key}.intent", + lambda y: self.generic_handler(key, y) + ) + + def generic_handler(self, intent_id, message): + title = self.questions[intent_id]["title"] + dialog = self.dialog_renderer.render(intent_id, {}) url = self.settings.get("OSD_API", "http://localhost:5050/send") emission = { "plugin": "manual", "data": { - "title": "Child Lock", + "title": title, "description": dialog }, - "time": 5000 + "time": 10000 } emit(url, "switchPlugin", emission) self.speak(dialog) diff --git a/car-manual-skill/locale/en-us/manual.car.childlock.dialog b/car-manual-skill/locale/en-us/manual.car.childlock.dialog deleted file mode 100644 index 4ffe54f..0000000 --- a/car-manual-skill/locale/en-us/manual.car.childlock.dialog +++ /dev/null @@ -1 +0,0 @@ -To enable child lock, slide the lock along the edge of the door. diff --git a/car-manual-skill/locale/en-us/manual.car.childlock.intent b/car-manual-skill/locale/en-us/manual.car.childlock.intent deleted file mode 100644 index 4314485..0000000 --- a/car-manual-skill/locale/en-us/manual.car.childlock.intent +++ /dev/null @@ -1 +0,0 @@ -How to enable child lock diff --git a/car-manual-skill/questions.json b/car-manual-skill/questions.json new file mode 100644 index 0000000..0089e70 --- /dev/null +++ b/car-manual-skill/questions.json @@ -0,0 +1,84 @@ +{ + "hazard.warning.button": { + "title": "Hazard Warning Button", + "questions": [ + "What is the Hazard Warning button", + "What happens when I press the warning button" + + ], + "answers": [ + "Hazard Warning button will activate the Hazard lights" + ] + }, + "rear.defogger": { + "title": "Rear Defogger", + "questions": [ + "What is the rear defogger", + "How do I defog the rear window and mirror" + ], + "answers": [ + "It will defog the rear windows and mirrors", + "Press the rear defogger and heated door mirror button to defog the rear window and mirrors when the ignition switch is in on" + ] + }, + "heating.system": { + "title": "Heating System", + "questions": [ + "How does the automatic heating system work", + "How do I manage the car temperature" + ], + "answers": [ + "The automatic heating system maintains the interior temperature you select. The system also selects the proper mix of heated or cooled air that raises or lowers the interior temperature to your preference as quickly as possible.", + "Press the Auto button and Adjust the temperature control dial for managing the interior temperature to your preference" + ] + }, + "lane.watch": { + "title": "Lane Watch", + "questions": [ + "What is Lane Watch", + "Which button do I use for watching the lanes", + "Is it safe to rely on Lane Watch while driving the car" + ], + "answers": [ + "LaneWatch is an assistance system that allows you to check the passenger side rear areas displayed on the audio/information screen when the turn signal is activated to the passenger’s side. A camera in the passenger side door mirror monitors these areas and allows you to check for vehicles, in addition to your visual check and use of the passenger door mirror. You can also keep the system on for your convenience while driving", + "On moving the signal lever to the passenger side there is the button for lane watch at the end of the lever", + "Like all assistance systems, LaneWatch has limitations. Over reliance on LaneWatch may result in a collision. The LaneWatch function can be affected by weather, lighting (including headlights and low sun angle), ambient darkness, camera condition, and loading." + ] + + }, + "parking.break": { + "title": "Parking Break", + "questions": [ + "What is the use of Parking Break", + "Where can I find the parking break" + ], + "answers": [ + "This button is used to keep vehicle stationary when it is parked. It can be applied manually or automatically release it", + "You can find it in the compartment between the seat on the front" + ] + }, + "speed.manual.shift.mode": { + "title": "7 speed manual shift mode", + "questions": [ + "How do I operate the manual shift mode", + "How do I operate the shift lever D", + "How do I operare teh shift lever S" + ], + "answers": [ + "Use the paddle shifters to change between 1st and 7th speeds without releasing your hands from the steering wheel. The transmission switches to the 7-speed manual shift mode when you pull a paddle shifter while driving.", + "The shift mode goes into the 7-speed manual shift mode temporarily, and the number is displayed in the shift indicator. The 7-speed manual shift mode is canceled automatically if you drive at constant speed or accelerate, and the number in the shift indicator goes off.", + "The shift mode goes into the 7-speed manual shift mode. The M indicator and the speed number are displayed in the shift indicator. As the vehicle speed slows down, the transmission automatically shifts down accordingly. When the vehicle comes to a stop, it automatically shifts down into 1st. If the vehicle speed increases and the engine speed reaches near the tachometer’s red zone, the transmission automatically shifts up." + ] + }, + "automatic.climate.control": { + "title": "Automatic Climate Control", + "questions": [ + "Where is the automatic climate control", + "How do I manage the automatic climate control system" + ], + "answers": [ + "You can find the climate control system below the display console", + "The automatic climate control system maintains the interior temperature you select. The system also selects the proper mix of heated or cooled air that raises or lowers the interior temperature to your preference as quickly as possible." + ] + } +}