Skip to content

Commit

Permalink
Rename to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
longzheng committed Dec 11, 2024
1 parent 791a5e3 commit 4231de6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
}
]
},
"outputActiveLimits": {
"publish": {
"type": "object",
"properties": {
"mqtt": {
Expand Down Expand Up @@ -444,7 +444,7 @@
}
},
"additionalProperties": false,
"description": "Optionally output active control limits"
"description": "Publish active control limits"
}
},
"required": [
Expand Down
6 changes: 3 additions & 3 deletions src/coordinator/helpers/inverterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { CappedArrayStack } from '../../helpers/cappedArrayStack.js';
import { timeWeightedAverage } from '../../helpers/timeWeightedAverage.js';
import { differenceInSeconds } from 'date-fns';
import { type ControlsModel } from '../../connections/sunspec/models/controls.js';
import { ActiveLimitOutput } from './activeLimitOutput.js';
import { Publish } from './publish.js';

export type SupportedControlTypes = Extract<
ControlType,
Expand Down Expand Up @@ -70,7 +70,7 @@ const defaultValues = {
} as const satisfies Record<ControlType, unknown>;

export class InverterController {
private activeLimitOutput: ActiveLimitOutput;
private activeLimitOutput: Publish;
private cachedDerSample = new CappedArrayStack<DerSample>({ limit: 100 });
private cachedSiteSample = new CappedArrayStack<SiteSample>({ limit: 100 });
private logger: Logger;
Expand Down Expand Up @@ -107,7 +107,7 @@ export class InverterController {
inverterConfiguration: InverterConfiguration,
) => Promise<void>;
}) {
this.activeLimitOutput = new ActiveLimitOutput({ config });
this.activeLimitOutput = new Publish({ config });
this.secondsToSample = config.inverterControl.sampleSeconds;
this.controlFrequencyMinimumSeconds =
config.inverterControl.controlFrequencyMinimumSeconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ import mqtt from 'mqtt';
import { type Config } from '../../helpers/config.js';
import { type ActiveInverterControlLimit } from './inverterController.js';

export class ActiveLimitOutput {
export class Publish {
private mqttClient: mqtt.MqttClient | undefined;

constructor({ config }: { config: Config }) {
if (config.outputActiveLimits?.mqtt) {
this.mqttClient = mqtt.connect(
config.outputActiveLimits.mqtt.host,
{
username: config.outputActiveLimits.mqtt.username,
password: config.outputActiveLimits.mqtt.password,
},
);
if (config.publish?.mqtt) {
this.mqttClient = mqtt.connect(config.publish.mqtt.host, {
username: config.publish.mqtt.username,
password: config.publish.mqtt.password,
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ A longer time will smooth out load changes but may result in overshoot.`,
})
.describe('MQTT meter configuration'),
]),
outputActiveLimits: z
publish: z
.object({
mqtt: z
.object({
Expand All @@ -258,7 +258,7 @@ A longer time will smooth out load changes but may result in overshoot.`,
})
.optional(),
})
.describe('Optionally output active control limits')
.describe('Publish active control limits')
.optional(),
});

Expand Down

0 comments on commit 4231de6

Please sign in to comment.