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 @@ +