refactor: remove legacy service

This commit is contained in:
Carlos Valente
2025-01-11 16:06:43 +01:00
committed by Carlos Valente
parent 1f71d4578c
commit 2cc434b0e9
50 changed files with 60 additions and 1851 deletions
@@ -3,11 +3,40 @@ import { DatabaseModel, AutomationSettings, Automation, NormalisedAutomationBlue
import { dbModel } from '../../models/dataModel.js';
import type { ErrorEmitter } from '../../utils/parser.js';
export function parseAutomationSettings(data: Partial<DatabaseModel>, emitError?: ErrorEmitter): AutomationSettings {
interface LegacyData extends Partial<DatabaseModel> {
http?: unknown;
osc?: {
enabledIn?: boolean;
portIn?: number;
};
}
export function parseAutomationSettings(data: LegacyData, emitError?: ErrorEmitter): AutomationSettings {
/**
* Leaving a path for migrating users to the new automations
* This should be removed after a few releases
*/
if (data.http || data.osc) {
emitError?.('Found legacy integrations');
console.log('Found legacy integrations...');
if (data.osc) {
return {
enabledAutomations: dbModel.automation.enabledAutomations,
enabledOscIn: data.osc?.enabledIn ?? dbModel.automation.enabledOscIn,
oscPortIn: data.osc?.portIn ?? dbModel.automation.oscPortIn,
automations: [],
blueprints: {},
};
} else {
return { ...dbModel.automation };
}
}
if (!data.automation) {
emitError?.('No data found to import');
return { ...dbModel.automation };
}
console.log('Found Automation settings, importing...');
return {
enabledAutomations: data.automation.enabledAutomations ?? dbModel.automation.enabledAutomations,