From dfc28ee6c31aaa9bd8979ddb914b5bf2e50bcbff Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 11 Sep 2026 14:40:15 +0200 Subject: [PATCH] feat: /api/data.php with fixture source, robots.txt Co-Authored-By: Claude Fable 5.1 --- public/api/data.php | 53 +++++++++++++++++++++++++++++++++++++++++++++ public/robots.txt | 2 ++ src/LiveSource.php | 29 +++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 public/api/data.php create mode 100644 public/robots.txt create mode 100644 src/LiveSource.php diff --git a/public/api/data.php b/public/api/data.php new file mode 100644 index 0000000..aa2cb7a --- /dev/null +++ b/public/api/data.php @@ -0,0 +1,53 @@ + ['config_missing'], 'message' => 'config.php ontbreekt: kopieer config.example.php naar config.php']); + exit; +} + +try { + $config = Config::load($configFile); + $storage = rtrim((string) $config->get('storage_path'), '/'); + $timezone = (string) $config->get('timezone'); + $lat = $config->get('forecast_lat'); + $lon = $config->get('forecast_lon'); + + $source = $config->get('data_source') === 'live' + ? LiveSource::fromConfig($config) + : new FixtureSource(null, $timezone); + + $service = new DashboardService( + $source, + new Cache($storage . '/cache'), + $config->get('cache_ttl'), + $timezone, + is_numeric($lat) ? (float) $lat : null, + is_numeric($lon) ? (float) $lon : null, + is_array($config->get('indoor_modules')) ? $config->get('indoor_modules') : [], + is_string($config->get('netatmo_device_id')) && $config->get('netatmo_device_id') !== '' ? $config->get('netatmo_device_id') : null, + ); + + echo json_encode($service->build(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); +} catch (Throwable $e) { + error_log('weerscherm: ' . $e->getMessage()); + http_response_code(500); + echo json_encode(['errors' => ['server_error']]); +} diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/src/LiveSource.php b/src/LiveSource.php new file mode 100644 index 0000000..a086e7c --- /dev/null +++ b/src/LiveSource.php @@ -0,0 +1,29 @@ +