Skip to content
Merged
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
47 changes: 28 additions & 19 deletions packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ export const useMqttStore = defineStore('mqtt', () => {
return dcMaxCurrent === undefined
? undefined
: convertDcCurrentToPower(dcMaxCurrent);
});
});

/**
* Get or set the charge point connected vehicle instant charging DC power identified by the charge point id
Expand Down Expand Up @@ -3706,18 +3706,31 @@ export const useMqttStore = defineStore('mqtt', () => {
////////////////////////////// consumer data ////////////////////////////////

/**
* Get a list of all consumers.
* Get a list of all consumers in the order of the hierarchy.
* @returns Consumer[]
*/
const consumerList = computed<Consumer[]>(() => {
const modules = getWildcardValues.value('openWB/consumer/+/module');
return Object.keys(modules)
.map((key) => {
const id = parseInt(key.split('/')[2]);
const module = modules[key] as ConsumerModule | undefined;
return getObjectIds
.value('consumer')
.filter((id) => accessConsumerAllowed.value(id))
.map((id) => {
const module = modules[`openWB/consumer/${id}/module`] as
ConsumerModule | undefined;
return { id, name: module?.name ?? `Verbraucher ${id}` };
})
.sort((a, b) => a.id - b.id);
});
Comment on lines +3714 to +3721

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Benutzerverwaltung kann dafür sorgen, dass ein Verbraucher zwar in der Hierarchie vorhanden ist, jedoch das Modul-Topic nicht empfangen wird. In dem Fall darf der Verbraucher nicht angezeigt werden. Siehe z.B. Z.935 für die Ladepunkte.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Z.3716 gibt es den Filter auf Verbraucher Module Topic , dadurch ist schon geprüft ob der Nutzer Rechte hat oder? Ich habe es kommentiert.

Oder wäre es besser mit ein helper "accessConsumerAllowed " wie bei CP's

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stimmt, hatte ich übersehen. Eine Hilfsmethode wäre aber schon besser, da die auch in anderen Situationen verwendet werden kann (z.B. vor dem Schalten eines Verbrauchers).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper accessConsumerAllowed hinzugefügt

});

/**
* Check if access to a specific consumer is allowed
* @param consumerId
* @returns boolean
*/
const accessConsumerAllowed = computed(() => {
return (consumerId: number) => {
const modules = getWildcardValues.value('openWB/consumer/+/module');
return `openWB/consumer/${consumerId}/module` in modules;
};
});

/**
Expand Down Expand Up @@ -3789,8 +3802,7 @@ export const useMqttStore = defineStore('mqtt', () => {
const consumerSumPower = computed(() => {
return (returnType: string = 'textValue') => {
const power = getValue.value('openWB/consumer/get/power') as
| number
| undefined;
number | undefined;
const valueObject = getValueObject.value(power);
if (Object.hasOwn(valueObject, returnType)) {
return valueObject[returnType as keyof ValueObject];
Expand Down Expand Up @@ -3840,8 +3852,7 @@ export const useMqttStore = defineStore('mqtt', () => {
const consumerOnTime = computed(() => {
return (consumerId: number): number | undefined => {
return getValue.value(`openWB/consumer/${consumerId}/set/on_time`) as
| number
| undefined;
number | undefined;
};
});

Expand Down Expand Up @@ -3890,8 +3901,7 @@ export const useMqttStore = defineStore('mqtt', () => {
const consumerStateStr = computed(() => {
return (consumerId: number): string | undefined => {
return getValue.value(`openWB/consumer/${consumerId}/get/state_str`) as
| string
| undefined;
string | undefined;
};
});

Expand Down Expand Up @@ -3920,8 +3930,7 @@ export const useMqttStore = defineStore('mqtt', () => {
const consumerFaultStr = computed(() => {
return (consumerId: number): string | undefined => {
return getValue.value(`openWB/consumer/${consumerId}/get/fault_str`) as
| string
| undefined;
string | undefined;
};
});

Expand All @@ -3933,8 +3942,7 @@ export const useMqttStore = defineStore('mqtt', () => {
const consumerUsageType = computed(() => {
return (consumerId: number): ConsumerUsageType | undefined => {
return getValue.value(`openWB/consumer/${consumerId}/usage`, 'type') as
| ConsumerUsageType
| undefined;
ConsumerUsageType | undefined;
};
});

Expand Down Expand Up @@ -4349,7 +4357,7 @@ export const useMqttStore = defineStore('mqtt', () => {
);
});

/**
/**
* Get the hybrid inverter/battery pairs. A battery is treated as "hybrid"
* when it is a direct child of an inverter in the component hierarchy
* The pairing is needed for the flow calculation - (Sankey Chart).
Expand Down Expand Up @@ -4713,6 +4721,7 @@ export const useMqttStore = defineStore('mqtt', () => {
batteryColor,
// Consumer data
consumerList,
accessConsumerAllowed,
consumerIds,
consumerName,
consumerColor,
Expand Down
Loading