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+
45168function 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+
56193function 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 } ;
0 commit comments