homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge.
531 lines • 23.6 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { Body, Controller, Delete, Get, Inject, Param, ParseIntPipe, Patch, Post, Put, Query, UseGuards, } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiBody, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiTags, } from '@nestjs/swagger';
import { AdminGuard } from '../../core/auth/guards/admin.guard.js';
import { PortRangeDto, SetBridgeAlertDto, SetScheduledRestartCronDto } from './config-editor.dto.js';
import { ConfigEditorService } from './config-editor.service.js';
function includesRestartInfo(include) {
return (include ?? '').split(',').map(s => s.trim()).includes('restart-info');
}
let ConfigEditorController = class ConfigEditorController {
configEditorService;
constructor(configEditorService) {
this.configEditorService = configEditorService;
}
getConfig() {
return this.configEditorService.getConfigFile();
}
updateConfig(body, include) {
if (includesRestartInfo(include)) {
return this.configEditorService.updateConfigFileWithRestartInfo(body);
}
return this.configEditorService.updateConfigFile(body);
}
getConfigForPlugin(pluginName) {
return this.configEditorService.getConfigForPlugin(pluginName);
}
updateConfigForPlugin(pluginName, body, include) {
if (includesRestartInfo(include)) {
return this.configEditorService.updateConfigForPluginWithRestartInfo(pluginName, body);
}
return this.configEditorService.updateConfigForPlugin(pluginName, body);
}
disablePlugin(pluginName, include) {
if (includesRestartInfo(include)) {
return this.configEditorService.disablePluginWithRestartInfo(pluginName);
}
return this.configEditorService.disablePlugin(pluginName);
}
enablePlugin(pluginName, include) {
if (includesRestartInfo(include)) {
return this.configEditorService.enablePluginWithRestartInfo(pluginName);
}
return this.configEditorService.enablePlugin(pluginName);
}
getPropertyForUi(key) {
return this.configEditorService.getPropertyForUi(key);
}
setPropertyForUi({ key, value }) {
return this.configEditorService.setPropertyForUi(key, value);
}
patchPropertiesForUi(body) {
return this.configEditorService.setPropertiesForUi(body);
}
setAccessoryControlInstanceBlacklist({ body }) {
return this.configEditorService.setAccessoryControlInstanceBlacklist(body);
}
getPluginsHideUpdatesFor() {
return this.configEditorService.getPluginsHideUpdatesFor();
}
setPluginsHideUpdatesFor({ body }) {
return this.configEditorService.setPluginsHideUpdatesFor(body);
}
getPluginsHideChildBridgeSetupFor() {
return this.configEditorService.getPluginsHideChildBridgeSetupFor();
}
setPluginsHideChildBridgeSetupFor({ body }) {
return this.configEditorService.setPluginsHideChildBridgeSetupFor(body);
}
getBridge(username) {
return this.configEditorService.getBridge(username);
}
setBridgeHideHapAlert(username, body) {
return this.configEditorService.setBridgeHideHapAlert(username, body.value);
}
setBridgeHideMatterAlert(username, body) {
return this.configEditorService.setBridgeHideMatterAlert(username, body.value);
}
setBridgeScheduledRestartCron(username, body) {
return this.configEditorService.setBridgeScheduledRestartCron(username, body.value);
}
listConfigBackups() {
return this.configEditorService.listConfigBackups();
}
getBackup(backupId) {
return this.configEditorService.getConfigBackup(backupId);
}
deleteBackup(backupId) {
return this.configEditorService.deleteConfigBackup(backupId);
}
deleteAllConfigBackups() {
return this.configEditorService.deleteAllConfigBackups();
}
getMatterPortRange() {
return this.configEditorService.getMatterPortRange();
}
setMatterPortRange(body) {
return this.configEditorService.setMatterPortRange(body);
}
getMatterConfig() {
return this.configEditorService.getMatterConfig();
}
updateMatterConfig(matterConfig) {
return this.configEditorService.updateMatterConfig(matterConfig);
}
deleteMatterConfig() {
return this.configEditorService.deleteMatterConfig();
}
setMatterEnabled(body) {
return this.configEditorService.setMatterEnabled(body.enabled, body.restart ?? true, body.externalsOnly ?? false);
}
getHapEnabled() {
return this.configEditorService.getHapEnabled();
}
setHapEnabled(body) {
return this.configEditorService.setHapEnabled(body.enabled, body.restart ?? true, body.externalsOnly ?? false);
}
};
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return the current Homebridge `config.json` file.' }),
Get(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getConfig", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Update the Homebridge `config.json` file.',
description: 'Pass `?include=restart-info` to receive `{ config, affectedBridges }` instead of the bare config — used by the editor to skip the follow-up `/status/homebridge/child-bridges` fetch after every save. Default response shape is unchanged.',
}),
ApiBody({ description: 'Homebridge config.json', type: 'json', isArray: false }),
ApiQuery({
name: 'include',
type: 'string',
required: false,
description: 'Comma-separated extras. Supported: `restart-info`.',
example: 'restart-info',
}),
Post(),
__param(0, Body()),
__param(1, Query('include')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "updateConfig", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Return the config blocks for a specific plugin.',
description: 'An array of config blocks will be returned. An empty array will be returned if the plugin is not configured.',
}),
Get('/plugin/:pluginName'),
__param(0, Param('pluginName')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getConfigForPlugin", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Replace the config for a specific plugin.',
description: 'An array of all config blocks for the plugin must be provided, missing blocks will be removed. Sending an empty array will remove all plugin config. Pass `?include=restart-info` to receive `{ config, affectedBridges }` with only this plugin\'s bridges in `affectedBridges` — the plugin settings modals use this to skip the follow-up `/status/homebridge/child-bridges` fetch.',
}),
Post('/plugin/:pluginName'),
ApiBody({ description: 'Array of plugin config blocks', type: 'json', isArray: true }),
ApiQuery({
name: 'include',
type: 'string',
required: false,
description: 'Comma-separated extras. Supported: `restart-info`.',
example: 'restart-info',
}),
__param(0, Param('pluginName')),
__param(1, Body()),
__param(2, Query('include')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, String]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "updateConfigForPlugin", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Mark a plugin as disabled.',
description: 'Pass `?include=restart-info` to receive `{ config, affectedBridges }` where `config` is the updated `disabledPlugins` array. Default response shape is unchanged.',
}),
ApiParam({ name: 'pluginName', type: 'string' }),
ApiQuery({
name: 'include',
type: 'string',
required: false,
description: 'Comma-separated extras. Supported: `restart-info`.',
example: 'restart-info',
}),
Put('plugin/:pluginName/disable'),
__param(0, Param('pluginName')),
__param(1, Query('include')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "disablePlugin", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Mark a plugin as enabled.',
description: 'Pass `?include=restart-info` to receive `{ config, affectedBridges }` where `config` is the updated `disabledPlugins` array. Default response shape is unchanged.',
}),
ApiParam({ name: 'pluginName', type: 'string' }),
ApiQuery({
name: 'include',
type: 'string',
required: false,
description: 'Comma-separated extras. Supported: `restart-info`.',
example: 'restart-info',
}),
Put('plugin/:pluginName/enable'),
__param(0, Param('pluginName')),
__param(1, Query('include')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "enablePlugin", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Get a config property for the Homebridge UI.' }),
ApiParam({ name: 'key', type: 'string', description: 'The property key to retrieve (e.g., "nodeUpdatePolicy")' }),
Get('/ui/:key'),
__param(0, Param('key')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getPropertyForUi", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Update a config property for the Homebridge UI.' }),
Put('/ui'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setPropertyForUi", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Update multiple Homebridge UI config properties in a single disk write.',
description: 'Body is a `{ key: value }` map. Keys support dot notation for nested properties (e.g. `terminal.fontSize`). The settings page batches concurrent field edits through this endpoint so a burst of changes is one PATCH instead of one PUT per field.',
}),
ApiBody({
description: 'Map of UI config property keys to their new values.',
schema: {
type: 'object',
additionalProperties: true,
example: { 'theme': 'red', 'lang': 'auto', 'terminal.fontSize': 14 },
},
}),
Patch('/ui'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "patchPropertiesForUi", null);
__decorate([
UseGuards(AdminGuard),
Put('/ui/accessory-control/instance-blacklist'),
ApiOperation({ summary: 'Update the accessory control instance blacklist.' }),
ApiBody({ description: 'Array of bridge instances for which control by the UI should be blocked.', type: 'json', isArray: true }),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setAccessoryControlInstanceBlacklist", null);
__decorate([
UseGuards(AdminGuard),
Get('/ui/plugins/hide-updates-for'),
ApiOperation({ summary: 'Get the plugins hide updates for list.' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ConfigEditorController.prototype, "getPluginsHideUpdatesFor", null);
__decorate([
UseGuards(AdminGuard),
Put('/ui/plugins/hide-updates-for'),
ApiOperation({ summary: 'Update the plugins hide updates for.' }),
ApiBody({ description: 'Array of plugin names to hide updates for in the UI.', type: 'json', isArray: true }),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setPluginsHideUpdatesFor", null);
__decorate([
UseGuards(AdminGuard),
Get('/ui/plugins/hide-child-bridge-setup-for'),
ApiOperation({ summary: 'Get the plugins hide child-bridge-setup recommendation list.' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ConfigEditorController.prototype, "getPluginsHideChildBridgeSetupFor", null);
__decorate([
UseGuards(AdminGuard),
Put('/ui/plugins/hide-child-bridge-setup-for'),
ApiOperation({ summary: 'Update the plugins hide child-bridge-setup recommendation list.' }),
ApiBody({ description: 'Array of plugin names for which the set-up child bridge recommendation should be hidden.', type: 'json', isArray: true }),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setPluginsHideChildBridgeSetupFor", null);
__decorate([
UseGuards(AdminGuard),
Get('/ui/bridges/:username'),
ApiOperation({ summary: 'Get a specific bridge configuration by username.' }),
ApiParam({
name: 'username',
type: String,
description: 'The MAC address of the bridge (e.g., "0E:02:9A:9D:44:45")',
example: '0E:02:9A:9D:44:45',
}),
ApiOkResponse({
description: 'Bridge configuration',
type: 'object',
schema: {
example: {
username: '0E:02:9A:9D:44:45',
hideHapAlert: true,
hideMatterAlert: false,
},
},
}),
__param(0, Param('username')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], ConfigEditorController.prototype, "getBridge", null);
__decorate([
UseGuards(AdminGuard),
Put('/ui/bridges/:username/hide-hap-alert'),
ApiOperation({ summary: 'Set the hideHapAlert flag for a specific bridge.' }),
ApiParam({
name: 'username',
type: String,
description: 'The MAC address of the bridge (e.g., "0E:02:9A:9D:44:45")',
example: '0E:02:9A:9D:44:45',
}),
ApiBody({ type: SetBridgeAlertDto }),
__param(0, Param('username')),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, SetBridgeAlertDto]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setBridgeHideHapAlert", null);
__decorate([
UseGuards(AdminGuard),
Put('/ui/bridges/:username/hide-matter-alert'),
ApiOperation({ summary: 'Set the hideMatterAlert flag for a specific bridge.' }),
ApiParam({
name: 'username',
type: String,
description: 'The MAC address of the bridge (e.g., "0E:02:9A:9D:44:45")',
example: '0E:02:9A:9D:44:45',
}),
ApiBody({ type: SetBridgeAlertDto }),
__param(0, Param('username')),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, SetBridgeAlertDto]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setBridgeHideMatterAlert", null);
__decorate([
UseGuards(AdminGuard),
Put('/ui/bridges/:username/scheduled-restart-cron'),
ApiOperation({ summary: 'Set the scheduledRestartCron for a specific child bridge.' }),
ApiParam({
name: 'username',
type: String,
description: 'The MAC address of the bridge (e.g., `0E:02:9A:9D:44:45`)',
example: '0E:02:9A:9D:44:45',
}),
ApiBody({ type: SetScheduledRestartCronDto }),
__param(0, Param('username')),
__param(1, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, SetScheduledRestartCronDto]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setBridgeScheduledRestartCron", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'List the available Homebridge `config.json` backups.' }),
Get('/backups'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "listConfigBackups", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return the Homebridge `config.json` file for the given backup ID.' }),
ApiParam({ name: 'backupId', type: 'number' }),
Get('/backups/:backupId'),
__param(0, Param('backupId', ParseIntPipe)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getBackup", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Delete the backup file for the given backup ID.' }),
ApiParam({ name: 'backupId', type: 'number' }),
Delete('/backups/:backupId'),
__param(0, Param('backupId', ParseIntPipe)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "deleteBackup", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Delete all the Homebridge `config.json` backups.' }),
Delete('/backups'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "deleteAllConfigBackups", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Get the Matter port range configuration.' }),
Get('/matter/ports'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getMatterPortRange", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Set the Matter port range configuration.' }),
Put('/matter/ports'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PortRangeDto]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setMatterPortRange", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Get Matter Configuration',
description: 'Returns the Matter configuration object for the main Homebridge bridge.',
}),
Get('/matter'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getMatterConfig", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Update Matter Configuration',
description: 'Update the Matter configuration object for the main Homebridge bridge.',
}),
ApiBody({ description: 'Matter configuration', type: 'json' }),
Put('/matter'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "updateMatterConfig", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Delete Matter Configuration',
description: 'Removes the Matter configuration object for the main Homebridge bridge, and deletes the Matter data for it.',
}),
Delete('/matter'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "deleteMatterConfig", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Enable or disable Matter for the main bridge in place',
description: 'Toggles `bridge.matter.enabled` without removing the config or its commissioning storage, so Matter can be re-enabled without re-commissioning. Requires Matter to already be configured.',
}),
ApiBody({ description: 'Matter enablement', type: 'json' }),
Put('/matter/enabled'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setMatterEnabled", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Get HAP enablement for the main bridge',
description: 'Returns whether HAP is published for the main Homebridge bridge. HAP is on by default. Reads tolerate both the legacy `bridge.hap: false` boolean form and the nested `bridge.hap: { enabled: false }` form used by Homebridge >= 2.0.3-beta.26.',
}),
Get('/hap'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "getHapEnabled", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Enable or disable HAP for the main bridge',
description: 'Toggles HAP for the main Homebridge bridge. The shape written to `bridge.hap` depends on the `protocolExternalsOnly` feature flag: when the running Homebridge supports it the nested object form is written, otherwise the boolean form is preserved.',
}),
ApiBody({ description: 'HAP enablement', type: 'json' }),
Put('/hap'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ConfigEditorController.prototype, "setHapEnabled", null);
ConfigEditorController = __decorate([
ApiTags('Homebridge Config Editor'),
ApiBearerAuth(),
UseGuards(AuthGuard()),
Controller('config-editor'),
__param(0, Inject(ConfigEditorService)),
__metadata("design:paramtypes", [ConfigEditorService])
], ConfigEditorController);
export { ConfigEditorController };
//# sourceMappingURL=config-editor.controller.js.map