Code Monkey home page Code Monkey logo

Comments (5)

JanLoebel avatar JanLoebel commented on September 25, 2024

@wormiedk have you any experience in javascript/node.js?

from eufy-node-client.

wormiedk avatar wormiedk commented on September 25, 2024

a little but normally I get by modifying examples. I found this on another forum but cannot get it to work

What I did:
sudo npm install -g typescript
git clone https://github.com/JanLoebel/eufy-node-client.git
cd eufy-node-client/src
nano test.ts

Contents of test.ts:

import { HttpService } from './http/http.service';
import { CommandTypes } from './p2p/command.model';
import { DeviceClientService } from './p2p/device-client.service';
import { LocalLookupService } from './p2p/local-lookup.service';
import { PushMessage } from './push/push.model';
import { PushService } from './push/push.service';

(async () => {
  const httpService = new HttpService(USERNAME, PASSWORD);
  const hubs = await httpService.listHubs();

  if (hubs && hubs.length > 0) {
    const hub = hubs[0];
    const lookupService = new LocalLookupService();
    const address = await lookupService.lookup(HOMEBASE_IP);

    const service = new DeviceClientService(address, hub.p2p_did, hub.member.action_user_id);
    const connected = await service.connect().catch((error) => {
      console.log('error trying to connected:', error);
      return false;
    });

    if (connected) {
      console.log('p2p connected, start listening for push messages');

      const pushService = new PushService();
      const credentials = await pushService.createPushCredentials();

      pushService.listen(credentials, async (msg: PushMessage) => {
        const event = msg.data;
        const payload = event.payload;
        if (payload && payload.event_type === 3103 && payload.channel === 2 && payload.push_count === 1) {
          console.log('doorbell pressed');

          if (!streaming) {
            service.sendCommandWithIntString(CommandTypes.CMD_NAS_TEST, 1, 2);
            streaming = true;

            setTimeout(() => {
              if (streaming) {
                service.sendCommandWithIntString(CommandTypes.CMD_NAS_TEST, 0, 2);
              }
              streaming = false;
            }, 6000);
          }
          await got.get('url_to_a_webhook');
        }
      });

      // Register generated token

      const fcmToken = credentials.fcm.token;

      await httpService.registerPushToken(fcmToken);
      await httpService.pushTokenCheck();
    }
  } else {
    console.warn('no hub found');
  }
})();

However this results in an error when trying to compile using
tsc test.ts

test.ts:2:10 - error TS2724: Module '"./p2p/command.model"' has no exported member 'CommandTypes'. Did you mean 'CommandType'?

2 import { CommandTypes } from './p2p/command.model';
~~~~~~~~~~~~

p2p/command.model.ts:1:13
1 export enum CommandType {
~~~~~~~~~~~
'CommandType' is declared here.

test.ts:35:16 - error TS2304: Cannot find name 'streaming'.

35 if (!streaming) {
~~~~~~~~~

test.ts:37:13 - error TS2304: Cannot find name 'streaming'.

37 streaming = true;
~~~~~~~~~

test.ts:40:19 - error TS2304: Cannot find name 'streaming'.

40 if (streaming) {
~~~~~~~~~

test.ts:43:15 - error TS2304: Cannot find name 'streaming'.

43 streaming = false;
~~~~~~~~~

test.ts:46:17 - error TS2304: Cannot find name 'got'.

46 await got.get('url_to_a_webhook');

from eufy-node-client.

1h8fulkat avatar 1h8fulkat commented on September 25, 2024

Try this:

  • cd eufy-node-client/
  • sudo npm i @types/node
  • tsc -b
  • cd build
  • node index.js

Now tell me what to do next :-D I really want to be able to control the security mode with home assistant!

from eufy-node-client.

JanLoebel avatar JanLoebel commented on September 25, 2024

After @bropat and I will finish the push-rework, I will restructure the index.ts and write some more documentation how to get started. But this is and will stay a library for other developers not users.

from eufy-node-client.

JanLoebel avatar JanLoebel commented on September 25, 2024

I've created a new repository with a 'Getting started' guide. If you have any problems / questions for that, please create an issue there.
https://github.com/JanLoebel/eufy-node-client-examples

from eufy-node-client.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.