simont77 / fakegato-history

Module to emulate Elgato Eve history
MIT License
168 stars 16 forks source link

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

Open ceraz68 opened 4 years ago

ceraz68 commented 4 years ago

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!

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)

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 commented 4 years ago

Solved by creating the variable outside of modules exports:

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