Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot retrieve device status with .get #663

Open
seb3x97 opened this issue Aug 25, 2024 · 6 comments
Open

Cannot retrieve device status with .get #663

seb3x97 opened this issue Aug 25, 2024 · 6 comments

Comments

@seb3x97
Copy link

seb3x97 commented Aug 25, 2024

I can start and stop my smartplug but when i try to get the status with the "get" function, the code never ends and doesn't return anything.

This is my code :

const TuyAPI = require('tuyapi');
const dotenv = require('dotenv');
dotenv.config();

const device = new TuyAPI({
    id: process.env.DEVICE_ID,
    key: process.env.DEVICE_KEY,
});

device.find().then(() => {
    device.connect();
});

device.on('connected', () => {
    console.log('Connected to device!');

    device.get().then(status => console.log(status))
});

setTimeout(() => { device.disconnect(); }, 20000);
@nospam2k
Copy link
Contributor

nospam2k commented Aug 27, 2024

#634 (comment)?

@seb3x97
Copy link
Author

seb3x97 commented Aug 28, 2024

This allows me to make the .get work but if between two I do a .set the .get no longer works

@nospam2k
Copy link
Contributor

Possibly this if it's a 3.5 device #623 (comment)

@seb3x97
Copy link
Author

seb3x97 commented Sep 6, 2024

I solved my problem. I haven't had much time recently so I just spent an hour to figure out what I needed to use the Tuya API (GET and SET power), I don't know if it breaks anything else in the code and if it is compatible with other versions than my device (3.4). I'll give you the patches but use them with caution because I didn't bother to understand all the code but only a small part to solve my problem.

(The lines to be added are the last lines of the two codes below, it might be a good idea to nest them in a condition for version 3.4)

line '778'

if (
      (
        packet.commandByte === CommandType.CONTROL ||
        packet.commandByte === CommandType.CONTROL_NEW
      ) && packet.payload === false) {
      delete this._resolvers[packet.sequenceN];

line '861'

   // Status response to SET command
   if (
      packet.commandByte === CommandType.STATUS &&
      typeof this._setResolver === 'function'
    ) {
      this._currentSequenceN++;

@Apollon77
Copy link
Collaborator

Sorry but I do not understand how these changes help ... without a debug log this is very strange. Because just to increase sequence counter is strange ... and just deleting a resolver will not resolve anything ...
Can you provide a DEBUG=* log please with the original "master" code?

@nospam2k
Copy link
Contributor

@seb3x97 Try again with latest master and see if you still have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants