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: incorrect defaulted values #27

Merged
merged 1 commit into from Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/p1.js
Expand Up @@ -7,11 +7,11 @@ logger.add(new logger.transports.Console({
}))

/**
* 1: Goto: http://developer.athom.com
* 1: Go to: https://tools.developer.homey.app/
* 2: Login into Homey
* 3: Open the inspector (chrome f12)
* 3: Open the inspector (Chrome f12)
* 4: Click the `network` tab
* 5: Refresh the page (you see couple of webpages being called)
* 5: Open the "Tools" > "System" page
* 6: Copy the `homeyId` from the url: https://[localId].homey.homeylocal.com/api/manager/system/ping?id=[homeyId]
*/
const homeyId = '5c....................23'
Expand Down Expand Up @@ -93,29 +93,29 @@ function publishToHomey (output) {
'power': {
'positive': {
'L1': {
'reading': output.power.instantaneousConsumedElectricityL1 || output.power.actualConsumed || 0,
'reading': getDefaultedValue(output.power.instantaneousConsumedElectricityL1, output.power.actualConsumed),
'unit': 'kW',
},
'L2': {
'reading': output.power.instantaneousConsumedElectricityL2 || 0,
'reading': getDefaultedValue(output.power.instantaneousConsumedElectricityL2),
'unit': 'kW',
},
'L3': {
'reading': output.power.instantaneousConsumedElectricityL3 || 0,
'reading': getDefaultedValue(output.power.instantaneousConsumedElectricityL3),
'unit': 'kW',
},
},
'negative': {
'L1': {
'reading': output.power.instantaneousProducedElectricityL1 || output.power.actualProduced || 0,
'reading': getDefaultedValue(output.power.instantaneousProducedElectricityL1, output.power.actualProduced),
'unit': 'kW',
},
'L2': {
'reading': output.power.instantaneousProducedElectricityL2 || 0,
'reading': getDefaultedValue(output.power.instantaneousProducedElectricityL2),
'unit': 'kW',
},
'L3': {
'reading': output.power.instantaneousProducedElectricityL3 || 0,
'reading': getDefaultedValue(output.power.instantaneousProducedElectricityL3),
'unit': 'kW',
},
},
Expand Down Expand Up @@ -154,6 +154,15 @@ function publishToHomey (output) {
}
}

function getDefaultedValue(...args) {
for (let arg of args) {
if (arg !== undefined) {
return arg;
}
}
return 0;
}

const p1Meter = new dsmr({
port: usbPort,
baudrate: bps,
Expand Down