iRayanKhan / homebridge-tuya

A Homebridge plugin to control Tuya devices locally.
MIT License
401 stars 166 forks source link

Allow new format for local_key #418

Closed justerror closed 10 months ago

justerror commented 1 year ago

Allow latin alphanumeric and special character for local_key Remove local_key check

Fixes #409 Fixes #410

hosigi05 commented 1 year ago

Experience the new format not being allowed in the current version of this plugin too. Would be great this could be fixed in due course. Thanks @iRayanKhan

SoCuul commented 1 year ago

As I just discovered, this regex does not cover all local keys. One of my local keys failed the regex parsing, specifically it included a | character.

I modified the regex string a little, and it looks like this fixes the problem:

^[a-zA-Z0-9~`!@#$%^&*|()+={}\[\];:\'\"<>.,\/\\\?-_]+$
ascl00 commented 1 year ago

At this point it might be just better to remove this check. It seems pretty much any ASCII character can be in the key, so continuing to extend the regex is not really helping.

houmark commented 1 year ago

+1 for merging this. I also encountered a new local key format today with both uppercase chars and special chars as well.

justerror commented 1 year ago

Removed all checks for local_key due to variability.

hosigi05 commented 1 year ago

Getting this error when installing this update in my environment:

[9/15/2023, 9:35:56 AM] ====================
[9/15/2023, 9:35:56 AM] ERROR LOADING PLUGIN homebridge-tuya:
[9/15/2023, 9:35:56 AM] /var/lib/homebridge/node_modules/homebridge-tuya/lib/AirConditionerAccessory.js:432
            this.setMultiState({this.dpActive: true, this.dpRotationSpeed: this.convertRotationSpeedFromHomeKitToTuya(value)}, callback);

SyntaxError: Unexpected token '.'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/var/lib/homebridge/node_modules/homebridge-tuya/index.js:11:33)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
[9/15/2023, 9:35:56 AM] ====================
lostdriveway commented 1 year ago

Hi - new here and excuse my noobness - having this issue with my Arlec ceiling fan - how do you install this fix?

SoCuul commented 1 year ago

Hi - new here and excuse my noobness - having this issue with my Arlec ceiling fan - how do you install this fix?

Hey! Since this isn't merged into the project yet, it'll make it harder to install. What you can try is replacing a few lines in your currently installed version. Keep in mind, all of these files will be located inside the homebridge-tuya folder inside node_modules.

File 1: index.js

Replace this:

if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);

With this:

if (!/^[a-zA-Z0-9~`!@#$%^&*|()+={}\[\];:\'\"<>.,\/\\\?-_]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id)

File 2: cli-decode.js

Replace this:

if (!/^[0-9a-f]+$/i.test(key)) {

With this:

if (!/^[a-zA-Z0-9~`!@#$%^&*|()+={}\[\];:\'\"<>.,\/\\\?-_]+$/i.test(key)) {

This may not work (in the future), but it's the easiest solution for you right now. It definitely solved it for me :)

lostdriveway commented 1 year ago

Awesome thanks for that! - now again excuse my basic skills

"Keep in mind, all of these files will be located inside the homebridge-tuya folder inside node_modules."

where is the node_modules folder usually found?

SoCuul commented 1 year ago

Awesome thanks for that! - now again excuse my basic skills

"Keep in mind, all of these files will be located inside the homebridge-tuya folder inside node_modules."

where is the node_modules folder usually found?

If you're running homebridge on docker, you can find it by entering your container, by running these commands:

docker exec -it homebridge /bin/bash
cd homebridge/node_modules/homebridge-tuya

If you're running it without any complicated setup, just go into the homebridge folder, then you'll see node_modules, enter that and you'll see tuya-homebridge.

Hope that clarifies it a bit, but feel free to let me know if you need any help!

lostdriveway commented 1 year ago

Thanks I'll give it a crack when I get home from work this afternoon!

lostdriveway commented 1 year ago

Ok I can get this far- but no idea what the command is to edit the 2 files...sorry

homebridge

SoCuul commented 1 year ago

Ok I can get this far- but no idea what the command is to edit the 2 files...sorry

homebridge

From there, you can edit it with any text editor of your choice. I suggest using nano, which you can find tutorials for online!

lostdriveway commented 1 year ago

ok - did the first file - can't find the cli-decode.js file though?

SoCuul commented 1 year ago

ok - did the first file - can't find the cli-decode.js file though?

cli-decode.js should be located in the bin folder

michael-j-green commented 1 year ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

iRayanKhan commented 1 year ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

lostdriveway commented 1 year ago

Well I managed to find and make the requested changes to the code - no local key error message after reboot but it still can't find the device.

I'll put it in the too hard basket for now until there's a better fix.

SoCuul commented 1 year ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained? This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

@iRayanKhan is there a chance you could merge this into the master branch and publish it. This plugin is still fully functional and works as intended, but this single local_key change pretty much makes the entire thing unusable.

michael-j-green commented 1 year ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained? This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself.

Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

SoCuul commented 1 year ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself.

Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

I would be happy to help out, but while I'm fluent in typescript, I have little to no experience building a homebridge plug-in. I've gone over the documentation countless times, but I haven't fully got the grasp of it.

lostdriveway commented 1 year ago

Finally got it working thanks to some help in the discord

had to add "//" in front of line 99 on the index.js and also added a line into the config.json and it finally showed up in Homebridge

michael-j-green commented 1 year ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself. Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

I would be happy to help out, but while I'm fluent in typescript, I have little to no experience building a homebridge plug-in. I've gone over the documentation countless times, but I haven't fully got the grasp of it.

That's fair :) Sorry to call you out like that!

ayushsharma82 commented 1 year ago

A working fork till then for easy install: https://github.com/ayushsharma82/homebridge-tuya-local

@iRayanKhan Feel free to pull and merge.

05TEVE commented 10 months ago

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself. Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

I would be happy to help out, but while I'm fluent in typescript, I have little to no experience building a homebridge plug-in. I've gone over the documentation countless times, but I haven't fully got the grasp of it.

That's fair :) Sorry to call you out like that!

I am happy to help out and try keep this plugin alive. I messaged @iRayanKhan a while back on twitter but never

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained? This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

That was me that reached out. I have sent a request to add you on Discord to discuss further.

05TEVE commented 10 months ago

A working fork till then for easy install: https://github.com/ayushsharma82/homebridge-tuya-local

@iRayanKhan Feel free to pull and merge.

A working fork till then for easy install: https://github.com/ayushsharma82/homebridge-tuya-local

@iRayanKhan Feel free to pull and merge.

Hey @ayushsharma82, I have spoken with @iRayanKhan and got access to merge PRs into the repository with the intention to start fixing some of the issues listed. Looking at the changes you have made i am thinking it might make sense to start with merging your fork back and publishing a new version?

05TEVE commented 10 months ago

Changes have been published up to NPM as version 3.1.0-beta.2. Should be available for testing on homebridge.