Skip to content

Commit

Permalink
Add support for water consumption
Browse files Browse the repository at this point in the history
See #69.
  • Loading branch information
ebaauw committed Feb 10, 2023
1 parent ff35d99 commit 41a6577
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/P1Accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class P1Accessory extends homebridgeLib.AccessoryDelegate {
}

static get Electricity () { return Electricity }

static get Gas () { return Gas }
static get Water () { return Water }
}

class Electricity extends P1Accessory {
Expand Down Expand Up @@ -75,4 +75,19 @@ class Gas extends P1Accessory {
}
}

class Water extends P1Accessory {
constructor (platform, data) {
super(platform, 'Water', data)
this.service = new P1Service.Water(this, data)
this.historyService = new homebridgeLib.ServiceDelegate.History(
this, {
consumptionDelegate: this.service.characteristicDelegate('consumption')
}
)
if (!this.platform.config.outlet) {
this.dummyService = new homebridgeLib.ServiceDelegate.Dummy(this)
}
}
}

module.exports = P1Accessory
6 changes: 6 additions & 0 deletions lib/P1Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class P1Platform extends homebridgeLib.Platform {
if (data.gas != null) {
this.gas = new P1Accessory.Gas(this, data.gas)
}
if (data.water != null) {
this.water = new P1Accessory.Water(this, data.water)
}
this.debug('initialised')
this.emit('initialised')
} else {
Expand All @@ -203,6 +206,9 @@ class P1Platform extends homebridgeLib.Platform {
if (this.gas != null) {
this.gas.check(data.gas)
}
if (this.water != null) {
this.water.check(data.water)
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions lib/P1Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class P1Service extends homebridgeLib.ServiceDelegate {
static get Electricity () { return Electricity }
static get Phase () { return Phase }
static get Gas () { return Gas }
static get Water () { return Water }
}

class Electricity extends P1Service {
Expand Down Expand Up @@ -165,4 +166,27 @@ class Gas extends P1Service {
}
}

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

check (data) {
this.values.consumption = data.consumption
const date = data.lastupdated == null ? new Date() : new Date(data.lastupdated)
this.values.lastUpdated = String(date).slice(0, 24)
}
}

module.exports = P1Service

0 comments on commit 41a6577

Please sign in to comment.