This commit is contained in:
Striker72rus 2026-03-25 14:00:06 +03:00
parent 1c5831c473
commit e2d8ba78b1
7 changed files with 52 additions and 45 deletions

View File

@ -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-доступ по-прежнему работает:

View File

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

View File

@ -1,6 +1,6 @@
{
"active": false,
"sensor_entity_id": "binary_sensor.barn_all_occupancy",
"opened_at": 1774435721,
"opened_at": 1774436133,
"expires_at": null
}

View File

@ -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-доступ по-прежнему работает:

View File

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

View File

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

View File

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