Skip to content

Commit

Permalink
Update P1Platform.js
Browse files Browse the repository at this point in the history
- Add accessory for Capacity tariff, see #69.
- Simulate 1000W current consumption when using `telegram` for testing,
- Add missing error reporting for `telegram` setting.
  • Loading branch information
ebaauw committed Feb 12, 2023
1 parent 0ab0eb9 commit 66cb7ca
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/P1Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class P1Platform extends homebridgeLib.Platform {
if (telegrams[this.config.telegram] != null) {
const p1 = new P1Client()
p1
.on('error', (error) => { this.warn(error) })
.on('warning', (message) => { this.warn(message) })
.once('telegram', (s) => { this.debug('telegram:\n%s', s) })
.once('rawData', (obj) => { this.debug('raw data: %j', obj) })
.once('data', (data) => { this.telegram = data })
Expand Down Expand Up @@ -150,7 +152,7 @@ class P1Platform extends homebridgeLib.Platform {
this.beat = beat
if (this.telegram != null && beat % 5 === 0) {
this.telegram.electricity.lastupdated = new Date().toISOString()
++this.telegram.electricity.consumption[this.telegram.electricity.tariff]
this.telegram.electricity.consumption[this.telegram.electricity.tariff] += 5 / 3600
this.onData(this.telegram)
return
}
Expand Down Expand Up @@ -189,6 +191,11 @@ class P1Platform extends homebridgeLib.Platform {
this, data.electricityBack, 'Electricity Delivered'
)
}
if (data.electricity.avg_power != null) {
this.electricityCapacity = new P1Accessory.ElectricityCapacity(
this, data.electricity
)
}
if (data.gas != null) {
this.gas = new P1Accessory.Gas(this, data.gas)
}
Expand All @@ -203,6 +210,9 @@ class P1Platform extends homebridgeLib.Platform {
if (this.electricityBack != null) {
this.electricityBack.check(data.electricityBack)
}
if (this.electricityCapacity != null) {
this.electricityCapacity.check(data.electricity)
}
if (this.gas != null) {
this.gas.check(data.gas)
}
Expand Down

0 comments on commit 66cb7ca

Please sign in to comment.