Skip to content

Commit

Permalink
Update P1Service.js
Browse files Browse the repository at this point in the history
- Add accessory for Capacity tariff, see #69.
  • Loading branch information
ebaauw committed Feb 12, 2023
1 parent f923ec1 commit 4e68b60
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/P1Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class P1Service extends homebridgeLib.ServiceDelegate {
}

static get Electricity () { return Electricity }
static get ElectricityCapacity () { return ElectricityCapacity }
static get Phase () { return Phase }
static get Gas () { return Gas }
static get Water () { return Water }
Expand Down Expand Up @@ -110,6 +111,34 @@ class Electricity extends P1Service {
}
}

class ElectricityCapacity extends P1Service {
constructor (p1Accessory, data) {
super(p1Accessory, data)
this.addCharacteristicDelegate({
key: 'consumption',
Characteristic: this.Characteristics.eve.TotalConsumption
})
this.addCharacteristicDelegate({
key: 'power',
Characteristic: this.Characteristics.eve.CurrentConsumption
})
this.addCharacteristicDelegate({
key: 'lastUpdated',
Characteristic: this.Characteristics.my.LastUpdated,
silent: true
})
this.check(data)
}

check (data) {
this.values.consumption =
Math.round(1000 * (data.consumption.low + data.consumption.normal)) / 1000
this.values.power = data.avg_power
const date = data.lastupdated == null ? new Date() : new Date(data.lastupdated)
this.values.lastUpdated = String(date).slice(0, 24)
}
}

class Phase extends P1Service {
constructor (p1Accessory, data, subtype) {
super(p1Accessory, data, subtype)
Expand Down

0 comments on commit 4e68b60

Please sign in to comment.