Skip to content
Closed
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 @@ -145,12 +145,17 @@ const notInHomeVariants = {
},
};
const notInHomeVariant = computed(() => {
if (!countersNotInHome.value) {
return notInHomeVariants.consumer;
const { consumerIds, counterIdsWithoutChildren } =
mqttStore.notInHomeConsumption;
if (consumerIds.length > 0) {
// counters with children are not listed in the details
return counterIdsWithoutChildren.length > 0
? notInHomeVariants.mixed
: notInHomeVariants.consumer;
}
return mqttStore.notInHomeConsumption.consumerIds.length > 0
? notInHomeVariants.mixed
: notInHomeVariants.counter;
return countersNotInHome.value
? notInHomeVariants.counter
: notInHomeVariants.consumer;
});
const detailsVisible = ref(false);
const detailsScope = ref<'inHome' | 'notInHome'>('inHome');
Expand All @@ -171,12 +176,12 @@ const openDetails = (event: MouseEvent, component: FlowComponent) => {
const homeHasDetails = computed(
() =>
mqttStore.inHomeConsumption.consumerIds.length > 0 ||
mqttStore.inHomeConsumption.counterIds.length > 0,
mqttStore.inHomeConsumption.counterIdsWithoutChildren.length > 0,
);
const notInHomeHasDetails = computed(
() =>
mqttStore.notInHomeConsumption.consumerIds.length > 0 ||
mqttStore.notInHomeConsumption.counterIds.length > 0,
mqttStore.notInHomeConsumption.counterIdsWithoutChildren.length > 0,
);
const showConsumerPower = computed(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const visible = computed({
});

const items = computed((): DetailsItem[] => {
const { consumerIds, counterIds } =
const { consumerIds, counterIdsWithoutChildren } =
props.scope === 'inHome'
? mqttStore.inHomeConsumption
: mqttStore.notInHomeConsumption;
Expand All @@ -102,7 +102,7 @@ const items = computed((): DetailsItem[] => {
color: mqttStore.consumerColor(id) || 'var(--q-consumer)',
power: mqttStore.consumerPower(id, 'textValue') as string,
})),
...counterIds.map((id) => ({
...counterIdsWithoutChildren.map((id) => ({
key: `counter-${id}`,
name: mqttStore.componentName(id) || `Zähler ${id}`,
icon: CounterIcon,
Expand Down
19 changes: 15 additions & 4 deletions packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4389,14 +4389,16 @@ export const useMqttStore = defineStore('mqtt', () => {
* Sort the consumers and sub-counters by whether they are counted in the
* home consumption. The root counter is only listed if it is excluded.
* @returns object with the keys inHome and notInHome, each holding the ids
* of the consumers and counters
* of the consumers and counters. counterIdsWithoutChildren holds the
* counters that have no components below them.
*/
const homeConsumptionAssignment = computed(() => {
const AUTO = 'auto_home_consumption';
const NOT_HOME = 'no_home_consumption';
const ids = () => ({
consumerIds: [] as number[],
counterIds: [] as number[],
counterIdsWithoutChildren: [] as number[],
});
const result = { inHome: ids(), notInHome: ids() };
function walk(
Expand All @@ -4415,10 +4417,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.counterIdsWithoutChildren.push(node.id);
}
}
walk(node.children, mode, false);
} else if (node.type === 'consumer') {
Expand Down