Generalize the manual system onto a json file

This commit is contained in:
Ceda EI 2021-01-02 03:16:49 +05:30
parent 1f87ced31b
commit 2c682eac44
5 changed files with 117 additions and 8 deletions

View File

@ -1,4 +1,4 @@
__pycache__/ __pycache__/
*.qmlc *.qmlc
settings.json settings.json
locale/en-us

View File

@ -1,3 +1,6 @@
import json
from pathlib import Path
from mycroft import MycroftSkill, intent_file_handler from mycroft import MycroftSkill, intent_file_handler
import requests import requests
@ -13,18 +16,42 @@ def emit(osd_url, event, data):
class CarManual(MycroftSkill): class CarManual(MycroftSkill):
def __init__(self): def __init__(self):
MycroftSkill.__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') for qid, question in questions.items():
def handle_manual_car(self, message): with open(f"{root_locale_path}/{qid}.intent", "w") as intent_file:
dialog = self.dialog_renderer.render("manual.car.childlock", {}) 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") url = self.settings.get("OSD_API", "http://localhost:5050/send")
emission = { emission = {
"plugin": "manual", "plugin": "manual",
"data": { "data": {
"title": "Child Lock", "title": title,
"description": dialog "description": dialog
}, },
"time": 5000 "time": 10000
} }
emit(url, "switchPlugin", emission) emit(url, "switchPlugin", emission)
self.speak(dialog) self.speak(dialog)

View File

@ -1 +0,0 @@
To enable child lock, slide the lock along the edge of the door.

View File

@ -1 +0,0 @@
How to enable child lock

View File

@ -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 passengers 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 tachometers 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."
]
}
}