Route local lane gate opens through edge bindings
This commit is contained in:
@@ -765,15 +765,23 @@ class moduleSelfServeRoute
|
||||
$lane = $selfserve->lane($lane_id);
|
||||
try {
|
||||
$this->applyShellyTransportOverride($lane);
|
||||
$lane->open($gate, $toggle_after);
|
||||
$queued_gate_command = null;
|
||||
if ($this->requestedShellyTransportOverride() === 'local') {
|
||||
$queued_gate_command = $this->queueLocalLaneGateOpen($lane, $gate, $toggle_after);
|
||||
} else {
|
||||
$lane->open($gate, $toggle_after);
|
||||
}
|
||||
|
||||
$response->success([
|
||||
'lane_id' => $lane_id,
|
||||
'gate' => $gate->name,
|
||||
'opened' => true,
|
||||
'queued' => $queued_gate_command !== null,
|
||||
'batch' => $queued_gate_command,
|
||||
'toggle_after' => $toggle_after,
|
||||
'state' => $lane->getLaneState()->name,
|
||||
'transport' => $this->requestedShellyTransportOverride(),
|
||||
]);
|
||||
], $queued_gate_command !== null ? 202 : 200);
|
||||
} catch (\Exception $e) {
|
||||
error_log('Failed to open self-serve lane gate ' . $gate->name . ' for lane ' . $lane_id . ': ' . $e->getMessage());
|
||||
$response->error('Failed to open ' . strtolower($gate->name) . ' gate.', 400);
|
||||
@@ -1720,6 +1728,27 @@ class moduleSelfServeRoute
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function queueLocalLaneGateOpen(selfserve_lane $lane, selfserve_lane_port $gate, int $toggleAfter): array
|
||||
{
|
||||
$requests = $this->buildLaneHardwareBatchRequests($lane, [[
|
||||
'target' => $gate->name,
|
||||
'action' => 'OPEN',
|
||||
'toggle_after' => $toggleAfter,
|
||||
]], true);
|
||||
$user = (new authentication())->get_user();
|
||||
|
||||
return (new edge_gateway_manager())->queueRelaySwitchBatch(
|
||||
$this->departmentIdForLane($lane),
|
||||
$requests,
|
||||
$user instanceof users_o ? (int)$user->id : null,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int,mixed> $items
|
||||
* @return array<int,array<string,mixed>>
|
||||
|
||||
@@ -311,6 +311,12 @@ it('wires self-serve lane gate open endpoint', function (): void {
|
||||
expect($moduleSelfServeRoute)->toContain('MAX_GATE_OPEN_TOGGLE_AFTER_SECONDS = 5');
|
||||
expect($moduleSelfServeRoute)->toContain('self::requireMaxValue($toggle_after, self::MAX_GATE_OPEN_TOGGLE_AFTER_SECONDS);');
|
||||
expect($moduleSelfServeRoute)->toContain('$lane->open($gate, $toggle_after)');
|
||||
expect($moduleSelfServeRoute)->toContain('queueLocalLaneGateOpen($lane, $gate, $toggle_after)');
|
||||
expect($moduleSelfServeRoute)->toContain('$this->requestedShellyTransportOverride() === \'local\'');
|
||||
expect($moduleSelfServeRoute)->toContain('queueRelaySwitchBatch(');
|
||||
expect($moduleSelfServeRoute)->toContain("'target' => \$gate->name");
|
||||
expect($moduleSelfServeRoute)->toContain("'queued' => \$queued_gate_command !== null");
|
||||
expect($moduleSelfServeRoute)->toContain('$queued_gate_command !== null ? 202 : 200');
|
||||
expect($moduleSelfServeRoute)->toContain("'toggle_after' => \$toggle_after");
|
||||
expect($moduleSelfServeRoute)->toContain('private function requestedRelayToggleAfter');
|
||||
expect($moduleSelfServeRoute)->toContain('Failed to open self-serve lane gate');
|
||||
|
||||
Reference in New Issue
Block a user