Skip to content

Commit 8f99f46

Browse files
committed
initial draft of standard params
1 parent f26f144 commit 8f99f46

File tree

6 files changed

+169
-62
lines changed

6 files changed

+169
-62
lines changed

.vehicle_profiles/merge.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import { glob } from 'glob'
22
import { readFile, writeFile } from 'fs/promises';
3+
import editJsonFile from 'edit-json-file'
34

45
const source_folder = '../vehicle_profiles';
56
const target = '../vehicle_profiles.json'
67

7-
const files = await glob(source_folder + '/**/*.json');
8+
const files = await glob(source_folder + '/bmw/*.json');
9+
const params = JSON.parse(await readFile('params.json'));
810

911
let result = {
1012
'cars': []
1113
};
1214

1315
async function add_json(path){
1416
let data = JSON.parse(await readFile(path));
17+
let newParams = [];
18+
Object.keys(data.pids).forEach(key => {
19+
for( const [param, exp] of Object.entries(data.pids[key].parameters)){
20+
newParams.push({
21+
"name": param,
22+
"expression": exp,
23+
...params[param].settings
24+
})
25+
}
26+
data.pids[key].parameters = newParams;
27+
})
1528
result.cars.push(data)
1629
}
1730

@@ -48,4 +61,14 @@ const supportedVehiclesListFilepath = await glob('../docs/content/*.Config/*.Aut
4861
if(supportedVehiclesListFilepath.length == 0 || supportedVehiclesListFilepath.length != 1) {
4962
throw new Error('Unable to determine automateDirectory');
5063
}
51-
await writeFile(supportedVehiclesListFilepath[0], supportedVehiclesListContent);
64+
await writeFile(supportedVehiclesListFilepath[0], supportedVehiclesListContent);
65+
66+
67+
let param_array = Object.getOwnPropertyNames(params);
68+
let schema_file = editJsonFile('schema.json');
69+
const PARAM_PATH = "properties.pids.items.properties.parameters.propertyNames.enum";
70+
let existing_params = schema_file.get(PARAM_PATH);
71+
if(existing_params !== param_array){
72+
schema_file.set(PARAM_PATH, param_array);
73+
schema_file.save();
74+
}

.vehicle_profiles/package-lock.json

+95
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vehicle_profiles/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"type": "module",
1313
"dependencies": {
1414
"ajv": "^8.17.1",
15+
"edit-json-file": "^1.8.1",
1516
"glob": "^11.0.0"
1617
}
1718
}

.vehicle_profiles/params.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"SOC": {
3+
"description": "State Of Charge",
4+
"settings": {
5+
"unit": "%",
6+
"class": "battery",
7+
"min": "0",
8+
"max": "100"
9+
}
10+
}
11+
}

.vehicle_profiles/schema.json

+36-59
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,41 @@
11
{
2-
"title": "WiCan Vehicle Profile",
3-
"description": "Data about various models of cars and their settings",
4-
"type": "object",
5-
"properties": {
6-
"car_model": {
7-
"description": "Name of car model, should include Make and Model(s)",
8-
"type": "string"
9-
},
10-
"init": {
11-
"description": "Init String, don't forget the final ;",
2+
"title": "WiCan Vehicle Profile",
3+
"description": "Data about various models of cars and their settings",
4+
"type": "object",
5+
"properties": {
6+
"car_model": {
7+
"description": "Name of car model, should include Make and Model(s)",
8+
"type": "string"
9+
},
10+
"init": {
11+
"description": "Init String, don't forget the final ;",
12+
"type": "string"
13+
},
14+
"pids": {
15+
"description": "Array of PID's and their parameters",
16+
"type": "array",
17+
"minItems": 1,
18+
"items": {
19+
"type": "object",
20+
"required": [
21+
"pid"
22+
],
23+
"properties": {
24+
"pid": {
25+
"description": "The PID for this group of parameters",
1226
"type": "string"
13-
},
14-
"pids": {
15-
"description": "Array of PID's and their parameters",
16-
"type": "array",
17-
"minItems": 1,
18-
"items": {
19-
"type": "object",
20-
"required": ["pid"],
21-
"properties": {
22-
"pid": {
23-
"description": "The PID for this group of parameters",
24-
"type": "string"
25-
},
26-
"parameters": {
27-
"description": "Array of Parameters for this PID",
28-
"type": "array",
29-
"minItems": 1,
30-
"items": {
31-
"type": "object",
32-
"required": ["name", "expression", "unit", "class"],
33-
"properties": {
34-
"name": {
35-
"description": "Used in MQTT JSON, no spaces",
36-
"type": "string"
37-
},
38-
"expression": {
39-
"description": "Expression to calculate value",
40-
"type": "string"
41-
},
42-
"unit": {
43-
"description": "Unit for this parameter",
44-
"type": "string"
45-
},
46-
"class": {
47-
"description": "Class of sensor, See Home Assistant sensor classes https://www.home-assistant.io/integrations/sensor/#device-class or https://www.home-assistant.io/integrations/binary_sensor/#device-class",
48-
"type": "string"
49-
},
50-
"type": {
51-
"description": "Type of sensor",
52-
"type": "string",
53-
"enum": ["sensor", "binary_sensor"]
54-
}
55-
}
56-
}
57-
}
58-
}
27+
},
28+
"parameters": {
29+
"description": "Object of Paramater and Expressions",
30+
"type": "object",
31+
"propertyNames": {
32+
"enum": [
33+
"SOC"
34+
]
5935
}
36+
}
6037
}
61-
},
62-
"additionalProperties": false,
63-
"required": [ "car_model", "init", "pids"]
38+
}
39+
}
40+
}
6441
}

.vehicle_profiles/validate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const schema = JSON.parse(await readFile("schema.json", "utf-8"))
77
const validate = ajv.compile(schema)
88

99
const source_folder = '../vehicle_profiles';
10-
const files = await glob(source_folder + '/**/*.json')
10+
const files = await glob(source_folder + '/bmw/*.json')
1111

1212
let errors = 0;
1313

0 commit comments

Comments
 (0)