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

How to include Fakegato to a platform (FakeGatoHistoryService is not defined) #91

Open
ceraz68 opened this issue Jul 17, 2020 · 1 comment

Comments

@ceraz68
Copy link

ceraz68 commented Jul 17, 2020

I have a working platform with 8 temperature sensors and struggling to integrate fakegato-history. I added fakegato-history 0.5.6 as a dependency for my plugin and its visible in the node_modules folder. I followed the instructions by adding to module export, in the module for each accessory creation, and returned the service (fakegato related entire are in Bold font).

By I can't resolve an error and pretty new to coding. I'm probably creating the FakeGatoHistoryService in the wrong place or out of scope. Thanks a lot for any hints!

  • error

ReferenceError: FakeGatoHistoryService is not defined
at HeaterReportingAccessory.getServices (/homebridge/node_modules/homebridge-heater-reporting/index.js:211:32)
at Server.createHAPAccessory (/usr/local/lib/node_modules/homebridge/src/server.ts:442:41)
at /usr/local/lib/node_modules/homebridge/src/server.ts:427:34
at Array.forEach ()
at /usr/local/lib/node_modules/homebridge/src/server.ts:417:21
at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/once.ts:10:18
at HeaterReportingPlatform.accessories (/homebridge/node_modules/homebridge-heater-reporting/index.js:185:9)
at /usr/local/lib/node_modules/homebridge/src/server.ts:415:24
at new Promise ()
at Server.loadPlatformAccessories (/usr/local/lib/node_modules/homebridge/src/server.ts:414:12)

  • Here are the relevant extracts of the key code:

module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
var FakeGatoHistoryService = require('fakegato-history')(homebridge);
homebridge.registerAccessory("homebridge-heater-reporting", "heater-reporting", HeaterReportingAccessory);
homebridge.registerPlatform("homebridge-heater-reporting", "heater-reporting", HeaterReportingPlatform);
}
function HeaterReportingPlatform(log, config){
this.sensors = config['sensors']; //sensors is an array in config.json, each sensor identified my name, keyword, serial
//(...)my code
}
HeaterReportingPlatform.prototype = {
accessories: function(callback) {
var sensorAccessories = []; //this is an array to store the sensor temperature accessories
for(var i = 0; i < this.sensors.length; i++){
var sensor = new HeaterReportingAccessory(this.log, this.sensors[i]);
sensorAccessories.push(sensor);
}
var saCount = sensorAccessories.length;
callback(sensorAccessories);
}
function HeaterReportingAccessory(log, sensorConfig) {
this.log = log;
this.keyword = sensorConfig["keyword"];
this.name = sensorConfig["name"];
this.sn = sensorConfig["serial"];
}
HeaterReportingAccessory.prototype = {
getServices: function() {
var informationService = new Service.AccessoryInformation();

    informationService
      .setCharacteristic(Characteristic.Name, this.name)
      .setCharacteristic(Characteristic.Manufacturer, "Dallas")
      .setCharacteristic(Characteristic.Model, this.keyword)
      .setCharacteristic(Characteristic.SerialNumber, this.sn);

    var temperatureService = new Service.TemperatureSensor(this.name);
    temperatureService.getCharacteristic(Characteristic.CurrentTemperature)
                            .on("get", this.getTemperature.bind(this));

//line 211
var loggingService = new FakeGatoHistoryService("weather", {displayName: this.name, log: this.log}, {storage: 'fs'});

    **return [informationService, temperatureService, loggingService];**
},
@ceraz68
Copy link
Author

ceraz68 commented Jul 18, 2020

Solved by creating the variable outside of modules exports:

var fakegatoHistory = require( 'fakegato-history' );
module.exports = function(homebridge) {
HistoryService = fakegatoHistory( homebridge );
...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant