-
This commit is contained in:
parent
a765905d6c
commit
3292d4a1b7
20
README.md
20
README.md
@ -60,6 +60,26 @@ Add-on использует persistent config file:
|
|||||||
|
|
||||||
Этот файл является runtime source of truth для панели в HA-режиме и переживает рестарт add-on.
|
Этот файл является runtime source of truth для панели в HA-режиме и переживает рестарт add-on.
|
||||||
|
|
||||||
|
Частые настройки можно менять прямо из UI add-on в Home Assistant:
|
||||||
|
|
||||||
|
- `app.title`
|
||||||
|
- `app.poll_interval_ms`
|
||||||
|
- `app.main_room_name`
|
||||||
|
- `app.main_room_icon`
|
||||||
|
- `app.edit_mode`
|
||||||
|
- `app.battery_history_hours`
|
||||||
|
- `home_assistant.base_url`
|
||||||
|
- `home_assistant.token`
|
||||||
|
- `home_assistant.verify_ssl`
|
||||||
|
- `home_assistant.weather_entity_id`
|
||||||
|
- `camera.rtsp_url`
|
||||||
|
- `camera.stream_url`
|
||||||
|
- `camera.stream_mode`
|
||||||
|
- `camera.poster_url`
|
||||||
|
- `camera.popup_timeout_minutes`
|
||||||
|
|
||||||
|
Сложные структуры, вроде `rooms`, по-прежнему удобнее держать в JSON.
|
||||||
|
|
||||||
### Старый embed-режим
|
### Старый embed-режим
|
||||||
|
|
||||||
Отдельный PHP-доступ по-прежнему работает:
|
Отдельный PHP-доступ по-прежнему работает:
|
||||||
|
|||||||
@ -51,6 +51,21 @@ function app_config_path(): string
|
|||||||
return APP_ROOT . '/config/config.json';
|
return APP_ROOT . '/config/config.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function app_runtime_mode(): string
|
||||||
|
{
|
||||||
|
return strtolower(trim((string)getenv('WALL_PANEL_RUNTIME_MODE')));
|
||||||
|
}
|
||||||
|
|
||||||
|
function app_addon_options_path(): string
|
||||||
|
{
|
||||||
|
$override = trim((string)getenv('WALL_PANEL_OPTIONS_PATH'));
|
||||||
|
if ($override !== '') {
|
||||||
|
return $override;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '/data/options.json';
|
||||||
|
}
|
||||||
|
|
||||||
function app_storage_path(string $file): string
|
function app_storage_path(string $file): string
|
||||||
{
|
{
|
||||||
$override = trim((string)getenv('WALL_PANEL_STORAGE_DIR'));
|
$override = trim((string)getenv('WALL_PANEL_STORAGE_DIR'));
|
||||||
@ -70,23 +85,34 @@ function app_load_config(): array
|
|||||||
$path = app_config_path();
|
$path = app_config_path();
|
||||||
app_ensure_directory(dirname($path));
|
app_ensure_directory(dirname($path));
|
||||||
|
|
||||||
|
$config = app_default_config();
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
$defaults = app_default_config();
|
$json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
file_put_contents($path, json_encode($defaults, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
if ($json === false) {
|
||||||
return $defaults;
|
throw new RuntimeException('Failed to encode default config');
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($path, $json . PHP_EOL, LOCK_EX);
|
||||||
|
} else {
|
||||||
|
$raw = file_get_contents($path);
|
||||||
|
if ($raw === false || trim($raw) !== '') {
|
||||||
|
$decoded = json_decode((string)$raw, true);
|
||||||
|
if (!is_array($decoded)) {
|
||||||
|
throw new RuntimeException('Invalid JSON in config/config.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = array_replace_recursive($config, $decoded);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$raw = file_get_contents($path);
|
if (app_runtime_mode() === 'addon') {
|
||||||
if ($raw === false || trim($raw) === '') {
|
$options = app_load_json_file(app_addon_options_path(), []);
|
||||||
return app_default_config();
|
if (is_array($options) && $options !== []) {
|
||||||
|
$config = array_replace_recursive($config, $options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$decoded = json_decode($raw, true);
|
return $config;
|
||||||
if (!is_array($decoded)) {
|
|
||||||
throw new RuntimeException('Invalid JSON in config/config.json');
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_replace_recursive(app_default_config(), $decoded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function app_save_config(array $config): void
|
function app_save_config(array $config): void
|
||||||
|
|||||||
@ -59,6 +59,26 @@ Add-on использует persistent config file:
|
|||||||
|
|
||||||
Этот файл является runtime source of truth для панели в HA-режиме и переживает рестарт add-on.
|
Этот файл является runtime source of truth для панели в HA-режиме и переживает рестарт add-on.
|
||||||
|
|
||||||
|
Частые настройки можно менять прямо из UI add-on в Home Assistant:
|
||||||
|
|
||||||
|
- `app.title`
|
||||||
|
- `app.poll_interval_ms`
|
||||||
|
- `app.main_room_name`
|
||||||
|
- `app.main_room_icon`
|
||||||
|
- `app.edit_mode`
|
||||||
|
- `app.battery_history_hours`
|
||||||
|
- `home_assistant.base_url`
|
||||||
|
- `home_assistant.token`
|
||||||
|
- `home_assistant.verify_ssl`
|
||||||
|
- `home_assistant.weather_entity_id`
|
||||||
|
- `camera.rtsp_url`
|
||||||
|
- `camera.stream_url`
|
||||||
|
- `camera.stream_mode`
|
||||||
|
- `camera.poster_url`
|
||||||
|
- `camera.popup_timeout_minutes`
|
||||||
|
|
||||||
|
Сложные структуры, вроде `rooms`, по-прежнему удобнее держать в JSON.
|
||||||
|
|
||||||
### Старый embed-режим
|
### Старый embed-режим
|
||||||
|
|
||||||
Отдельный PHP-доступ по-прежнему работает:
|
Отдельный PHP-доступ по-прежнему работает:
|
||||||
|
|||||||
@ -22,5 +22,41 @@ ports_description:
|
|||||||
map:
|
map:
|
||||||
- addon_config:rw
|
- addon_config:rw
|
||||||
homeassistant_api: true
|
homeassistant_api: true
|
||||||
options: {}
|
options:
|
||||||
schema: {}
|
app:
|
||||||
|
title: Wall Panel
|
||||||
|
poll_interval_ms: 5000
|
||||||
|
main_room_name: Главная
|
||||||
|
main_room_icon: mdi:home
|
||||||
|
edit_mode: false
|
||||||
|
battery_history_hours: 4320
|
||||||
|
home_assistant:
|
||||||
|
base_url: ""
|
||||||
|
token: ""
|
||||||
|
verify_ssl: true
|
||||||
|
weather_entity_id: ""
|
||||||
|
camera:
|
||||||
|
rtsp_url: rtsp://10.0.6.110:45321/feff99fa45f317e7
|
||||||
|
stream_url: ""
|
||||||
|
stream_mode: hls
|
||||||
|
poster_url: http://10.0.6.110:5000/api/doorbell/latest.jpg
|
||||||
|
popup_timeout_minutes: 3
|
||||||
|
schema:
|
||||||
|
app:
|
||||||
|
title: str
|
||||||
|
poll_interval_ms: int
|
||||||
|
main_room_name: str
|
||||||
|
main_room_icon: str
|
||||||
|
edit_mode: bool
|
||||||
|
battery_history_hours: int
|
||||||
|
home_assistant:
|
||||||
|
base_url: str
|
||||||
|
token: str
|
||||||
|
verify_ssl: bool
|
||||||
|
weather_entity_id: str
|
||||||
|
camera:
|
||||||
|
rtsp_url: str
|
||||||
|
stream_url: str
|
||||||
|
stream_mode: str
|
||||||
|
poster_url: str
|
||||||
|
popup_timeout_minutes: int
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user