Skip to content

Commit

Permalink
fix: display proper brightness values for v2.21. closes #133
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Apr 7, 2023
1 parent 68e9431 commit 3f44fc5
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions ui/src/stores/appstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { defineStore } from 'pinia';
import { socket } from '../socket';
import settingDescriptions from '../setting-descriptions.js';
import settingToComponentMap from '../setting-components.js';

export const useAppStore = defineStore('appStore', () => {
const appInfo = ref({});
const settings = ref({});
const rawLiveData = ref({});
const rawSettings = ref({});
const peakWatts = ref(0);
const isSaveToFlash = ref(false);
const isBusy = ref(false);
Expand All @@ -26,7 +26,20 @@ export const useAppStore = defineStore('appStore', () => {
PeakWatts: peakWatts.value.toFixed(1),
};
});

const settingsComponents = computed(() => {
const components = { ...settingToComponentMap };
if (info.value?.build === 'v2.21') {
components.Brightness = {
name: 'range',
min: 1,
max: 101,
step: 25,
display: (value) => ((value - 1) / 25 + 1),
};
}
return components;
});

const init = async () => {
await fetchAppInfo();
await fetchSettings();
Expand All @@ -48,18 +61,18 @@ export const useAppStore = defineStore('appStore', () => {
await socket.send({ command: 'GET_APP_INFO' });
};

const parseSettings = (rawSettings) => {
for (const name in rawSettings) {
const value = Number(rawSettings[name]);
const parseSettings = () => {
for (const name in rawSettings.value) {
const value = Number(rawSettings.value[name]);
settings.value[name] = {
value,
lastSent: value,
display: settingDescriptions[name]?.displayText ?? name,
hint: settingDescriptions[name]?.description ?? '',
component: settingToComponentMap[name],
component: settingsComponents.value[name],
isUpdating: false,
};
const isBooleanField = settingToComponentMap[name]?.name === 'checkbox';
const isBooleanField = settingsComponents.value[name]?.name === 'checkbox';
if (isBooleanField) {
settings.value[name].value = value === 1;
}
Expand Down Expand Up @@ -145,15 +158,16 @@ export const useAppStore = defineStore('appStore', () => {
};

socket.on('GET_SETTINGS', (data) => {
parseSettings(data);
rawSettings.value = data;
parseSettings();
isBusy.value = false;
});
socket.on('GET_INFO', (data) => {
info.value = data;
parseSettings();
isBusy.value = false;
});
socket.on('GET_APP_INFO', (data) => {
console.log(data);
appInfo.value = data;
isBusy.value = false;
});
Expand Down

0 comments on commit 3f44fc5

Please sign in to comment.