Skip to content

Commit

Permalink
Fix Current limit not showing anything if using Grid instead of Shore…
Browse files Browse the repository at this point in the history
… as input source
  • Loading branch information
corinadev committed Nov 1, 2018
1 parent 9a5817f commit 874860c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 52 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

if (getParameterByName('debug')) window.onerror = function (e) { alert(e) }
</script>
<script type="text/javascript" src="bundle.484549cdf64a3475e9c0.js"></script></body>
<script type="text/javascript" src="bundle.6b31cb953bb4c28d253f.js"></script></body>

<script>
function debugLogFn(msg) {
Expand Down
16 changes: 10 additions & 6 deletions src/service/venusSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class VenusSystem {
systemInstanceId = null
acInput1 = null
acInput2 = null
shorePowerInput = null

/**
* "Shore" and "Grid" are just different names for the same thing
* "Shore" is for boats and "Grid" is for land based systems
*/
shoreOrGridPowerInput = null
generatorInput = null
gridInput = null
equipment

constructor() {
Expand Down Expand Up @@ -55,7 +59,7 @@ class VenusSystem {
if (SERVICES.SYSTEM.includes(dbusPath)) {
return `${type}/${this.portalId}/system/${this.systemInstanceId}${dbusPath}`
} else if (SERVICES.SHORE_POWER.includes(dbusPath)) {
return `${type}/${this.portalId}/vebus/${this.vebusInstanceId}/Ac/In/${this.shorePowerInput}${dbusPath}`
return `${type}/${this.portalId}/vebus/${this.vebusInstanceId}/Ac/In/${this.shoreOrGridPowerInput}${dbusPath}`
} else if (SERVICES.VEBUS.includes(dbusPath)) {
return `${type}/${this.portalId}/vebus/${this.vebusInstanceId}${dbusPath}`
} else if (SERVICES.SETTINGS.includes(dbusPath)) {
Expand Down Expand Up @@ -129,13 +133,13 @@ class VenusSystem {

switch (data.value) {
case AC_SOURCE_TYPE.SHORE:
this.shorePowerInput = input + 1
case AC_SOURCE_TYPE.GRID:
this.shoreOrGridPowerInput = input + 1
break
case AC_SOURCE_TYPE.GENERATOR:
this.generatorInput = input + 1
break
case AC_SOURCE_TYPE.GRID:
this.gridInput = input + 1
default:
break
}
}
Expand Down
128 changes: 84 additions & 44 deletions test/venusSystem.test.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,98 @@
import VenusSystem from "../src/service/venusSystem"
import { DBUS_PATHS } from "../src/config/dbusPaths"
import { AC_SOURCE_TYPE } from "../src/service/topics"

describe("initialization", () => {
test("starts with no portal id", () => {
const system = new VenusSystem()
expect(system.portalId).toBe(null)
})
describe("venus system", () => {
describe("initialization", () => {
test("starts with no portal id", () => {
const system = new VenusSystem()
expect(system.portalId).toBe(null)
})

test("starts as not initialized", () => {
const system = new VenusSystem()
expect(system.isInitialized()).toBeFalsy()
})
test("starts as not initialized", () => {
const system = new VenusSystem()
expect(system.isInitialized()).toBeFalsy()
})

test("initializes portal id after first `/Serial` notification received", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
expect(system.portalId).toBe("985dadd0c9e4")
expect(system.isInitialized()).toBeFalsy()
})
test("initializes portal id after first `/Serial` notification received", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
expect(system.portalId).toBe("985dadd0c9e4")
expect(system.isInitialized()).toBeFalsy()
})

test("initializes vebus device id after `/DeviceInstance` notification received", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
expect(system.vebusInstanceId).toBe(257)
expect(system.isInitialized()).toBeFalsy()
})
test("initializes vebus device id after `/DeviceInstance` notification received", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
expect(system.vebusInstanceId).toBe(257)
expect(system.isInitialized()).toBeFalsy()
})

test("is initialized after portal id and vebus device id are set", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
expect(system.isInitialized()).toBeFalsy()
test("is initialized after portal id and vebus device id are set", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
expect(system.isInitialized()).toBeFalsy()
})
})
})

describe("return topic based on dbus path", () => {
let system
describe("return topic based on dbus path", () => {
describe("system paths", () => {
test("correctly initializes system paths", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/system/0/DeviceInstance", { value: 0 })

beforeEach(() => {
system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
system.handleSystemMessage("N/985dadd0c9e4/system/0/DeviceInstance", { value: 0 })
})
expect(system.getTopicFromDbusPath("N", DBUS_PATHS.BATTERY.VOLTAGE)).toBe(
`N/985dadd0c9e4/system/0/Dc/Battery/Voltage`
)
})
})

test("correctly initializes system paths", () => {
expect(system.getTopicFromDbusPath("N", DBUS_PATHS.BATTERY.VOLTAGE)).toBe(
`N/985dadd0c9e4/system/0/Dc/Battery/Voltage`
)
})
describe("vebus paths", () => {
test("correctly initializes system paths", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })

expect(system.getTopicFromDbusPath("N", DBUS_PATHS.INVERTER_CHARGER.AC_LOADS.OUTPUT_CURRENT_PHASE_1)).toBe(
`N/985dadd0c9e4/vebus/257/Ac/Out/L1/I`
)
})
})

describe("shore power paths", () => {
test("when two inputs configured, shore and generator", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
system.handleSystemMessage("N/985dadd0c9e4/settings/0/Settings/SystemSetup/AcInput1", {
value: AC_SOURCE_TYPE.GENERATOR
})
system.handleSystemMessage("N/985dadd0c9e4/settings/0/Settings/SystemSetup/AcInput2", {
value: AC_SOURCE_TYPE.SHORE
})

expect(system.getTopicFromDbusPath("N", DBUS_PATHS.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT)).toBe(
`N/985dadd0c9e4/vebus/257/Ac/In/2/CurrentLimit`
)
})

test("when two inputs configured, shore and grid", () => {
const system = new VenusSystem()
system.handleSystemMessage("N/985dadd0c9e4/system/0/Serial", { value: "985dadd0c9e4" })
system.handleSystemMessage("N/985dadd0c9e4/vebus/257/DeviceInstance", { value: 257 })
system.handleSystemMessage("N/985dadd0c9e4/settings/0/Settings/SystemSetup/AcInput1", {
value: AC_SOURCE_TYPE.GENERATOR
})
system.handleSystemMessage("N/985dadd0c9e4/settings/0/Settings/SystemSetup/AcInput2", {
value: AC_SOURCE_TYPE.GRID
})

test("correctly initializes vebus paths", () => {
expect(system.getTopicFromDbusPath("N", DBUS_PATHS.INVERTER_CHARGER.AC_LOADS.CURRENT)).toBe(
`N/985dadd0c9e4/vebus/257/Ac/Out/L1/I`
)
expect(system.getTopicFromDbusPath("N", DBUS_PATHS.INVERTER_CHARGER.SHORE_POWER.CURRENT_LIMIT)).toBe(
`N/985dadd0c9e4/vebus/257/Ac/In/2/CurrentLimit`
)
})
})
})
})

0 comments on commit 874860c

Please sign in to comment.