Skip to content

Commit 6149c88

Browse files
authored
Merge pull request #122 from highmobility/feature/add-equals-diff-merge
Updates API-s for Command, Capabilities and properties
2 parents daf77ed + 5ee523e commit 6149c88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+578
-383
lines changed

.eslintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ rules:
3838
- allowSeparatedGroups: true
3939
ignoreCase: true
4040
ignoreDeclarationSort: true
41+
'@typescript-eslint/ban-types': off
4142
'@typescript-eslint/explicit-module-boundary-types': off
4243
'@typescript-eslint/no-non-null-assertion': off
4344
settings:

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"yamljs": "^0.3.0"
6161
},
6262
"dependencies": {
63+
"abab": "^2.0.5",
6364
"ieee754": "^1.2.1",
6465
"lodash.clonedeep": "^4.5.0",
6566
"lodash.get": "^4.4.2",

scripts/generate-capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function printCapabilityClassDefinition(filename: string, declarations: ts.Node[
215215
CapabilityBaseClassName,
216216
),
217217
),
218-
printer(tsUtils.createImportDeclaration(`../configuration`, ConfigurationClassName)),
218+
printer(tsUtils.createImportDeclaration(`../core/Configuration`, ConfigurationClassName)),
219219
]
220220
.join('\n')
221221
.concat('\n'),

scripts/generate-configuration.ts

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Configuration,
66
MeasurementTypes,
77
Properties,
8+
Property,
89
PropertyComponents,
910
TypeDefinition,
1011
TypeDefinitions,
@@ -42,6 +43,128 @@ function createConfiguration() {
4243
console.log('Successfully created configuration.');
4344
}
4445

46+
export const getPropertyIdentityKey = (capabilityName: string) => (propertyName: string) => {
47+
switch (capabilityName) {
48+
case 'adas':
49+
switch (propertyName) {
50+
case 'lane_keep_assists_states':
51+
case 'park_assists':
52+
return 'location';
53+
}
54+
55+
case 'charging':
56+
switch (propertyName) {
57+
case 'departure_times':
58+
return 'state';
59+
case 'reduction_times':
60+
return 'start_stop';
61+
}
62+
63+
case 'chassis_settings':
64+
switch (propertyName) {
65+
case 'current_spring_rates':
66+
case 'maximum_spring_rates':
67+
case 'minimum_spring_rates':
68+
return 'axle';
69+
}
70+
71+
case 'climate':
72+
switch (propertyName) {
73+
case 'hvac_weekday_starting_times':
74+
return 'weekday';
75+
}
76+
77+
case 'crash':
78+
switch (propertyName) {
79+
case 'incidents':
80+
return 'location';
81+
}
82+
83+
case 'dashboard_lights':
84+
switch (propertyName) {
85+
case 'bulb_failures':
86+
return 'id';
87+
case 'dashboard_lights':
88+
return 'name';
89+
}
90+
91+
case 'diagnostics':
92+
switch (propertyName) {
93+
case 'diesel_exhaust_filter_status':
94+
return 'status';
95+
96+
case 'tire_pressures':
97+
case 'tire_pressures_differences':
98+
case 'tire_pressure_statuses':
99+
case 'tire_pressures_targets':
100+
case 'tire_temperatures':
101+
case 'wheel_rpms':
102+
return 'location';
103+
}
104+
105+
case 'doors':
106+
switch (propertyName) {
107+
case 'inside_locks':
108+
case 'locks':
109+
case 'positions':
110+
return 'location';
111+
}
112+
113+
case 'lights':
114+
switch (propertyName) {
115+
case 'fog_lights':
116+
case 'interior_lights':
117+
case 'reading_lamps':
118+
return 'location';
119+
}
120+
121+
case 'race':
122+
switch (propertyName) {
123+
case 'accelerations':
124+
return 'direction';
125+
case 'brake_torque_vectorings':
126+
return 'axle';
127+
}
128+
129+
case 'seats':
130+
switch (propertyName) {
131+
case 'person_detected':
132+
case 'seatbelts_state':
133+
return 'location';
134+
}
135+
136+
case 'tachograph':
137+
switch (propertyName) {
138+
case 'drivers_cards_present':
139+
case 'drivers_working_states':
140+
case 'drivers_time_states':
141+
return 'driver_number';
142+
}
143+
144+
case 'trips':
145+
switch (propertyName) {
146+
case 'end_address_components':
147+
case 'start_address_components':
148+
case 'thresholds':
149+
return 'type';
150+
}
151+
152+
case 'usage':
153+
switch (propertyName) {
154+
case 'driving_modes_activation_periods':
155+
case 'driving_modes_energy_consumptions':
156+
return 'driving_mode';
157+
}
158+
159+
case 'windows':
160+
switch (propertyName) {
161+
case 'open_percentages':
162+
case 'positions':
163+
return 'location';
164+
}
165+
}
166+
};
167+
45168
function mapStateProps({
46169
properties,
47170
state,
@@ -53,6 +176,20 @@ function mapStateProps({
53176
return [];
54177
}
55178

179+
function mapPropertyIdentityKeys(identityKeyFn: (name: string) => string | undefined) {
180+
return function (property: Property) {
181+
const key = identityKeyFn(property.name);
182+
if (key) {
183+
return {
184+
...property,
185+
identity_key: key,
186+
};
187+
}
188+
189+
return property;
190+
};
191+
}
192+
56193
function mapTypesToEntity<T extends TypeDefinition>(entity: T) {
57194
return {
58195
...entity,
@@ -76,11 +213,15 @@ function parseCapabilities() {
76213
return CapabilitiesFileList.reduce<Configuration['capabilities']>(
77214
(configurationObject, fileName) => {
78215
const capability = parseYmlFile<Capability>(`${CapabilitiesPath}/${fileName}`);
216+
const identityKeyFn = getPropertyIdentityKey(capability.name);
217+
79218
return {
80219
...configurationObject,
81220
[capability.name]: {
82221
...capability,
83-
properties: capability.properties.map((property) => mapTypesToEntity(property)),
222+
properties: capability.properties
223+
.map(mapTypesToEntity)
224+
.map(mapPropertyIdentityKeys(identityKeyFn)),
84225
state: mapStateProps(capability),
85226
},
86227
};

scripts/generate-property-components.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { snakeCaseToPascalCase } from '@/utils/strings';
88
import { cleanOrCreateDirectory, printSourceFile } from './shared/utils';
99
import {
1010
ConfigurationClassName,
11-
PropertyClassName,
1211
PropertyComponentsClassesPath,
12+
PropertyTypeName,
1313
} from './shared/constants';
1414
import * as tsUtils from './shared/typescript';
1515

@@ -55,7 +55,7 @@ function createConstructorDeclaration({ name }: PropertyComponent) {
5555
undefined,
5656
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Readonly'), [
5757
ts.factory.createTypeReferenceNode(
58-
ts.factory.createIdentifier(PropertyClassName),
58+
ts.factory.createIdentifier(PropertyTypeName),
5959
undefined,
6060
),
6161
]),
@@ -79,11 +79,8 @@ function createDataComponentValueTypeDefinitionOverride() {
7979
[
8080
ts.factory.createReturnStatement(
8181
ts.factory.createPropertyAccessExpression(
82-
ts.factory.createPropertyAccessExpression(
83-
ts.factory.createThis(),
84-
ts.factory.createIdentifier('property'),
85-
),
86-
ts.factory.createIdentifier('definition'),
82+
ts.factory.createThis(),
83+
ts.factory.createIdentifier('property'),
8784
),
8885
),
8986
],
@@ -192,8 +189,8 @@ function printPropertyComponentClassDefinition(filename: string, classDeclaratio
192189

193190
const nodes = [
194191
[
195-
printer(tsUtils.createImportDeclaration(`../configuration`, ConfigurationClassName)),
196-
printer(tsUtils.createImportDeclaration(`../core/${PropertyClassName}`, PropertyClassName)),
192+
printer(tsUtils.createImportDeclaration(`../core/Configuration`, ConfigurationClassName)),
193+
printer(tsUtils.createImportDeclaration(`../types`, PropertyTypeName)),
197194
printer(tsUtils.createImportDeclaration(`../core/${BaseClassName}`, BaseClassName)),
198195
]
199196
.join('\n')
@@ -213,14 +210,23 @@ function printPropertyComponentsMetaData(classNames: string[], components: Prope
213210
.map((className) => printer(tsUtils.createImportDeclaration(`./${className}`, className)))
214211
.join('\n')
215212
.concat('\n'),
213+
printer(tsUtils.createImportDeclaration(`./types`, ComponentNameTypeName)).concat('\n\n'),
216214
printer(createPropertyComponentClassMapDefinition(components)).concat('\n'),
217215
printer(createPropertyComponentMapDefinition(components)).concat('\n'),
218-
printer(createPropertyComponentNameDeclaration(components)),
219216
];
220217

221218
printSourceFile(filename, nodes);
222219
}
223220

221+
function printPropertyComponentsTypes(components: PropertyComponents) {
222+
const filename = path.join(PropertyComponentsClassesPath, `types.ts`);
223+
const printer = tsUtils.createPrinter(filename);
224+
225+
const nodes = [printer(createPropertyComponentNameDeclaration(components))];
226+
227+
printSourceFile(filename, nodes);
228+
}
229+
224230
function printExportDefinitionsForPropertyComponents(classNames: string[]) {
225231
const filename = path.join(PropertyComponentsClassesPath, `index.ts`);
226232
const printer = tsUtils.createPrinter(filename);
@@ -257,6 +263,7 @@ function generatePropertyComponents() {
257263

258264
printExportDefinitionsForPropertyComponents(classNames);
259265
printPropertyComponentsMetaData(classNames, components);
266+
printPropertyComponentsTypes(components);
260267

261268
console.log('Successfully generated property components.');
262269
}

scripts/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const PropertyComponentsClassesPath = resolve(SourcesPath, 'components');
2222

2323
export const ConfigurationClassName = 'Configuration';
2424
export const CapabilityBaseClassName = 'Capability';
25-
export const PropertyClassName = 'Property';
25+
export const PropertyTypeName = 'Property';
2626

2727
export const EventsRegex = new RegExp(`events.`);
2828
export const CustomTypesRegex = new RegExp(`types.`);

src/capabilities/Adas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Capability } from '../core/Capability';
2-
import { Configuration } from '../configuration';
2+
import { Configuration } from '../core/Configuration';
33

44
import { UniversalProperties } from './properties';
55

src/capabilities/Browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Capability } from '../core/Capability';
2-
import { Configuration } from '../configuration';
2+
import { Configuration } from '../core/Configuration';
33

44
import { UniversalProperties } from './properties';
55

src/capabilities/Capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Capability } from '../core/Capability';
2-
import { Configuration } from '../configuration';
2+
import { Configuration } from '../core/Configuration';
33

44
import { UniversalProperties } from './properties';
55

0 commit comments

Comments
 (0)