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:
2026-09-13 09:34:20 +02:00
co-authored by Claude Fable 5.1
parent 66bce8e8d0
commit dba1875683
16 changed files with 380 additions and 20 deletions
+36 -4
View File
@@ -32,7 +32,7 @@ final class DashboardServiceTest extends TestCase
return new DashboardService(
$this->source,
new Cache($this->dir),
['stations' => 300, 'measure' => 900, 'forecast' => 3600],
['stations' => 300, 'measure' => 900, 'pressure' => 900, 'forecast' => 3600],
'Europe/Amsterdam',
$lat,
$lon,
@@ -46,12 +46,19 @@ final class DashboardServiceTest extends TestCase
{
$p = $this->service()->build();
self::assertSame(['generated_at', 'timezone', 'station', 'outdoor', 'indoor', 'rain', 'forecast', 'forecast_stale', 'errors'], array_keys($p));
self::assertSame(['generated_at', 'timezone', 'station', 'outdoor', 'indoor', 'rain', 'pressure', 'forecast', 'forecast_stale', 'errors'], array_keys($p));
self::assertSame('2026-09-11T14:32:05+02:00', $p['generated_at']);
self::assertSame('Europe/Berlin', $p['timezone']);
self::assertSame(['measured_at' => '2026-09-11T14:30:12+02:00', 'stale' => false], $p['station']);
self::assertSame(['temp' => 16.4, 'trend' => 'down', 'min' => 9.2, 'min_at' => '2026-09-11T06:10:00+02:00', 'max' => 19.8, 'max_at' => '2026-09-11T13:05:00+02:00'], $p['outdoor']);
self::assertSame(['temp' => 16.4, 'trend' => 'down', 'min' => 9.2, 'min_at' => '2026-09-11T06:10:00+02:00', 'max' => 19.8, 'max_at' => '2026-09-11T13:05:00+02:00', 'humidity' => 71.0], $p['outdoor']);
self::assertCount(3, $p['indoor']);
self::assertSame(612, $p['indoor'][0]['co2']);
self::assertSame(48.0, $p['indoor'][0]['humidity']);
self::assertSame(1014.2, $p['pressure']['current']);
self::assertSame('up', $p['pressure']['trend']);
self::assertCount(49, $p['pressure']['history']);
self::assertSame('2026-09-10T14:30:00+02:00', $p['pressure']['history'][0]['at']);
self::assertFalse($p['pressure']['stale']);
self::assertSame(2.4, $p['rain']['today']);
self::assertSame(['2026-09-08', '2026-09-09', '2026-09-10'], array_column($p['rain']['previous_days'], 'date'));
self::assertEqualsWithDelta(38.5, $p['rain']['month_total'], 0.0001);
@@ -73,6 +80,29 @@ final class DashboardServiceTest extends TestCase
self::assertSame((new \DateTimeImmutable('2026-09-11 12:32:05 UTC'))->getTimestamp(), $end);
}
public function testPressureHistoryIsRequestedForLast24Hours(): void
{
$this->service()->build();
[$deviceId, $begin, $end] = $this->source->lastArgs['pressure'];
$now = (new \DateTimeImmutable('2026-09-11 12:32:05 UTC'))->getTimestamp();
self::assertSame('70:ee:50:00:00:01', $deviceId);
self::assertSame($now - 86400, $begin);
self::assertSame($now, $end);
}
public function testPressureFailureKeepsCurrentValueAndMarksStale(): void
{
$this->source->responses['pressure'] = new UpstreamException('500');
$p = $this->service()->build();
self::assertSame(1014.2, $p['pressure']['current']);
self::assertSame([], $p['pressure']['history']);
self::assertTrue($p['pressure']['stale']);
self::assertSame(['netatmo_unavailable'], $p['errors']);
}
public function testForecastUsesStationLocationUnlessConfigured(): void
{
$this->service()->build();
@@ -96,6 +126,8 @@ final class DashboardServiceTest extends TestCase
self::assertSame([], $p['indoor']);
self::assertNull($p['rain']['today']);
self::assertSame(0, $this->source->calls['measure'], 'zonder regenmeter-id geen getmeasure-call');
self::assertSame(0, $this->source->calls['pressure'], 'zonder device-id geen luchtdruk-call');
self::assertSame(['current' => null, 'trend' => null, 'history' => [], 'stale' => false], $p['pressure']);
self::assertSame('Europe/Amsterdam', $p['timezone'], 'fallback-tijdzone uit config');
self::assertSame(['netatmo_unavailable', 'forecast_unavailable'], $p['errors']);
}
@@ -152,7 +184,7 @@ final class DashboardServiceTest extends TestCase
$this->service()->build();
$this->service('2026-09-11 12:36:05 UTC')->build();
self::assertSame(['stations' => 1, 'measure' => 1, 'forecast' => 1], $this->source->calls);
self::assertSame(['stations' => 1, 'measure' => 1, 'pressure' => 1, 'forecast' => 1], $this->source->calls);
$this->service('2026-09-11 12:38:05 UTC')->build();
self::assertSame(2, $this->source->calls['stations'], 'stations na 5 min opnieuw');