Neues Ladestationsmodul mit ocpp Modul erstellt.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class ConnectionRegistry
|
||||
{
|
||||
public static function empty(): array
|
||||
{
|
||||
return [
|
||||
'connections' => [],
|
||||
'lastSeen' => []
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromJson(string $json): array
|
||||
{
|
||||
$data = json_decode($json, true);
|
||||
if (!is_array($data)) {
|
||||
return self::empty();
|
||||
}
|
||||
return array_replace(self::empty(), $data);
|
||||
}
|
||||
|
||||
public static function toJson(array $state): string
|
||||
{
|
||||
return json_encode(array_replace(self::empty(), $state));
|
||||
}
|
||||
|
||||
public static function touch(array $state, string $chargePointId, string $remote = ''): array
|
||||
{
|
||||
$state = array_replace(self::empty(), $state);
|
||||
$state['connections'][$chargePointId] = [
|
||||
'chargePointId' => $chargePointId,
|
||||
'remote' => $remote,
|
||||
'timestamp' => time()
|
||||
];
|
||||
$state['lastSeen'][$chargePointId] = time();
|
||||
return $state;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user