feat(api): humidity, CO2, current pressure and 24h pressure history
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Weerscherm;
|
||||
|
||||
/** Zet een getmeasure-body (scale=30min, type=Pressure) om naar een gesorteerde reeks punten. */
|
||||
final class PressureHistory
|
||||
{
|
||||
public const HOURS = 24;
|
||||
|
||||
/**
|
||||
* @param array<string|int, mixed> $body
|
||||
* @return list<array{at: string, hpa: float}>
|
||||
*/
|
||||
public static function map(array $body, \DateTimeZone $tz): array
|
||||
{
|
||||
$points = [];
|
||||
foreach ($body as $timestamp => $values) {
|
||||
if (!is_numeric($timestamp) || !is_array($values) || !isset($values[0]) || !is_numeric($values[0])) {
|
||||
continue;
|
||||
}
|
||||
$points[(int) $timestamp] = (float) $values[0];
|
||||
}
|
||||
ksort($points);
|
||||
|
||||
$out = [];
|
||||
foreach ($points as $ts => $hpa) {
|
||||
$out[] = ['at' => (new \DateTimeImmutable('@' . $ts))->setTimezone($tz)->format(\DATE_ATOM), 'hpa' => $hpa];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user