Skip to content

Commit

Permalink
Fix Amber integration with real test data
Browse files Browse the repository at this point in the history
  • Loading branch information
longzheng committed Sep 4, 2024
1 parent 1a2be7c commit e3d462a
Show file tree
Hide file tree
Showing 4 changed files with 3,724 additions and 77 deletions.
65 changes: 6 additions & 59 deletions src/limiters/negativeFeedIn/amber/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,12 @@ import {
import { AmberLimiter } from '.';
import { setupServer } from 'msw/node';
import { HttpResponse, http } from 'msw';
import sitePricesJson from '../../../../tests/amber/mocks/sitePrices.json';

describe('AmberLimiter', () => {
// sample data from https://community.openhab.org/t/supporting-spot-energy-pricing/157274
const sitePricesResponse = [
{
type: 'ActualInterval',
duration: 5,
spotPerKwh: 6.12,
perKwh: 24.33,
date: '2021-05-05',
nemTime: '2021-05-06T12:30:00+10:00',
startTime: '2021-05-05T02:00:01Z',
endTime: '2021-05-05T02:30:00Z',
renewables: 45,
channelType: 'general',
tariffInformation: 'string',
spikeStatus: 'none',
descriptor: 'negative',
},
{
type: 'CurrentInterval',
duration: 5,
spotPerKwh: 6.12,
perKwh: 24.33,
date: '2021-05-05',
nemTime: '2021-05-06T12:30:00+10:00',
startTime: '2021-05-05T02:00:01Z',
endTime: '2021-05-05T02:30:00Z',
renewables: 45,
channelType: 'general',
tariffInformation: 'string',
spikeStatus: 'none',
descriptor: 'negative',
range: 'string',
estimate: true,
advancedPrice: 'string',
},
{
type: 'ForecastInterval',
duration: 5,
spotPerKwh: -6.12,
perKwh: -24.33,
date: '2021-05-05',
nemTime: '2021-05-06T13:00:00+10:00',
startTime: '2021-05-05T02:30:01Z',
endTime: '2021-05-05T03:00:00Z',
renewables: 45,
channelType: 'general',
tariffInformation: 'string',
spikeStatus: 'none',
descriptor: 'negative',
range: 'string',
advancedPrice: 'string',
},
];

const mockRestHandlers = [
http.get('https://api.amber.com.au/v1/sites/*/prices/current', () => {
return HttpResponse.json(sitePricesResponse);
return HttpResponse.json(sitePricesJson as unknown as JSON);
}),
];

Expand Down Expand Up @@ -101,8 +48,8 @@ describe('AmberLimiter', () => {
mockServer.resetHandlers();
});

it('should return correct control limit when negative price', async () => {
vi.setSystemTime(new Date('2021-05-05T02:30:01Z'));
it('should return correct control limit when feed-in costs money', async () => {
vi.setSystemTime(new Date('2024-09-04T01:00:01Z'));

// give the polling a chance to finish
await vi.advanceTimersToNextTimerAsync();
Expand All @@ -117,8 +64,8 @@ describe('AmberLimiter', () => {
});
});

it('should return no control limit when positive price', async () => {
vi.setSystemTime(new Date('2021-05-05T02:00:01Z'));
it('should return no control limit when feed-in earns money', async () => {
vi.setSystemTime(new Date('2024-09-04T10:00:01Z'));

// give the polling a chance to finish
await vi.advanceTimersToNextTimerAsync();
Expand Down
39 changes: 21 additions & 18 deletions src/limiters/negativeFeedIn/amber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ export class AmberLimiter implements LimiterType {
getInverterControlLimit(): InverterControlLimit {
const price = this.getCurrentPrice();

const limit =
price && price < 0
? {
// if feed in price is negative, limit export to 0
opModConnect: undefined,
opModEnergize: undefined,
opModExpLimW: 0,
opModGenLimW: undefined,
}
: {
// can't find current interval, assume export is fine
// if feed in price is positive, export is fine
opModConnect: undefined,
opModEnergize: undefined,
opModExpLimW: undefined,
opModGenLimW: undefined,
};
// negative price means feed-in earns money
// positive price means feed-in costs money
const feedInCostsMoney = price && price > 0;

const limit = feedInCostsMoney
? {
// if feed in price is negative, limit export to 0
opModConnect: undefined,
opModEnergize: undefined,
opModExpLimW: 0,
opModGenLimW: undefined,
}
: {
// can't find current interval, assume export is fine
// if feed in price is positive, export is fine
opModConnect: undefined,
opModEnergize: undefined,
opModExpLimW: undefined,
opModGenLimW: undefined,
};

writeControlLimit({ limit, name: 'amber' });

Expand Down Expand Up @@ -81,7 +84,7 @@ export class AmberLimiter implements LimiterType {
}

const feedInIntervals = data
// .filter((interval) => interval.channelType === 'feedIn')
.filter((interval) => interval.channelType === 'feedIn')
.map(
(interval) =>
({
Expand Down
Loading

0 comments on commit e3d462a

Please sign in to comment.