Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add types to edgeconfig.ts #2699

Merged
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
75 changes: 37 additions & 38 deletions ui/src/app/shared/components/edge/edgeconfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { ChannelAddress, Widgets } from '../../shared';
import { Edge } from './edge';

Expand Down Expand Up @@ -105,7 +104,7 @@
* Lists all available Factories, grouped by category.
*/
public static listAvailableFactories(factories: { [id: string]: EdgeConfig.Factory }): CategorizedFactories[] {
const allFactories = [
const allFactories: CategorizedFactories[] = [

Check warning on line 107 in ui/src/app/shared/components/edge/edgeconfig.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/edge/edgeconfig.ts#L107

Added line #L107 was not covered by tests
{
category: { title: 'Simulatoren', icon: 'flask-outline' },
factories: Object.entries(factories)
Expand All @@ -118,15 +117,15 @@
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.meter.api.SymmetricMeter"), // TODO replaced by ElectricityMeter
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.meter.api.ElectricityMeter"),
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.ess.dccharger.api.EssDcCharger"),
],
].flat(2),
},
{
category: { title: 'Speichersysteme', icon: 'battery-charging-outline' },
factories: [
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.ess.api.SymmetricEss"),
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.battery.api.Battery"),
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.batteryinverter.api.ManagedSymmetricBatteryInverter"),
],
].flat(2),
},
{
category: { title: 'Speichersystem-Steuerung', icon: 'options-outline' },
Expand All @@ -136,28 +135,28 @@
/Controller\.Ess.*/,
/Controller\.Symmetric.*/,
]),
],
].flat(2),
},
{
category: { title: 'E-Auto-Ladestation', icon: 'car-outline' },
factories: [
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.evcs.api.Evcs"),
],
].flat(2),
},
{
category: { title: 'E-Auto-Ladestation-Steuerung', icon: 'options-outline' },
factories: [
EdgeConfig.getFactoriesByIds(factories, [
'Controller.Evcs',
]),
],
].flat(2),
},
{
category: { title: 'I/Os', icon: 'log-in-outline' },
factories: [
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.io.api.DigitalOutput"),
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.io.api.DigitalInput"),
],
].flat(2),
},
{
category: { title: 'I/O-Steuerung', icon: 'options-outline' },
Expand All @@ -168,13 +167,13 @@
'Controller.IO.HeatingElement',
'Controller.Io.HeatPump.SgReady',
]),
],
].flat(2),
},
{
category: { title: 'Temperatursensoren', icon: 'thermometer-outline' },
factories: [
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.thermometer.api.Thermometer"),
],
].flat(2),
},
{
category: { title: 'Externe Schnittstellen', icon: 'megaphone-outline' },
Expand All @@ -188,7 +187,7 @@
'Controller.Api.Rest.ReadOnly',
'Controller.Api.Rest.ReadWrite',
]),
],
].flat(2),
},
{
category: { title: 'Cloud-Schnittstellen', icon: 'cloud-outline' },
Expand All @@ -199,7 +198,7 @@
EdgeConfig.getFactoriesByIds(factories, [
'Controller.Api.Backend',
]),
],
].flat(2),
},
{
category: { title: 'Geräte-Schnittstellen', icon: 'swap-horizontal-outline' },
Expand All @@ -211,7 +210,7 @@
'Bridge.Modbus.Tcp',
'Kaco.BlueplanetHybrid10.Core',
]),
],
].flat(2),
},
{
category: { title: 'Standard-Komponenten', icon: 'resize-outline' },
Expand All @@ -223,13 +222,13 @@
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.timedata.api.Timedata"),
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.predictor.api.oneday.Predictor24Hours"),
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.scheduler.api.Scheduler"),
],
].flat(2),
},
{
category: { title: 'Spezial-Controller', icon: 'repeat-outline' },
factories: [
EdgeConfig.getFactoriesByNature(factories, "io.openems.edge.controller.api.Controller"),
],
].flat(2),
},
{
category: { title: 'Weitere', icon: 'radio-button-off-outline' },
Expand All @@ -241,8 +240,7 @@
const result: CategorizedFactories[] = [];
allFactories.forEach(item => {
const factories =
// create one flat array
[].concat(...item.factories)
item.factories

Check warning on line 243 in ui/src/app/shared/components/edge/edgeconfig.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/edge/edgeconfig.ts#L243

Added line #L243 was not covered by tests
// remove Factories from list that have already been listed before
.filter(factory => !ignoreFactoryIds.includes(factory.id))
// remove duplicates
Expand Down Expand Up @@ -588,10 +586,9 @@
const allComponents = [];
const factories = this.listAvailableFactories();
for (const entry of factories) {
const components = [];
const components: EdgeConfig.Component[] = [];

Check warning on line 589 in ui/src/app/shared/components/edge/edgeconfig.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/edge/edgeconfig.ts#L589

Added line #L589 was not covered by tests
for (const factory of entry.factories) {
components.push(this.getComponentsByFactory(factory.id));
// components.concat(...this.getComponentsByFactory(factory.id));
components.concat(...this.getComponentsByFactory(factory.id));

Check warning on line 591 in ui/src/app/shared/components/edge/edgeconfig.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/edge/edgeconfig.ts#L591

Added line #L591 was not covered by tests
}
allComponents.push({
category: entry.category,
Expand All @@ -601,8 +598,7 @@
const result: CategorizedComponents[] = [];
allComponents.forEach(item => {
const components =
// create one flat array
[].concat(...item.components)
item.components

Check warning on line 601 in ui/src/app/shared/components/edge/edgeconfig.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/edge/edgeconfig.ts#L601

Added line #L601 was not covered by tests
// remove Components from list that have already been listed before
.filter(component => !ignoreComponentIds.includes(component.id))
// remove duplicates
Expand Down Expand Up @@ -661,9 +657,9 @@
*
* @param address the ChannelAddress
*/
public getChannel(address: ChannelAddress): EdgeConfig.ComponentChannel {
public getChannel(address: ChannelAddress): EdgeConfig.ComponentChannel | null {
const component = this.components[address.componentId];
if (component) {
if (component?.channels) {
return component.channels[address.channelId];
} else {
return null;
Expand Down Expand Up @@ -701,13 +697,13 @@

export module EdgeConfig {
export class ComponentChannel {
public readonly type: "BOOLEAN" | "SHORT" | "INTEGER" | "LONG" | "FLOAT" | "DOUBLE" | "STRING";
public readonly accessMode: "RO" | "RW" | "WO";
public readonly unit: string;
public readonly category: "OPENEMS_TYPE" | "ENUM" | "STATE";
public readonly level: "INFO" | "OK" | "WARNING" | "FAULT";
public readonly persistencePriority: PersistencePriority;
public readonly text: string;
public readonly type!: "BOOLEAN" | "SHORT" | "INTEGER" | "LONG" | "FLOAT" | "DOUBLE" | "STRING";
public readonly accessMode!: "RO" | "RW" | "WO";
public readonly unit!: string;
public readonly category!: "OPENEMS_TYPE" | "ENUM" | "STATE";
public readonly level!: "INFO" | "OK" | "WARNING" | "FAULT";
public readonly persistencePriority?: PersistencePriority;
public readonly text!: string;
public readonly options?: { [key: string]: number };
}

Expand All @@ -724,14 +720,17 @@
}

export class FactoryProperty {
public readonly id: string;
public readonly name: string;
public readonly description: string;
public readonly isRequired: boolean;
public readonly defaultValue: any;
public readonly schema: {};
public readonly id!: string;
public readonly name!: string;
public readonly description!: string;
public readonly type!: string;
public readonly isRequired!: boolean;
public readonly isPassword!: boolean;
public readonly defaultValue!: any;
public readonly schema!: {};
}


export class Factory {
public id: string = "";
public componentIds: string[] = [];
Expand All @@ -748,7 +747,7 @@
*
* @param propertyId the Property-ID
*/
static getPropertyForId(factory: Factory, propertyId: string): FactoryProperty {
static getPropertyForId(factory: Factory, propertyId: string): FactoryProperty | null {
for (const property of factory.properties) {
if (property.id === propertyId) {
return property;
Expand Down
2 changes: 1 addition & 1 deletion ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"module": "es2020",
"noImplicitOverride": true,
"lib": [
"es2019",
"es2022",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lib es version is bumped to es2022 to use .flat().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

generally target es version is lower than lib es version to compatibility.
but this project target es is higher than lib es version. ??
anyway, it is not change of target es version, so I think no effect browser compatibility.

"dom"
],
"resolveJsonModule": true,
Expand Down