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:
@@ -18,7 +18,7 @@ final class DashboardService
|
||||
private array $errors = [];
|
||||
|
||||
/**
|
||||
* @param array{stations: int, measure: int, forecast: int} $ttl
|
||||
* @param array{stations: int, measure: int, pressure: int, forecast: int} $ttl
|
||||
* @param array<string, string> $indoorModules
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -47,6 +47,7 @@ final class DashboardService
|
||||
$now = $nowUtc->setTimezone($tz);
|
||||
|
||||
$rain = $this->rain($station, $now);
|
||||
$pressure = $this->pressure($station, $now);
|
||||
$forecast = $this->forecast($station, $tz);
|
||||
|
||||
return [
|
||||
@@ -63,9 +64,11 @@ final class DashboardService
|
||||
'min_at' => $this->iso($station['outdoor']['min_at'], $tz),
|
||||
'max' => $station['outdoor']['max'],
|
||||
'max_at' => $this->iso($station['outdoor']['max_at'], $tz),
|
||||
'humidity' => $station['outdoor']['humidity'],
|
||||
],
|
||||
'indoor' => $station['indoor'],
|
||||
'rain' => $rain,
|
||||
'pressure' => $pressure,
|
||||
'forecast' => $forecast['days'],
|
||||
'forecast_stale' => $forecast['stale'],
|
||||
'errors' => $this->errors,
|
||||
@@ -91,6 +94,25 @@ final class DashboardService
|
||||
return RainCalculator::compute($measure['data'], $now, $station['sum_rain_24']) + ['stale' => $measure['stale']];
|
||||
}
|
||||
|
||||
/** @return array{current: ?float, trend: ?string, history: list<array{at: string, hpa: float}>, stale: bool} */
|
||||
private function pressure(array $station, \DateTimeImmutable $now): array
|
||||
{
|
||||
$base = ['current' => $station['pressure']['current'], 'trend' => $station['pressure']['trend']];
|
||||
if ($station['device_id'] === null) {
|
||||
return $base + ['history' => [], 'stale' => false];
|
||||
}
|
||||
$begin = $now->getTimestamp() - PressureHistory::HOURS * 3600;
|
||||
$measure = $this->fetch(
|
||||
'pressure',
|
||||
fn() => $this->source->pressureHistory($station['device_id'], $begin, $now->getTimestamp()),
|
||||
self::ERR_NETATMO,
|
||||
);
|
||||
return $base + [
|
||||
'history' => $measure['data'] === null ? [] : PressureHistory::map($measure['data'], $now->getTimezone()),
|
||||
'stale' => $measure['stale'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{days: list<array>, stale: bool} */
|
||||
private function forecast(array $station, \DateTimeZone $tz): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user