bropat / eufy-security-client

This shared library allows to control Eufy security devices by connecting to the Eufy cloud servers and local/remote stations over p2p.
MIT License
484 stars 69 forks source link

[Bug]: eufy.getStations() works once, then does not again, for a period of time #121

Closed andreasnuesslein closed 2 years ago

andreasnuesslein commented 2 years ago

Client version

1.6.6

Node version

16.14.0

Operating System type

Linux

Operating system version

Ubuntu 21.10

Describe the bug

I try to use the API but only on the first run, I get a station list; on a consecutive run, it stays empty :(

To reproduce

import { EufySecurity, EufySecurityConfig} from "eufy-security-client";

const config = {
  username: "xxx",
  password: "xxx",
  p2pConnectionSetup: 1,
  pollingIntervalMinutes: 10,
  eventDurationSeconds: 10,
} as EufySecurityConfig;

async function dings(): Promise<void> {
  const eufy = new EufySecurity(config);
  if (await eufy.connect()) {
    await eufy.refreshCloudData();
    console.log(eufy);
    console.log(eufy.getStations());
    process.exit()
  }
}
dings();

Screenshots & Logfiles

The result is a bunch of eufy-data and then obviously an empty array.

Additional context

What I did notice, I saw some connected: false and some connected: true here and there.

I thought the eufy.connect() would make sure that I was connected though? :thinking:

Maybe I'm just doing the connection wrong in the first place?

bropat commented 2 years ago

You should not wait on the connect(), but register and use the respective emitter events.

andreasnuesslein commented 2 years ago

Hello @bropat thank you for your response - could you give me one example, pretty please?

in the eufysecurity.d.ts I didn't see any emitter events that I could register to and I did find EufySecurityEvents but I don't understand on which signal I should expect my stations to show up. is getStations() not returning an Array<Station> so I can grab my stations that way?

Thanks :beer:

andreasnuesslein commented 2 years ago

If you were just talking about the event emitter for connect: I did replace the connect() with the respective listener but my stations-list stays empty

  eufy.addListener("connect", async() => {
    console.log("connected");
    // console.log(await eufy.refreshCloudData());   // turned on and off - no difference
    console.log(eufy.getStations());
  });
  eufy.connect()
andreasnuesslein commented 2 years ago

Huhm... I kept poking at the code and now I can't reproduce the problem anymore and I do get the stations.

What I did change is, that I changed my country. But

a) Initially I never had it set, even when it worked before and b) I did try to change it before opening this issue here, and then nothing worked - it threw errors.

Either way: it seems like this issue is resolved for now. But I'm curious to see if anybody else turns up having the same situation.

Again: thanks for this project