@@ -397,6 +397,13 @@ private function extractFromSensorCommand(array $cmd, string $interface, array &
397
397
return $ ret !== false ;
398
398
}
399
399
400
+ private function preg_array_key_exists ($ pattern , $ array ): array
401
+ {
402
+ $ keys = array_keys ($ array );
403
+ return preg_grep ($ pattern ,$ keys );
404
+ }
405
+
406
+
400
407
private function extractFromSdrCommand (array $ cmd , string $ interface , array &$ sensorData , array &$ states ): bool
401
408
{
402
409
$ ret = $ this ->runCommand (array_merge ($ cmd , ['-I ' , $ interface , 'sdr ' , 'list ' , 'full ' ]), true );
@@ -417,6 +424,14 @@ private function extractFromSdrCommand(array $cmd, string $interface, array &$se
417
424
foreach ($ this ->unitsOfMeasure as $ uom => $ type ) {
418
425
if (str_contains ($ value , $ uom )) {
419
426
$ value = trim (str_replace ($ uom , '' , $ value ));
427
+
428
+ $ id_pattern = "/^ " .$ id ."/ " ;
429
+ $ id_count = count ($ this ->preg_array_key_exists ($ id_pattern , $ sensorData [$ type ]));
430
+ if ($ id_count > 0 ) {
431
+ $ description .= ' ' . $ id_count +1 ;
432
+ $ id = $ this ->generateId ($ description );
433
+ }
434
+
420
435
$ sensorData [$ type ][$ id ] = $ description ;
421
436
$ states [$ id ] = $ value ;
422
437
}
@@ -521,4 +536,4 @@ private function getSensorsByType(Request $request, string $type, string $unit):
521
536
}
522
537
523
538
524
- }
539
+ }
0 commit comments