|
1 | 1 | import { describe, expect, it } from 'vitest'; |
| 2 | +import { type ActiveInverterControlLimit } from './inverterController.js'; |
2 | 3 | import { |
| 4 | + adjustActiveInverterControlForBatteryCharging, |
3 | 5 | calculateTargetSolarPowerRatio, |
4 | 6 | calculateTargetSolarWatts, |
5 | 7 | getActiveInverterControlLimit, |
@@ -236,3 +238,88 @@ describe('getActiveInverterControlLimit', () => { |
236 | 238 | } satisfies typeof inverterControlLimit); |
237 | 239 | }); |
238 | 240 | }); |
| 241 | + |
| 242 | +describe('adjustActiveInverterControlForBatteryCharging', () => { |
| 243 | + it('should return the original limit if opModExpLimW is undefined', () => { |
| 244 | + const activeInverterControlLimit: ActiveInverterControlLimit = { |
| 245 | + opModEnergize: undefined, |
| 246 | + opModConnect: undefined, |
| 247 | + opModGenLimW: undefined, |
| 248 | + opModExpLimW: undefined, |
| 249 | + opModImpLimW: undefined, |
| 250 | + opModLoadLimW: undefined, |
| 251 | + }; |
| 252 | + const result = adjustActiveInverterControlForBatteryCharging({ |
| 253 | + activeInverterControlLimit, |
| 254 | + batteryChargeBufferWatts: 100, |
| 255 | + }); |
| 256 | + expect(result.opModExpLimW?.value).toEqual(undefined); |
| 257 | + }); |
| 258 | + |
| 259 | + it('should return the original limit if opModExpLimW is greater than the buffer', () => { |
| 260 | + const activeInverterControlLimit: ActiveInverterControlLimit = { |
| 261 | + opModEnergize: undefined, |
| 262 | + opModConnect: undefined, |
| 263 | + opModGenLimW: undefined, |
| 264 | + opModExpLimW: { source: 'fixed', value: 200 }, |
| 265 | + opModImpLimW: undefined, |
| 266 | + opModLoadLimW: undefined, |
| 267 | + }; |
| 268 | + const result = adjustActiveInverterControlForBatteryCharging({ |
| 269 | + activeInverterControlLimit, |
| 270 | + batteryChargeBufferWatts: 100, |
| 271 | + }); |
| 272 | + expect(result.opModExpLimW?.value).toEqual(200); |
| 273 | + }); |
| 274 | + |
| 275 | + it('should return the original limit if opModExpLimW is equal to the buffer', () => { |
| 276 | + const activeInverterControlLimit: ActiveInverterControlLimit = { |
| 277 | + opModEnergize: undefined, |
| 278 | + opModConnect: undefined, |
| 279 | + opModGenLimW: undefined, |
| 280 | + opModExpLimW: { source: 'fixed', value: 100 }, |
| 281 | + opModImpLimW: undefined, |
| 282 | + opModLoadLimW: undefined, |
| 283 | + }; |
| 284 | + const result = adjustActiveInverterControlForBatteryCharging({ |
| 285 | + activeInverterControlLimit, |
| 286 | + batteryChargeBufferWatts: 100, |
| 287 | + }); |
| 288 | + expect(result.opModExpLimW?.value).toEqual(100); |
| 289 | + }); |
| 290 | + |
| 291 | + it('should adjust the limit if opModExpLimW is less than the buffer', () => { |
| 292 | + const activeInverterControlLimit: ActiveInverterControlLimit = { |
| 293 | + opModEnergize: undefined, |
| 294 | + opModConnect: undefined, |
| 295 | + opModGenLimW: undefined, |
| 296 | + opModExpLimW: { source: 'batteryChargeBuffer', value: 0 }, |
| 297 | + opModImpLimW: undefined, |
| 298 | + opModLoadLimW: undefined, |
| 299 | + }; |
| 300 | + const result = adjustActiveInverterControlForBatteryCharging({ |
| 301 | + activeInverterControlLimit, |
| 302 | + batteryChargeBufferWatts: 100, |
| 303 | + }); |
| 304 | + expect(result.opModExpLimW?.value).toBe(100); |
| 305 | + }); |
| 306 | + |
| 307 | + it('should not affect the other limits', () => { |
| 308 | + const activeInverterControlLimit: ActiveInverterControlLimit = { |
| 309 | + opModEnergize: { source: 'fixed', value: true }, |
| 310 | + opModConnect: { source: 'fixed', value: true }, |
| 311 | + opModGenLimW: { source: 'fixed', value: 1000 }, |
| 312 | + opModExpLimW: { source: 'fixed', value: 0 }, |
| 313 | + opModImpLimW: { source: 'fixed', value: 1000 }, |
| 314 | + opModLoadLimW: { source: 'fixed', value: 1000 }, |
| 315 | + }; |
| 316 | + const result = adjustActiveInverterControlForBatteryCharging({ |
| 317 | + activeInverterControlLimit, |
| 318 | + batteryChargeBufferWatts: 100, |
| 319 | + }); |
| 320 | + expect(result).toEqual({ |
| 321 | + ...activeInverterControlLimit, |
| 322 | + opModExpLimW: { source: 'batteryChargeBuffer', value: 100 }, |
| 323 | + }); |
| 324 | + }); |
| 325 | +}); |
0 commit comments