-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Romain DUBOC
committed
Apr 5, 2017
1 parent
e4197ae
commit 5bc0647
Showing
7 changed files
with
194 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
var Service, Characteristic, Command, ExecutionState, State, AbstractAccessory; | ||
|
||
var PowerConsumption, EnergyConsumption; | ||
|
||
var inherits = function (ctor, superCtor) { | ||
|
||
if (ctor === undefined || ctor === null) | ||
throw new TypeError('The constructor to "inherits" must not be ' + | ||
'null or undefined'); | ||
|
||
if (superCtor === undefined || superCtor === null) | ||
throw new TypeError('The super constructor to "inherits" must not ' + | ||
'be null or undefined'); | ||
|
||
if (superCtor.prototype === undefined) | ||
throw new TypeError('The super constructor to "inherits" must ' + | ||
'have a prototype'); | ||
|
||
ctor.super_ = superCtor; | ||
Object.setPrototypeOf(ctor.prototype, superCtor.prototype); | ||
} | ||
|
||
module.exports = function(homebridge, abstractAccessory, api) { | ||
AbstractAccessory = abstractAccessory; | ||
Service = homebridge.hap.Service; | ||
Characteristic = homebridge.hap.Characteristic; | ||
Command = api.Command; | ||
ExecutionState = api.ExecutionState; | ||
State = api.State; | ||
|
||
makeCharacteristics(); | ||
|
||
return ElectricitySensor; | ||
} | ||
|
||
/** | ||
* Accessory "ElectricitySensor" | ||
*/ | ||
|
||
ElectricitySensor = function(log, api, device) { | ||
AbstractAccessory.call(this, log, api, device); | ||
var service = new Service.Outlet(device.label); | ||
service.addCharacteristic(EnergyConsumption); | ||
service.addCharacteristic(PowerConsumption); | ||
|
||
this.energyState = service.getCharacteristic(EnergyConsumption); | ||
this.powerState = service.getCharacteristic(PowerConsumption); | ||
|
||
this.services.push(service); | ||
}; | ||
|
||
ElectricitySensor.UUID = 'ElectricitySensor'; | ||
|
||
ElectricitySensor.prototype = { | ||
|
||
onStateUpdate: function(name, value) { | ||
if (name == 'core:ElectricEnergyConsumptionState') { | ||
this.energyState.updateValue(value); | ||
} else if (name == 'core:ElectricPowerConsumptionState') { | ||
this.powerState.updateValue(value); | ||
} | ||
} | ||
} | ||
|
||
function makeCharacteristics() { | ||
PowerConsumption = function() { | ||
Characteristic.call(this, 'Current Consumption', 'E863F10D-079E-48FF-8F27-9C2605A29F52'); | ||
this.setProps({ | ||
format: Characteristic.Formats.INT, | ||
maxValue: 65535, | ||
minValue: 0, | ||
minStep: 1, | ||
unit: "W", | ||
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] | ||
}); | ||
this.value = this.getDefaultValue(); | ||
}; | ||
inherits(PowerConsumption, Characteristic); | ||
|
||
EnergyConsumption = function() { | ||
Characteristic.call(this, 'Total Consumption', 'E863F10C-079E-48FF-8F27-9C2605A29F52'); | ||
this.setProps({ | ||
format: Characteristic.Formats.FLOAT, | ||
maxValue: 4294967295, | ||
minValue: 0, | ||
minStep: 0.01, | ||
unit: "kWh", | ||
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] | ||
}); | ||
this.value = this.getDefaultValue(); | ||
}; | ||
inherits(EnergyConsumption, Characteristic); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters