Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ const notInHomeVariants = {
iconColor: 'var(--q-secondary-counter-stroke)',
},
};
// follows the counters listed in the details: if all of them are hidden, the
// node only shows consumers
const notInHomeVariant = computed(() => {
if (!countersNotInHome.value) {
if (mqttStore.shownCounterIds.notInHome.length === 0) {
return notInHomeVariants.consumer;
}
return mqttStore.notInHomeConsumption.consumerIds.length > 0
Expand All @@ -171,12 +173,12 @@ const openDetails = (event: MouseEvent, component: FlowComponent) => {
const homeHasDetails = computed(
() =>
mqttStore.inHomeConsumption.consumerIds.length > 0 ||
mqttStore.inHomeConsumption.counterIds.length > 0,
mqttStore.shownCounterIds.inHome.length > 0,
);
const notInHomeHasDetails = computed(
() =>
mqttStore.notInHomeConsumption.consumerIds.length > 0 ||
mqttStore.notInHomeConsumption.counterIds.length > 0,
mqttStore.shownCounterIds.notInHome.length > 0,
);
const showConsumerPower = computed(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ const visible = computed({
});

const items = computed((): DetailsItem[] => {
const { consumerIds, counterIds } =
const { consumerIds } =
props.scope === 'inHome'
? mqttStore.inHomeConsumption
: mqttStore.notInHomeConsumption;
const counterIds = mqttStore.shownCounterIds[props.scope];
const unmeasured =
props.scope === 'inHome' &&
mqttStore.unmeasuredHomeConsumptionPower('value') !== undefined
Expand Down Expand Up @@ -109,7 +110,7 @@ const items = computed((): DetailsItem[] => {
color:
mqttStore.secondaryCounterColor(id) ||
'var(--q-secondary-counter-stroke)',
power: mqttStore.counterPower('textValue', id) as string,
power: mqttStore.counterLocalPower('textValue', id) as string,
})),
...unmeasured,
];
Expand Down
72 changes: 69 additions & 3 deletions packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4267,6 +4267,32 @@ export const useMqttStore = defineStore('mqtt', () => {
};
});

/**
* Get the counter's own share of power: its power minus the power of the
* components directly below it. identified by counterId
* @param returnType type of return value, 'textValue', 'value', 'scaledValue', 'scaledUnit' or 'object'
* @param counterId counter ID
* @returns string | number | ValueObject | undefined
*/
const counterLocalPower = computed(() => {
return (returnType: string = 'textValue', counterId?: number) => {
const id = counterId;
let localPower = undefined;
if (id !== undefined) {
localPower = getValue.value(`openWB/counter/${id}/get/local_power`) as
number | undefined;
}
const valueObject = getValueObject.value(localPower);
if (returnType in valueObject) {
return valueObject[returnType as keyof ValueObject];
}
if (returnType == 'object') {
return valueObject;
}
console.error('returnType not found!', returnType, localPower);
};
});

/**
* Get daily counter energy imported identified by root grid counter in component hierarchy or counterId
* @param returnType type of return value, 'textValue', 'value', 'scaledValue', 'scaledUnit' or 'object'
Expand Down Expand Up @@ -4424,6 +4450,7 @@ export const useMqttStore = defineStore('mqtt', () => {
const ids = () => ({
consumerIds: [] as number[],
counterIds: [] as number[],
counterIdsWithChildren: [] as number[],
});
const result = { inHome: ids(), notInHome: ids() };
function walk(
Expand All @@ -4442,10 +4469,19 @@ export const useMqttStore = defineStore('mqtt', () => {
AUTO,
) as string | undefined;
const mode = own && own !== AUTO ? own : parentMode;
let bucket;
if (mode === NOT_HOME) {
result.notInHome.counterIds.push(node.id);
} else if (!isRoot) {
result.inHome.counterIds.push(node.id);
bucket = result.notInHome;
} else if (isRoot) {
bucket = undefined;
} else {
bucket = result.inHome;
}
if (bucket) {
bucket.counterIds.push(node.id);
if (node.children?.length) {
bucket.counterIdsWithChildren.push(node.id);
}
}
walk(node.children, mode, false);
} else if (node.type === 'consumer') {
Expand Down Expand Up @@ -4490,6 +4526,34 @@ export const useMqttStore = defineStore('mqtt', () => {
() => homeConsumptionAssignment.value.notInHome,
);

// own share in W below which a counter with components below it is hidden
// (threshold for showing in the home consumption details)
const COUNTER_OWN_SHARE_THRESHOLD = 50;

/**
* Get the counters to list in the home consumption details. A counter with
* components below it is left out if its own share is negligible, as it
* then only measures those components.
* @returns object with the keys inHome and notInHome, each holding counter ids
*/
const shownCounterIds = computed(() => {
const shown = (bucket: {
counterIds: number[];
counterIdsWithChildren: number[];
}) => {
// a counter that only measures the components below it is hidden
const hidden = (id: number) =>
bucket.counterIdsWithChildren.includes(id) &&
Math.abs(Number(counterLocalPower.value('value', id) ?? 0)) <
COUNTER_OWN_SHARE_THRESHOLD;
return bucket.counterIds.filter((id) => !hidden(id));
};
return {
inHome: shown(inHomeConsumption.value),
notInHome: shown(notInHomeConsumption.value),
};
});

/**
* Get the summed power of all consumers and counters that are not counted
* in the home consumption.
Expand Down Expand Up @@ -4899,13 +4963,15 @@ export const useMqttStore = defineStore('mqtt', () => {
componentName,
gridComponentColor,
counterPower,
counterLocalPower,
counterDailyImported,
counterDailyExported,
// Home data
homePower,
homeDailyYield,
inHomeConsumption,
notInHomeConsumption,
shownCounterIds,
notInHomeConsumptionPower,
unmeasuredHomeConsumptionPower,
// PV data
Expand Down
Loading