Repository navigation
Update tuya-smart extension - #29505
anwarulislam wants to merge 1 commit into
Conversation
- Add deeplink control feature and fuzzy search for device management - Initial fork commit
|
Thank you for your contribution! 🎉 🔔 @AndresMorelos you might want to have a look. You can use this guide to learn how to check out the Pull Request locally in order to test it. 📋 Quick checkout commandsBRANCH="ext/tuya-smart"
FORK_URL="https://github.com/anwarulislam/raycast-extensions.git"
EXTENSION_NAME="tuya-smart"
REPO_NAME="raycast-extensions"
git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run devWe're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 15 business days. |
Greptile SummaryThis PR adds deeplink support to the Tuya Smart extension, enabling Apple Shortcuts and Siri voice control via a new
Confidence Score: 3/5The core deeplink mechanism works, but users following the documented shortcut examples with a separate The new command never reads
Important Files Changed
Prompt To Fix All With AIFix the following 4 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 4
extensions/tuya-smart/src/control-device.tsx:61-97
**`action` argument read from props is missing — docs/code mismatch causes wrong behavior**
Both `SHORTCUTS_GUIDE.md` and `SIRI_VOICE_GUIDE.md` instruct users to pass a separate `action` key in deeplink arguments (e.g., `{"query":"tubelight","action":"on"}`), but the code only reads `query` from `props.arguments` and then re-parses the action from within the query string. When a user follows the documented format with `query:"tubelight"` and `action:"on"`, the `action` value is never consumed — `parseQueryForAction("tubelight")` finds no action keyword and defaults to toggle, so the device is toggled instead of turned on.
### Issue 2 of 4
extensions/tuya-smart/src/control-device.tsx:134-169
**Dead code: `fuzzyMatchAction` is never called**
The `fuzzyMatchAction` function is defined but not referenced anywhere in the file. `parseQueryForAction` is used instead for extracting the action from the query string. This adds dead code and creates a Fuse instance unnecessarily.
### Issue 3 of 4
extensions/tuya-smart/src/control-device.tsx:19-40
Debug `console.log` calls should be removed before shipping. They will appear in users' logs and add noise.
```suggestion
try {
// Load cached devices
const cache = new Cache();
const cachedDevices = cache.get("devices");
if (!cachedDevices) {
await showHUD("❌ No cached devices found. Please open Tuya Smart extension first.");
return;
}
const devices: Device[] = JSON.parse(cachedDevices);
if (devices.length === 0) {
await showHUD("❌ No devices available");
return;
}
// Parse action and device name from query
const { action, cleanedQuery } = parseQueryForAction(query);
```
### Issue 4 of 4
extensions/tuya-smart/src/control-device.tsx:8-10
**Manually defined `Argument` interface — prefer auto-generated type**
`ControlDeviceArguments` is a manually defined interface for command arguments, but Raycast auto-generates argument types in `raycast-env.d.ts` when the extension builds. Manual definitions can drift out of sync with `package.json` and cause subtle type mismatches over time.
Reviews (1): Last reviewed commit: "Update tuya-smart extension" | Re-trigger Greptile |
| threshold: 0.4, // 0.0 = perfect match, 1.0 = match anything | ||
| ignoreLocation: true, | ||
| includeScore: true, | ||
| }); | ||
|
|
||
| // Search for the switch using cleaned query | ||
| const results = fuse.search(cleanedQuery); | ||
|
|
||
| if (results.length === 0) { | ||
| await showHUD(`❌ No switch found matching "${cleanedQuery}"`); | ||
| return; | ||
| } | ||
|
|
||
| // Get the best match | ||
| const bestMatch = results[0].item; | ||
| const { device, switch: switchCommand } = bestMatch; | ||
|
|
||
| // Use parsed action or default to toggle | ||
| const finalAction = action; | ||
|
|
||
| // Determine the command value based on action | ||
| const command = getCommandForSwitch(device, switchCommand, finalAction); | ||
|
|
||
| if (!command) { | ||
| await showHUD(`❌ Cannot perform "${finalAction}" on ${switchCommand.name || switchCommand.code}`); | ||
| return; | ||
| } | ||
|
|
||
| // Send the command | ||
| const success = await sendCommand({ | ||
| device_id: device.id, | ||
| commands: [command], | ||
| }); | ||
|
|
||
| if (success) { | ||
| const switchName = switchCommand.name || switchCommand.code; | ||
| const actionText = finalAction === "toggle" ? "toggled" : `turned ${finalAction}`; |
There was a problem hiding this comment.
action argument read from props is missing — docs/code mismatch causes wrong behavior
Both SHORTCUTS_GUIDE.md and SIRI_VOICE_GUIDE.md instruct users to pass a separate action key in deeplink arguments (e.g., {"query":"tubelight","action":"on"}), but the code only reads query from props.arguments and then re-parses the action from within the query string. When a user follows the documented format with query:"tubelight" and action:"on", the action value is never consumed — parseQueryForAction("tubelight") finds no action keyword and defaults to toggle, so the device is toggled instead of turned on.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/tuya-smart/src/control-device.tsx
Line: 61-97
Comment:
**`action` argument read from props is missing — docs/code mismatch causes wrong behavior**
Both `SHORTCUTS_GUIDE.md` and `SIRI_VOICE_GUIDE.md` instruct users to pass a separate `action` key in deeplink arguments (e.g., `{"query":"tubelight","action":"on"}`), but the code only reads `query` from `props.arguments` and then re-parses the action from within the query string. When a user follows the documented format with `query:"tubelight"` and `action:"on"`, the `action` value is never consumed — `parseQueryForAction("tubelight")` finds no action keyword and defaults to toggle, so the device is toggled instead of turned on.
How can I resolve this? If you propose a fix, please make it concise.| } | ||
|
|
||
| function fuzzyMatchAction(input: string): string { | ||
| const normalized = input.toLowerCase().trim(); | ||
|
|
||
| // Define action patterns with their keywords | ||
| const actionPatterns = [ | ||
| { | ||
| action: "on", | ||
| keywords: ["on", "turn on", "switch on", "enable", "start", "activate", "open", "power on"], | ||
| }, | ||
| { | ||
| action: "off", | ||
| keywords: ["off", "turn off", "switch off", "disable", "stop", "deactivate", "close", "power off", "shut"], | ||
| }, | ||
| { | ||
| action: "toggle", | ||
| keywords: ["toggle", "switch", "flip"], | ||
| }, | ||
| ]; | ||
|
|
||
| // Create fuzzy search for actions | ||
| const allOptions = actionPatterns.flatMap((pattern) => | ||
| pattern.keywords.map((keyword) => ({ | ||
| keyword, | ||
| action: pattern.action, | ||
| })) | ||
| ); | ||
|
|
||
| const fuse = new Fuse(allOptions, { | ||
| keys: ["keyword"], | ||
| threshold: 0.3, // More strict for actions | ||
| includeScore: true, | ||
| }); | ||
|
|
||
| const results = fuse.search(normalized); |
There was a problem hiding this comment.
Dead code:
fuzzyMatchAction is never called
The fuzzyMatchAction function is defined but not referenced anywhere in the file. parseQueryForAction is used instead for extracting the action from the query string. This adds dead code and creates a Fuse instance unnecessarily.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/tuya-smart/src/control-device.tsx
Line: 134-169
Comment:
**Dead code: `fuzzyMatchAction` is never called**
The `fuzzyMatchAction` function is defined but not referenced anywhere in the file. `parseQueryForAction` is used instead for extracting the action from the query string. This adds dead code and creates a Fuse instance unnecessarily.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| console.log(`Received query: "${query}"`); | ||
|
|
||
| try { | ||
| // Load cached devices | ||
| const cache = new Cache(); | ||
| const cachedDevices = cache.get("devices"); | ||
|
|
||
| if (!cachedDevices) { | ||
| await showHUD("❌ No cached devices found. Please open Tuya Smart extension first."); | ||
| return; | ||
| } | ||
|
|
||
| const devices: Device[] = JSON.parse(cachedDevices); | ||
|
|
||
| if (devices.length === 0) { | ||
| await showHUD("❌ No devices available"); | ||
| return; | ||
| } | ||
|
|
||
| // Parse action and device name from query | ||
| const { action, cleanedQuery } = parseQueryForAction(query); | ||
| console.log(`Parsed action: "${action}", cleaned query: "${cleanedQuery}"`); |
There was a problem hiding this comment.
Debug
console.log calls should be removed before shipping. They will appear in users' logs and add noise.
| console.log(`Received query: "${query}"`); | |
| try { | |
| // Load cached devices | |
| const cache = new Cache(); | |
| const cachedDevices = cache.get("devices"); | |
| if (!cachedDevices) { | |
| await showHUD("❌ No cached devices found. Please open Tuya Smart extension first."); | |
| return; | |
| } | |
| const devices: Device[] = JSON.parse(cachedDevices); | |
| if (devices.length === 0) { | |
| await showHUD("❌ No devices available"); | |
| return; | |
| } | |
| // Parse action and device name from query | |
| const { action, cleanedQuery } = parseQueryForAction(query); | |
| console.log(`Parsed action: "${action}", cleaned query: "${cleanedQuery}"`); | |
| try { | |
| // Load cached devices | |
| const cache = new Cache(); | |
| const cachedDevices = cache.get("devices"); | |
| if (!cachedDevices) { | |
| await showHUD("❌ No cached devices found. Please open Tuya Smart extension first."); | |
| return; | |
| } | |
| const devices: Device[] = JSON.parse(cachedDevices); | |
| if (devices.length === 0) { | |
| await showHUD("❌ No devices available"); | |
| return; | |
| } | |
| // Parse action and device name from query | |
| const { action, cleanedQuery } = parseQueryForAction(query); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/tuya-smart/src/control-device.tsx
Line: 19-40
Comment:
Debug `console.log` calls should be removed before shipping. They will appear in users' logs and add noise.
```suggestion
try {
// Load cached devices
const cache = new Cache();
const cachedDevices = cache.get("devices");
if (!cachedDevices) {
await showHUD("❌ No cached devices found. Please open Tuya Smart extension first.");
return;
}
const devices: Device[] = JSON.parse(cachedDevices);
if (devices.length === 0) {
await showHUD("❌ No devices available");
return;
}
// Parse action and device name from query
const { action, cleanedQuery } = parseQueryForAction(query);
```
How can I resolve this? If you propose a fix, please make it concise.| } | ||
|
|
||
| interface SwitchItem { |
There was a problem hiding this comment.
Manually defined
Argument interface — prefer auto-generated type
ControlDeviceArguments is a manually defined interface for command arguments, but Raycast auto-generates argument types in raycast-env.d.ts when the extension builds. Manual definitions can drift out of sync with package.json and cause subtle type mismatches over time.
Rule Used: What: Don't manually define Preferences for `get... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/tuya-smart/src/control-device.tsx
Line: 8-10
Comment:
**Manually defined `Argument` interface — prefer auto-generated type**
`ControlDeviceArguments` is a manually defined interface for command arguments, but Raycast auto-generates argument types in `raycast-env.d.ts` when the extension builds. Manual definitions can drift out of sync with `package.json` and cause subtle type mismatches over time.
**Rule Used:** What: Don't manually define `Preferences` for `get... ([source](https://app.greptile.com/raycast/-/custom-context?memory=d93fc9fb-a45d-4479-a6a4-b1b4af98ebc8))
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
0xdhrv
left a comment
There was a problem hiding this comment.
Hi @anwarulislam 👋
Thanks for the contribution 🔥
Could you look into the suggestions from Greptile?
I converted this PR into a draft until it's ready for the review, please press the button Ready for review when it's ready and we'll have a look 😊
|
This pull request has been automatically marked as stale because it did not have any recent activity. It will be closed if no further activity occurs in the next 7 days to keep our backlog clean 😊 |
|
This pull request has been automatically closed due to inactivity. Feel free to comment in the thread when you're ready to continue working on it 🙂 You can also catch us in Slack if you want to discuss this. |
Description
Screencast
Checklist
npm run buildand tested this distribution build in Raycastassetsfolder are used by the extension itselfREADMEare placed outside of themetadatafolder