From e2d8ba78b17300c9c043cb13c239297729bcf8d9 Mon Sep 17 00:00:00 2001 From: Striker72rus Date: Wed, 25 Mar 2026 14:00:06 +0300 Subject: [PATCH] - --- README.md | 7 ++++++- lib/config.php | 35 ++++++++++++++++------------------- storage/popup_state.json | 2 +- wall_panel/README.md | 7 ++++++- wall_panel/config.yaml | 6 ++++-- wall_panel/lib/config.php | 36 +++++++++++++++++------------------- wall_panel/run.sh | 4 ++-- 7 files changed, 52 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 9faabb7..9b2e9ca 100755 --- a/README.md +++ b/README.md @@ -56,10 +56,13 @@ php -S 0.0.0.0:8080 Add-on использует persistent config file: -- `/config/config.json` внутри контейнера +- `/homeassistant/wall_panel/config.json` внутри контейнера +- на хосте Home Assistant это будет `/config/wall_panel/config.json` Этот файл является runtime source of truth для панели в HA-режиме и переживает рестарт add-on. +Настройки, внесённые через add-on UI Home Assistant, используются только как bootstrap при первом создании файла. Дальше редактируйте именно этот файл. + Частые настройки можно менять прямо из UI add-on в Home Assistant: - `app.title` @@ -80,6 +83,8 @@ Add-on использует persistent config file: Сложные структуры, вроде `rooms`, по-прежнему удобнее держать в JSON. +Внутренний runtime cache add-on хранит в `/data/wall_panel`. + ### Старый embed-режим Отдельный PHP-доступ по-прежнему работает: diff --git a/lib/config.php b/lib/config.php index c26ac71..a145670 100755 --- a/lib/config.php +++ b/lib/config.php @@ -86,15 +86,8 @@ function app_load_config(): array app_ensure_directory(dirname($path)); $config = app_default_config(); - $storedConfig = $config; - if (!file_exists($path)) { - $json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - if ($json === false) { - throw new RuntimeException('Failed to encode default config'); - } - - file_put_contents($path, $json . PHP_EOL, LOCK_EX); - } else { + $pathExists = file_exists($path); + if ($pathExists) { $raw = file_get_contents($path); if ($raw === false || trim($raw) !== '') { $decoded = json_decode((string)$raw, true); @@ -103,21 +96,25 @@ function app_load_config(): array } $config = array_replace_recursive($config, $decoded); - $storedConfig = $config; } } - $optionsPath = function_exists('app_addon_options_path') - ? app_addon_options_path() - : '/data/options.json'; - if (is_file($optionsPath)) { - $options = app_load_json_file($optionsPath, []); - if (is_array($options) && $options !== []) { - $config = array_replace_recursive($config, $options); - if (app_runtime_mode() === 'addon' && $config !== $storedConfig) { - app_save_config($config); + if (!$pathExists) { + $optionsPath = function_exists('app_addon_options_path') + ? app_addon_options_path() + : '/data/options.json'; + if (is_file($optionsPath)) { + $options = app_load_json_file($optionsPath, []); + if (is_array($options) && $options !== []) { + $config = array_replace_recursive($config, $options); } } + $json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + if ($json === false) { + throw new RuntimeException('Failed to encode default config'); + } + + file_put_contents($path, $json . PHP_EOL, LOCK_EX); } return $config; diff --git a/storage/popup_state.json b/storage/popup_state.json index 54524fe..0bf47ef 100755 --- a/storage/popup_state.json +++ b/storage/popup_state.json @@ -1,6 +1,6 @@ { "active": false, "sensor_entity_id": "binary_sensor.barn_all_occupancy", - "opened_at": 1774435721, + "opened_at": 1774436133, "expires_at": null } diff --git a/wall_panel/README.md b/wall_panel/README.md index d6f9cce..193904e 100755 --- a/wall_panel/README.md +++ b/wall_panel/README.md @@ -55,10 +55,13 @@ php -S 0.0.0.0:8080 Add-on использует persistent config file: -- `/config/config.json` внутри контейнера +- `/homeassistant/wall_panel/config.json` внутри контейнера +- на хосте Home Assistant это будет `/config/wall_panel/config.json` Этот файл является runtime source of truth для панели в HA-режиме и переживает рестарт add-on. +Настройки, внесённые через add-on UI Home Assistant, используются только как bootstrap при первом создании файла. Дальше редактируйте именно этот файл. + Частые настройки можно менять прямо из UI add-on в Home Assistant: - `app.title` @@ -79,6 +82,8 @@ Add-on использует persistent config file: Сложные структуры, вроде `rooms`, по-прежнему удобнее держать в JSON. +Внутренний runtime cache add-on хранит в `/data/wall_panel`. + ### Старый embed-режим Отдельный PHP-доступ по-прежнему работает: diff --git a/wall_panel/config.yaml b/wall_panel/config.yaml index ebc1049..3afff4c 100755 --- a/wall_panel/config.yaml +++ b/wall_panel/config.yaml @@ -1,6 +1,6 @@ name: Wall Panel description: Wall Panel PHP interface as a Home Assistant add-on -version: "1.0.4" +version: "1.0.5" slug: wall_panel url: https://git.striker72rus.ru/PHP/wallpanell.git init: false @@ -20,7 +20,9 @@ ports: ports_description: 8099/tcp: Wall Panel web UI map: - - addon_config:rw + - type: homeassistant_config + read_only: false + path: /homeassistant/wall_panel homeassistant_api: true options: app: diff --git a/wall_panel/lib/config.php b/wall_panel/lib/config.php index c26ac71..6d78d6e 100755 --- a/wall_panel/lib/config.php +++ b/wall_panel/lib/config.php @@ -86,15 +86,8 @@ function app_load_config(): array app_ensure_directory(dirname($path)); $config = app_default_config(); - $storedConfig = $config; - if (!file_exists($path)) { - $json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - if ($json === false) { - throw new RuntimeException('Failed to encode default config'); - } - - file_put_contents($path, $json . PHP_EOL, LOCK_EX); - } else { + $pathExists = file_exists($path); + if ($pathExists) { $raw = file_get_contents($path); if ($raw === false || trim($raw) !== '') { $decoded = json_decode((string)$raw, true); @@ -103,21 +96,26 @@ function app_load_config(): array } $config = array_replace_recursive($config, $decoded); - $storedConfig = $config; } } - $optionsPath = function_exists('app_addon_options_path') - ? app_addon_options_path() - : '/data/options.json'; - if (is_file($optionsPath)) { - $options = app_load_json_file($optionsPath, []); - if (is_array($options) && $options !== []) { - $config = array_replace_recursive($config, $options); - if (app_runtime_mode() === 'addon' && $config !== $storedConfig) { - app_save_config($config); + if (!$pathExists) { + $optionsPath = function_exists('app_addon_options_path') + ? app_addon_options_path() + : '/data/options.json'; + if (is_file($optionsPath)) { + $options = app_load_json_file($optionsPath, []); + if (is_array($options) && $options !== []) { + $config = array_replace_recursive($config, $options); } } + + $json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + if ($json === false) { + throw new RuntimeException('Failed to encode default config'); + } + + file_put_contents($path, $json . PHP_EOL, LOCK_EX); } return $config; diff --git a/wall_panel/run.sh b/wall_panel/run.sh index a4e925c..60ea168 100755 --- a/wall_panel/run.sh +++ b/wall_panel/run.sh @@ -3,8 +3,8 @@ set -eu DOCROOT="${WALL_PANEL_DOCROOT:-/app}" PORT="${WALL_PANEL_PORT:-8099}" -CONFIG_PATH="${WALL_PANEL_CONFIG_PATH:-/config/config.json}" -STORAGE_DIR="${WALL_PANEL_STORAGE_DIR:-/config/storage}" +CONFIG_PATH="${WALL_PANEL_CONFIG_PATH:-/homeassistant/wall_panel/config.json}" +STORAGE_DIR="${WALL_PANEL_STORAGE_DIR:-/data/wall_panel}" mkdir -p "$(dirname "$CONFIG_PATH")" "$STORAGE_DIR"