diff --git a/backend/api/services/InverterService.ts b/backend/api/services/InverterService.ts index 6a739fa..13d86a8 100644 --- a/backend/api/services/InverterService.ts +++ b/backend/api/services/InverterService.ts @@ -2,7 +2,9 @@ import ApiBase from './ApiBase.js'; import InterfaceInvPowerFlowRealtimeData from '../../models/InterfaceInvPowerFlowRealtimeData.js'; import InterfaceInvMeterRealtimeData from '../../models/InterfaceInvMeterRealtimeData.js'; export default class extends ApiBase { - static async getPowerFlowRealtimeData(host: string): Promise { + static async getPowerFlowRealtimeData( + host: string + ): Promise { return this.get( host, 'solar_api/v1/GetPowerFlowRealtimeData.fcgi' diff --git a/backend/backend.ts b/backend/backend.ts index 2049aa1..96ef799 100644 --- a/backend/backend.ts +++ b/backend/backend.ts @@ -12,7 +12,7 @@ import chargeRoutes from './routes/chargeRoutes.js'; import configRoutes from './routes/configRoutes.js'; import configEnabledRoutes from './routes/configEnabledRoutes.js'; import configEnabledPowergridRoutes from './routes/configEnabledPowergridRoutes.js'; -import configPreferredPhase from './routes/configPreferredPhase.js' +import configPreferredPhase from './routes/configPreferredPhase.js'; import livedataRoutes from './routes/livedataRoutes.js'; import appInfoRoutes from './routes/appInfoRoutes.js'; import AppInfo from './classes/AppInfo.js'; @@ -37,7 +37,7 @@ app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpecs)); app.use(express.static('./svelte-build')); app.use('/', chargeRoutes); app.use('/', configRoutes); -app.use('/', configPreferredPhase) +app.use('/', configPreferredPhase); app.use('/', configEnabledRoutes); app.use('/', configEnabledPowergridRoutes); app.use('/', livedataRoutes); diff --git a/backend/classes/ConfigFile.ts b/backend/classes/ConfigFile.ts index a7547bd..b20b41d 100644 --- a/backend/classes/ConfigFile.ts +++ b/backend/classes/ConfigFile.ts @@ -58,7 +58,7 @@ export default class { value: 6740, onePhase: false } - ], + ] }; const dirPath = path.dirname(this.filePath); if (!fs.existsSync(dirPath)) { diff --git a/backend/classes/WebSocketManager.ts b/backend/classes/WebSocketManager.ts index 72d9029..4797878 100644 --- a/backend/classes/WebSocketManager.ts +++ b/backend/classes/WebSocketManager.ts @@ -51,7 +51,7 @@ export default class WebSocketManager { this.sendEvent('backendTerminalUpdate', { type, msg, ts }); } - public static sendEventPreferredPhase(state: Pick) { + public static sendEventPreferredPhase(state: Pick) { this.sendEvent('preferredPhaseUpdate', { state }); } diff --git a/backend/loop.ts b/backend/loop.ts index e88ebc7..d076946 100644 --- a/backend/loop.ts +++ b/backend/loop.ts @@ -142,11 +142,14 @@ function findClosestValue(availablePower: number, mappingArray: any[]): any { const maximumWatts = configFile.MaximumWatts; // Filter the mappings based on the preferredPhase and power constraints. - const filteredMappings = mappingArray.filter(item => { - return ((preferredPhase === 0) || // 0 for auto (accept all) - (preferredPhase === 1 && item.onePhase) || // 1 for phase 1 - (preferredPhase === 2 && !item.onePhase)) && // 2 for phase 3 - (item.value >= minimumWatts && item.value <= maximumWatts); // within min and max power range + const filteredMappings = mappingArray.filter((item) => { + return ( + (preferredPhase === 0 || // 0 for auto (accept all) + (preferredPhase === 1 && item.onePhase) || // 1 for phase 1 + (preferredPhase === 2 && !item.onePhase)) && // 2 for phase 3 + item.value >= minimumWatts && + item.value <= maximumWatts + ); // within min and max power range }); // If there are no mappings left after filtering, return a default response. @@ -159,13 +162,14 @@ function findClosestValue(availablePower: number, mappingArray: any[]): any { // Find the mapping that is closest to availablePower. const optimalMapping = filteredMappings.reduce((prev, curr) => { - return (Math.abs(curr.value - availablePower) < Math.abs(prev.value - availablePower)) ? curr : prev; + return Math.abs(curr.value - availablePower) < Math.abs(prev.value - availablePower) + ? curr + : prev; }); return optimalMapping; } - function calculateChargeSettings(config: InterfaceConfig) { const availablePower = LiveData.data.Inverter.Export + LiveData.data.Charger.Consumption; diff --git a/backend/models/InterfaceConfig.ts b/backend/models/InterfaceConfig.ts index 0e7ae2d..8677dac 100644 --- a/backend/models/InterfaceConfig.ts +++ b/backend/models/InterfaceConfig.ts @@ -11,6 +11,6 @@ export default interface InterfaceConfig { UsePowergrid: boolean; BatteryCapacity: number; CarEfficiency: number; - // 0 = Auto, 1 = One Phase, 2 = 3 Phases - PreferredPhase: 0 | 1 | 2 + // 0 = Auto, 1 = One Phase, 2 = 3 Phases + PreferredPhase: 0 | 1 | 2; } diff --git a/backend/routes/configPreferredPhase.ts b/backend/routes/configPreferredPhase.ts index dc0435b..8210d39 100644 --- a/backend/routes/configPreferredPhase.ts +++ b/backend/routes/configPreferredPhase.ts @@ -47,27 +47,27 @@ const r = express.Router(); * example: 'Error writing to config file' */ r.post('/preferredPhase', async (req, res) => { - const stateData = req.body.state; - if (stateData !== 0 && stateData !== 1 && stateData !== 2) { - res.status(400).json({ - msg: 'Bad Request: state must be 0, 1, or 2' - }); - return; - } - const configData = ConfigFile.read(); - configData.PreferredPhase = stateData; - const success = ConfigFile.write(configData); + const stateData = req.body.state; + if (stateData !== 0 && stateData !== 1 && stateData !== 2) { + res.status(400).json({ + msg: 'Bad Request: state must be 0, 1, or 2' + }); + return; + } + const configData = ConfigFile.read(); + configData.PreferredPhase = stateData; + const success = ConfigFile.write(configData); - // It's better to send events after ensuring that data is written successfully. - if (success) { - WebSocketManager.sendEventPreferredPhase(stateData); // Adjusted position - res.status(200).json({ msg: 'success' }); - } else { - errorLog('Error writing preferredPhase state to config file.'); - res.status(500).json({ - msg: 'Error writing to config file' - }); - } + // It's better to send events after ensuring that data is written successfully. + if (success) { + WebSocketManager.sendEventPreferredPhase(stateData); // Adjusted position + res.status(200).json({ msg: 'success' }); + } else { + errorLog('Error writing preferredPhase state to config file.'); + res.status(500).json({ + msg: 'Error writing to config file' + }); + } }); -export default r; \ No newline at end of file +export default r; diff --git a/dist/output.css b/dist/output.css index a4ce468..cb12f24 100644 --- a/dist/output.css +++ b/dist/output.css @@ -44,9 +44,21 @@ html { -o-tab-size: 4; tab-size: 4; /* 3 */ - font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, - 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', - 'Segoe UI Symbol', 'Noto Color Emoji'; + font-family: + ui-sans-serif, + system-ui, + -apple-system, + BlinkMacSystemFont, + 'Segoe UI', + Roboto, + 'Helvetica Neue', + Arial, + 'Noto Sans', + sans-serif, + 'Apple Color Emoji', + 'Segoe UI Emoji', + 'Segoe UI Symbol', + 'Noto Color Emoji'; /* 4 */ font-feature-settings: normal; /* 5 */ diff --git a/src/app.html b/src/app.html index 7358d27..dd948c1 100644 --- a/src/app.html +++ b/src/app.html @@ -1,4 +1,4 @@ - + diff --git a/src/lib/api/models/BackendLogs.ts b/src/lib/api/models/BackendLogs.ts index 3fffd4c..98fc211 100644 --- a/src/lib/api/models/BackendLogs.ts +++ b/src/lib/api/models/BackendLogs.ts @@ -1,7 +1,7 @@ export default interface BackendLogs { - items: { - type: string; - msg: string; - ts: string - }[]; + items: { + type: string; + msg: string; + ts: string; + }[]; } diff --git a/src/lib/api/models/Config.ts b/src/lib/api/models/Config.ts index 844b361..6cfaf53 100644 --- a/src/lib/api/models/Config.ts +++ b/src/lib/api/models/Config.ts @@ -11,6 +11,6 @@ export default interface Config { UsePowergrid: boolean; BatteryCapacity: number; CarEfficiency: number; - // 0 = Auto, 1 = One Phase, 2 = 3 Phases - PreferredPhase: 0 | 1 | 2 + // 0 = Auto, 1 = One Phase, 2 = 3 Phases + PreferredPhase: 0 | 1 | 2; } diff --git a/src/lib/api/services/ServiceConfigPreferredPhase.ts b/src/lib/api/services/ServiceConfigPreferredPhase.ts index f185bb8..cf3a57c 100644 --- a/src/lib/api/services/ServiceConfigPreferredPhase.ts +++ b/src/lib/api/services/ServiceConfigPreferredPhase.ts @@ -2,7 +2,7 @@ import type ResBase from '../models/ResBase'; import ApiBase from './ApiBase'; export default class extends ApiBase { - static async postEnabled(state: 0 | 1 | 2): Promise { - return this.post('preferredPhase', { state }); - } + static async postEnabled(state: 0 | 1 | 2): Promise { + return this.post('preferredPhase', { state }); + } } diff --git a/src/lib/api/services/ServiceWebsocket.ts b/src/lib/api/services/ServiceWebsocket.ts index 0fd01f7..2a86324 100644 --- a/src/lib/api/services/ServiceWebsocket.ts +++ b/src/lib/api/services/ServiceWebsocket.ts @@ -15,8 +15,7 @@ export default class { newErrorToast(errMsg); } else { this.socket = new WebSocket(`ws://${window.location.hostname}:${get(appInfo).webSocketPort}`); - } - + } this.socket.onmessage = (event) => { const message = JSON.parse(event.data); diff --git a/src/lib/components/SectionLiveData.svelte b/src/lib/components/SectionLiveData.svelte index c1cf467..1734259 100644 --- a/src/lib/components/SectionLiveData.svelte +++ b/src/lib/components/SectionLiveData.svelte @@ -150,10 +150,10 @@ {$liveData.Charger.PhaseMode === 0 ? 'Auto' : $liveData.Charger.PhaseMode === 1 - ? '1P' - : $liveData.Charger.PhaseMode === 2 - ? '3P' - : 'unknown'} + ? '1P' + : $liveData.Charger.PhaseMode === 2 + ? '3P' + : 'unknown'} {/if}

@@ -208,10 +208,10 @@ {$liveData.Charger.PhaseModeCalc === 0 ? 'Auto' : $liveData.Charger.PhaseModeCalc === 1 - ? '1P' - : $liveData.Charger.PhaseModeCalc === 2 - ? '3P' - : 'unknown'} + ? '1P' + : $liveData.Charger.PhaseModeCalc === 2 + ? '3P' + : 'unknown'} {/if}