Skip to content

Commit

Permalink
Merge pull request #77 from davbauer/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
davbauer authored Mar 28, 2024
2 parents 11a2d89 + 41b0cd1 commit 6ce3909
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 57 deletions.
Binary file modified assets/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion backend/classes/AppInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import InterfaceAppInfo from '../models/InterfaceAppInfo.js';

export default class {
static get(): InterfaceAppInfo {
const webSocketPort =
process.env.WEBSOCK_PORT !== undefined ? Number(process.env.WEBSOCK_PORT) : 81;
return {
webSocketPort: Number(process.env.WEBSOCK_PORT) || 81,
webSocketPort,
gitCommitId: process.env.COMMITID || 'undefined',
gitBranchName: process.env.BRANCH || 'undefined',
uptime: process.uptime(),
Expand Down
6 changes: 3 additions & 3 deletions backend/classes/ConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ export default class {
typeof data.CheckSeconds === 'number' &&
typeof data.MinimumWatts === 'number' &&
typeof data.MaximumWatts === 'number' &&
typeof data.UsePowergrid === 'boolean' &&
typeof data.CarEfficiency === 'number' &&
typeof data.OffsetWatts === 'number' &&
typeof data.BatteryCapacity === 'number' &&
typeof data.OffsetWatts === 'number'
typeof data.CarEfficiency === 'number' &&
typeof data.PreferredPhase === 'number'
);
}
}
10 changes: 1 addition & 9 deletions backend/classes/WebSocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ export default class WebSocketManager {

this.wss.on('connection', (clientWs: ws.WebSocket) => {
const clientWithID = clientWs as WebSocketWithID;
clientWithID.id = uuidv4(); // Assign a UUID to the client
clientWithID.id = uuidv4();

this.clients.push(clientWithID);
infoLog(`WS Client connection established (Id: ${clientWithID.id})`);
// Send initial data to the client immediately upon connection.
clientWithID.send(
JSON.stringify({
wsConnectionId: clientWithID.id ?? 'undefined',
event: 'liveDataUpdate',
data: LiveData.data
})
);

clientWithID.on('close', () => {
const index = this.clients.findIndex((client) => client.id === clientWithID.id);
Expand Down
4 changes: 2 additions & 2 deletions backend/loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default async function (): Promise<void> {

const config: InterfaceConfig = ConfigFile.read();

infoLog(`Mode: '${config.Mode}'`);

const mainInverterPowerFlow = await InverterService.getPowerFlowRealtimeData(
ConfigFile.read().MainInverterHost
);
Expand Down Expand Up @@ -87,7 +89,6 @@ export default async function (): Promise<void> {
const result = calculateChargeSettings(config);
Object.assign(LiveData.data.Charger, result);
if (config.Mode === 'force_off') {
infoLog(`Mode set to '${config.Mode}'`);
if (LiveData.data.Charger.Status === CAR_CHARGING) {
infoLog('Car is charging -> forcing off!');
await ChargerService.setChargeStart();
Expand All @@ -96,7 +97,6 @@ export default async function (): Promise<void> {
return;
}
if (config.Mode === 'sleep') {
infoLog(`Mode set to '${config.Mode}'`);
WebSocketManager.sendEventLiveData();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"axios": "^1.6.7",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"express": "^4.19.2",
"morgan": "^1.10.0",
"openapi-types": "^12.1.3",
"swagger-jsdoc": "^6.2.8",
Expand Down
42 changes: 21 additions & 21 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,21 @@ basic-auth@~2.0.1:
dependencies:
safe-buffer "5.1.2"

body-parser@1.20.1:
version "1.20.1"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.1.tgz#b1812a8912c195cd371a3ee5e66faa2338a5c668"
integrity sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==
body-parser@1.20.2:
version "1.20.2"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.2.tgz#6feb0e21c4724d06de7ff38da36dad4f57a747fd"
integrity sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==
dependencies:
bytes "3.1.2"
content-type "~1.0.4"
content-type "~1.0.5"
debug "2.6.9"
depd "2.0.0"
destroy "1.2.0"
http-errors "2.0.0"
iconv-lite "0.4.24"
on-finished "2.4.1"
qs "6.11.0"
raw-body "2.5.1"
raw-body "2.5.2"
type-is "~1.6.18"
unpipe "1.0.0"

Expand Down Expand Up @@ -354,7 +354,7 @@ content-disposition@0.5.4:
dependencies:
safe-buffer "5.2.1"

content-type@~1.0.4:
content-type@~1.0.4, content-type@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918"
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==
Expand All @@ -364,10 +364,10 @@ cookie-signature@1.0.6:
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==

cookie@0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b"
integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==
cookie@0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051"
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==

cors@^2.8.5:
version "2.8.5"
Expand Down Expand Up @@ -467,17 +467,17 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==

express@^4.18.2:
version "4.18.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59"
integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==
express@^4.19.2:
version "4.19.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465"
integrity sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==
dependencies:
accepts "~1.3.8"
array-flatten "1.1.1"
body-parser "1.20.1"
body-parser "1.20.2"
content-disposition "0.5.4"
content-type "~1.0.4"
cookie "0.5.0"
cookie "0.6.0"
cookie-signature "1.0.6"
debug "2.6.9"
depd "2.0.0"
Expand Down Expand Up @@ -814,10 +814,10 @@ range-parser@~1.2.1:
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==

raw-body@2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.1.tgz#fe1b1628b181b700215e5fd42389f98b71392857"
integrity sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==
raw-body@2.5.2:
version "2.5.2"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.2.tgz#99febd83b90e08975087e8f1f9419a149366b68a"
integrity sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==
dependencies:
bytes "3.1.2"
http-errors "2.0.0"
Expand Down
8 changes: 8 additions & 0 deletions src/lib/api/services/ServiceLiveData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type LiveData from '$lib/models/LiveData';
import ApiBase from './ApiBase';

export default class extends ApiBase {
static async getLiveData(): Promise<LiveData> {
return this.get<LiveData>('livedata');
}
}
12 changes: 8 additions & 4 deletions src/lib/components/SectionModeSwitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,36 @@
<div class="flex justify-center">
<div class="text-center join">
<button
data-tip="Force Off"
class="join-item btn tooltip"
on:click={() => onModeChange('force_off')}
class="join-item btn"
class:btn-active={$config.Mode === 'force_off'}
class:btn-primary={$config.Mode === 'force_off'}
>
<IconPower />
</button>
<button
data-tip="Sleep"
class="join-item btn tooltip"
on:click={() => onModeChange('sleep')}
class="join-item btn"
class:btn-active={$config.Mode === 'sleep'}
class:btn-primary={$config.Mode === 'sleep'}
>
<IconZzz />
</button>
<button
data-tip="Sun"
class="join-item btn tooltip"
on:click={() => onModeChange('sun')}
class="join-item btn"
class:btn-active={$config.Mode === 'sun'}
class:btn-primary={$config.Mode === 'sun'}
>
<IconSunHigh />
</button>
<button
data-tip="Sun+Force"
class="join-item btn tooltip"
on:click={() => onModeChange('sun_force')}
class="join-item btn"
class:btn-active={$config.Mode === 'sun_force'}
class:btn-primary={$config.Mode === 'sun_force'}
>
Expand Down
9 changes: 6 additions & 3 deletions src/lib/components/SectionPhaseSwitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@
<div class="flex justify-center">
<div class="text-center join">
<button
data-tip="Auto"
class="join-item btn tooltip"
on:click={() => onPreferredPhaseChange(0)}
class="join-item btn"
class:btn-active={$config.PreferredPhase === 0}
class:btn-info={$config.PreferredPhase === 0}
>
<IconSwitch2 />
</button>
<button
data-tip="Phase 1"
class="join-item btn tooltip"
on:click={() => onPreferredPhaseChange(1)}
class="join-item btn"
class:btn-active={$config.PreferredPhase === 1}
class:btn-info={$config.PreferredPhase === 1}
>
<IconNumber1 />
</button>
<button
data-tip="Phase 3"
class="join-item btn tooltip"
on:click={() => onPreferredPhaseChange(2)}
class="join-item btn"
class:btn-active={$config.PreferredPhase === 2}
class:btn-info={$config.PreferredPhase === 2}
>
Expand Down
22 changes: 16 additions & 6 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import '../app.css';
import { appInfo, config, toasts } from '$lib/store';
import { appInfo, config, liveData, toasts } from '$lib/store';
import Toast from '$lib/components/Toast.svelte';
import { onMount } from 'svelte';
import ServiceAppInfo from '$lib/api/services/ServiceAppInfo';
Expand All @@ -10,20 +10,30 @@
import BackendTerminalWindow from '$lib/components/SectionBackendTerminal.svelte';
import SectionBackendTerminal from '$lib/components/SectionBackendTerminal.svelte';
import moment from 'moment';
import ServiceLiveData from '$lib/api/services/ServiceLiveData';
import { sendActivitySignal } from '$lib/utilities/UtilStoreActivityDot';
import { SignalStateType } from '$lib/models/SignalStateType';
import ServiceWebsocket from '$lib/api/services/ServiceWebsocket';
let initApplication: 'ERROR' | 'SUCCESS' | 'LOADING' = 'LOADING';
onMount(() => {
Promise.all([ServiceAppInfo.getAppInfo(), ServiceConfig.getConfig()])
.then(([appInfoResponse, configResponse]) => {
Promise.all([
ServiceAppInfo.getAppInfo(),
ServiceConfig.getConfig(),
ServiceLiveData.getLiveData()
])
.then(([appInfoResponse, configResponse, liveDataResponse]) => {
appInfo.set(appInfoResponse);
console.log(JSON.stringify(configResponse, null, 2));
config.set(configResponse);
newSuccessToast('Loaded app info and config');
liveData.set(liveDataResponse);
sendActivitySignal(SignalStateType.LIVEDATA);
newSuccessToast('Loaded app info, config and liveData');
ServiceWebsocket.initSocket();
initApplication = 'SUCCESS';
})
.catch((_error) => {
newErrorToast('Error loading app info or config');
newErrorToast('Error loading app info, config and liveData');
initApplication = 'ERROR';
});
});
Expand Down
6 changes: 0 additions & 6 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<script lang="ts">
import { onMount } from 'svelte';
import SectionChargeControl from '$lib/components/SectionChargeControl.svelte';
import SectionLiveData from '$lib/components/SectionLiveData.svelte';
import SectionAmpereMapping from '$lib/components/SectionAmpereMapping.svelte';
import SectionSettings from '$lib/components/SectionSettings.svelte';
import ServiceWebsocket from '$lib/api/services/ServiceWebsocket';
import SectionPhaseSwitch from '$lib/components/SectionPhaseSwitch.svelte';
import SectionModeSwitch from '$lib/components/SectionModeSwitch.svelte';
onMount(async () => {
ServiceWebsocket.initSocket();
});
</script>

<div class="m-3 text-lg leading-loose">
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
themes: [
{
custom: {
...require('daisyui/src/theming/themes')['dark'],
...require('daisyui/src/theming/themes')['dracula'],
'--rounded-badge': '0.8rem'
}
}
Expand Down

0 comments on commit 6ce3909

Please sign in to comment.