Closed dacarson closed 3 months ago
I have made this work with two changes:
Add the logging to index.js:277
lux: accessory.LightLevelService ? accessory.LightLevelService.getCharacteristic(Characteristic.CurrentAmbientLightLevel).value : accessory.CurrentConditionsService.getCharacteristic(Characteristic.CurrentAmbientLightLevel).value
Switch from 'weather' to 'custom', in currentConditions.js:151
but also do this:
this.services = [this.CurrentConditionsService];
this.historyService = new FakeGatoHistoryService("custom", this, this.config.fakegatoParameters);
this.services = this.getServices();
The 2nd part doesn't seem right. When examining the code in FakeGato, it looks at all the Services
that are part of the Accessory
. And then for each Characteristic
of each Services
it checks to see if it can create a history entry for it. If so, it does.
The challenge is the historyService
is part of the Accessory
and if I don't override the value of this.service
it crashes. It crashes because when it walks the list of Services, it reaches the historyService which is undefined
at that moment.
I'm wondering if there is different way Services
should be registered with the Accessory
.
This is what it currently looks like:
Worked out an elegant fix. Following the pattern in index.js
that has an array of Accessories:
this.accessoriesList = [];
In currentConditions.js
, create an array of services, aka this.services = [];
Then add each Service as they are created, aka:
this.services.push(this.CurrentConditionsService);
later
this.services.concat(compatibility.getServices(this));
and later:
this.services.push(this.informationService);
and lastly do this:
this.historyService = new FakeGatoHistoryService("custom", this, this.config.fakegatoParameters);
this.services.push(this.historyService);
Change getServices()
function to just return the services object:
getServices: function ()
{
return this.services;
}
This way, only fully defined Service
objects exist in the services array. FakeGatoHistoryService
is now happy.
Very interesting!
With this PR now merged to fakegato Added lux to accessoryType 'custom' , this plugin should be able to support Light Level history in the Eve app.