simont77 / fakegato-history

Module to emulate Elgato Eve history
MIT License
166 stars 17 forks source link

History not showing for Energy type #55

Closed lint2015 closed 6 years ago

lint2015 commented 6 years ago

I'm trying to implement energy consumption history into this plugin. It appears to be creating the fakeGatoHistoryService, adding entries, and writing entries to disk properly, but I still cannot see history in the Eve app.

I also have the homebridge-weather-station-extended plugin installed it's working fine. When the Eve app is refreshed, there will be activity in the log where fakegato-history sends new weather entries to the Eve app, but not so for the energy consumption history I'm trying to implement.

I've noticed nothing in the fakeGatoHistoryService is being assigned an iid, they all remain null and I suspect this is why it's not working, but I can't figure out why this is happening or how to fix it. Any pointers?

I've uploaded a copy of my code here, and this is a sample of the fakegatoHistoryService (iids bolded):

FakeGatoHistory { displayName: 'Computer History', UUID: 'E863F007-079E-48FF-8F27-9C2605A29F52', subtype: undefined, iid: null, characteristics: [ Characteristic { displayName: 'Name', UUID: '00000023-0000-1000-8000-0026BB765291', iid: null, value: 'Computer History', status: null, eventOnlyCharacteristic: false, props: [Object], subscriptions: 0, _events: [Object], _eventsCount: 1 }, S2R1Characteristic { displayName: 'S2R1', UUID: 'E863F116-079E-48FF-8F27-9C2605A29F52', iid: null, value: '9eMFAAAAAAATibQgBAECAgIHAg8DOgLADwAAAAAAAAAAAQE=', status: null, eventOnlyCharacteristic: false, props: [Object], subscriptions: 0, _events: [Object], _eventsCount: 1 }, S2R2Characteristic { displayName: 'S2R2', UUID: 'E863F117-079E-48FF-8F27-9C2605A29F52', iid: null, value: null, status: null, eventOnlyCharacteristic: false, props: [Object], subscriptions: 0, _events: [Object], _eventsCount: 2 }, S2W1Characteristic { displayName: 'S2W1', UUID: 'E863F11C-079E-48FF-8F27-9C2605A29F52', iid: null, value: null, status: null, eventOnlyCharacteristic: false, props: [Object], subscriptions: 0, _events: [Object], _eventsCount: 2 }, S2W2Characteristic { displayName: 'S2W2', UUID: 'E863F121-079E-48FF-8F27-9C2605A29F52', iid: null, value: null, status: null, eventOnlyCharacteristic: false, props: [Object], subscriptions: 0, _events: [Object], _eventsCount: 2 } ], optionalCharacteristics: [], isHiddenService: false, isPrimaryService: false, linkedServices: [], size: 4032, minutes: 5, storage: 'fs', path: '/homebridge', filename: undefined, disableTimer: false, accessoryName: 'Computer', log: { [Function: bound ] debug: [Function], info: [Function], warn: [Function], error: [Function], log: [Function], prefix: 'TP Link' }, loaded: true, accessoryType116: '04 0102 0202 0702 0f03', accessoryType117: '1f', accessoryType: 'energy', firstEntry: 0, lastEntry: 569, history: [ 'noValue', { time: 1527009683, setRefTime: 1 }, { power: 22, time: 1527009683 }, { power: 21.9, time: 1527010510 }, { power: 27.3, time: 1527011567 }, { power: 68, time: 1527012167 }, { power: 0, time: 1527013284 }, { power: 0, time: 1527013884 }, { power: 0, time: 1527014484 }, { power: 0, time: 1527015084 }, { power: 0, time: 1527015684 }, { power: 0, time: 1527016284 }, { power: 0, time: 1527016884 }, { power: 0, time: 1527017484 }, { power: 0, time: 1527018084 }, { power: 0, time: 1527018684 }, { power: 0, time: 1527019284 }, { power: 0, time: 1527019884 }, { power: 0, time: 1527020484 }, { power: 0, time: 1527021084 }, { power: 0, time: 1527021684 }, { power: 0, time: 1527022284 }, { power: 0, time: 1527022884 }, { power: 0, time: 1527023484 }, { power: 0, time: 1527024084 }, { power: 0, time: 1527024684 }, { power: 0, time: 1527025284 }, { power: 0, time: 1527025884 }, { power: 0, time: 1527026484 }, { power: 0, time: 1527027084 }, { power: 0, time: 1527027684 }, { power: 0, time: 1527028284 }, { power: 0, time: 1527028884 }, { power: 0, time: 1527029484 }, { power: 0, time: 1527030084 }, { power: 0, time: 1527030684 }, { power: 0, time: 1527031284 }, { power: 0, time: 1527031884 }, { power: 0, time: 1527032484 }, { power: 0, time: 1527033084 }, { power: 0, time: 1527033684 }, { power: 0, time: 1527034284 }, { power: 0, time: 1527034884 }, { power: 0, time: 1527035484 }, { power: 0, time: 1527036084 }, { power: 0, time: 1527036684 }, { power: 0, time: 1527037284 }, { power: 0, time: 1527037884 }, { power: 0, time: 1527038484 }, { power: 0, time: 1527039084 }, { power: 0, time: 1527039684 }, { power: 0, time: 1527040284 }, { power: 0, time: 1527040884 }, { power: 0, time: 1527041484 }, { power: 0, time: 1527042084 }, { power: 0, time: 1527042684 }, { power: 0, time: 1527043284 }, { power: 0, time: 1527043884 }, { power: 0, time: 1527044484 }, { power: 0, time: 1527045084 }, { power: 0, time: 1527045684 }, { power: 0, time: 1527046284 }, { power: 0, time: 1527046884 }, { power: 0, time: 1527047484 }, { power: 0, time: 1527048084 }, { power: 0, time: 1527048684 }, { power: 0, time: 1527049284 }, { power: 0, time: 1527049884 }, { power: 0, time: 1527050484 }, { power: 0, time: 1527051084 }, { power: 0, time: 1527051684 }, { power: 0, time: 1527052284 }, { power: 0, time: 1527052884 }, { power: 0, time: 1527053484 }, { power: 0, time: 1527054084 }, { power: 0, time: 1527054684 }, { power: 0, time: 1527055284 }, { power: 0, time: 1527055884 }, { power: 0, time: 1527056484 }, { power: 0, time: 1527057084 }, { power: 0, time: 1527057684 }, { power: 0, time: 1527058284 }, { power: 0, time: 1527058884 }, { power: 0, time: 1527059484 }, { power: 0, time: 1527060084 }, { power: 0, time: 1527060684 }, { power: 0, time: 1527061284 }, { power: 0, time: 1527061884 }, { power: 0, time: 1527062484 }, { power: 0, time: 1527063084 }, { power: 0, time: 1527063684 }, { power: 0, time: 1527064284 }, { power: 51.1, time: 1527064884 }, { power: 51.1, time: 1527065484 }, { power: 51.1, time: 1527066084 }, { power: 51.1, time: 1527066684 }, { power: 51.1, time: 1527067284 }, { power: 51.1, time: 1527067884 }, { power: 51.1, time: 1527068484 }, { power: 51.1, time: 1527069084 }, ... 470 more items ], memorySize: 4032, usedMemory: 569, currentEntry: 1, transfer: false, setTime: true, refTime: 548702483, memoryAddress: 0, dataStream: '', saving: false, initialTime: 1527009683 }

Cheers!

simont77 commented 6 years ago

Did you check with Hesperus if all services and characteristics are visible to iOS? Unfortunately you are using a dynamic plugin, and I’m not familiar with that. Maybe @NorthernMan54 can help you.

NorthernMan54 commented 6 years ago

I’m away from my computer for a few days, and can take a look when I’m back home.

On May 27, 2018, at 3:57 AM, simont77 notifications@github.com wrote:

Did you check with Hesperus if all services and characteristics are visible to iOS? Unfortunately you are using a dynamic plugin, and I’m not familiar with that. Maybe @NorthernMan54 can help you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

lint2015 commented 6 years ago

@simont77 I’ve just installed it and indeed the entire history service I created isn’t being seen there, whereas the weather history service is. It does look related to it not being assigned iids.

Thanks guys. When I get some more time I’ll try debugging with HAP-NodeJS, which seems to be responsible for iid assignments, too.

NorthernMan54 commented 6 years ago

Just looking at this quickly, and I’m wondering if “Fakegato” is not seeing this as a platform accessory

In this line

this.historyService = new FakeGatoHistoryService("energy", this, {
  storage:'fs',
  minutes: 5
});

When you pass “this”, it should be the accessory, and this “if" should trigger. If the “if” isn’t triggering you are passing the wrong object. Looking at the plugin structure, I’m thinking it could be “this.homebridgeAccessory"

https://github.com/simont77/fakegato-history/blob/fe7e5bc768aa538b7c5a569dfd1d63bf0ce0485a/fakegato-history.js#L443 https://github.com/simont77/fakegato-history/blob/fe7e5bc768aa538b7c5a569dfd1d63bf0ce0485a/fakegato-history.js#L443

PS Some pro-tips when your extending / working with someones’s plugin

1 - Fork their repository, and clone it directly into your development environment 2 - When you are asking for advice, check in your changes to GitHub, so people can just look at your GitHub and / or fork your changes to look at them ( Saves using dropbox etc ) 3 - When your done your changes, you can easily submit a pull request back to the original plugin author.

On May 27, 2018, at 7:31 PM, lint2015 notifications@github.com wrote:

@simont77 https://github.com/simont77 I’ve just installed it and indeed the entire history service I created isn’t being seen there, whereas the weather history service is. It does look related to it not being assigned iids.

Thanks guys. When I get some more time I’ll try debugging with HAP-NodeJS, which seems to be responsible for iid assignments too.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/simont77/fakegato-history/issues/55#issuecomment-392387882, or mute the thread https://github.com/notifications/unsubscribe-auth/AS5CmF2jF6yXbh_QZPwKdnD4zHgKNk-0ks5t2zdfgaJpZM4UPJi3.

lint2015 commented 6 years ago

@NorthernMan54 Thanks. I suspected I might've been passing the wrong object... I logged the 'this' object to check but the way the object was set up was incredibly unwieldy - over 1700 lines...

Reviewing the object again, it looks like the nests in the json output werent indented properly - which gave the illusion that the fakegatoHistoryService was created under the same object as the accessory's infoService and outletService. Your suggestion looks extremely promising.

Regarding the if statement, I had already logged where it was going and it was branching to the else as you suspect.

Thanks for your help! I'm not familiar with GitHub procedure but it's about time I read up on it and follow recommended procedures...

lint2015 commented 6 years ago

Okay, I've got it working now! After changing the object being passed, the last hurdle was the accessory being programmed to remove any services it didn't recognise, which meant the history service was getting purged not long after being created.

Again, thanks for the help! I've started putting some of the code changes on GitHub as I clean them up.

Also, just a heads up, the library of Eve custom characteristics linked in the Wiki has been moved here: https://github.com/ebaauw/homebridge-lib/blob/master/lib/EveHomeKitTypes.js

NorthernMan54 commented 6 years ago

Great news

On May 28, 2018, at 8:12 PM, lint2015 notifications@github.com wrote:

Okay, I've got it working now! After changing the object being passed, the last hurdle was the accessory was programmed to remove any services it didn't recognise, probably to get rid of cached services created by older versions.

Again, thanks for the help! I've started putting some of the code changes on GitHub as I clean them up.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

simont77 commented 6 years ago

Also, just a heads up, the library of Eve custom characteristics linked in the Wiki has been moved here: https://github.com/ebaauw/homebridge-lib/blob/master/lib/EveHomeKitTypes.js

Thanks, updated!