Skip to content

Update tuya-smart extension - #29505

Closed
anwarulislam wants to merge 1 commit into
raycast:mainfrom
anwarulislam:ext/tuya-smart
Closed

anwarulislam wants to merge 1 commit into
raycast:mainfrom
anwarulislam:ext/tuya-smart

Conversation

@anwarulislam

@anwarulislam anwarulislam commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Screencast

Checklist

- Add deeplink control feature and fuzzy search for device management
- Initial fork commit
@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: tuya-smart Issues related to the tuya-smart extension platform: macOS OP is contributor The OP of the PR is a contributor of the extension labels Jul 17, 2026
@raycastbot

Copy link
Copy Markdown
Collaborator

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 commands
BRANCH="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 dev

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 15 business days.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds deeplink support to the Tuya Smart extension, enabling Apple Shortcuts and Siri voice control via a new control-device no-view command that uses Fuse.js fuzzy search against cached device data.

  • A new control-device command reads devices from the Raycast cache (populated by the main extension view), parses an action and device name from a single query argument using regex, and sends the resulting command via the Tuya API.
  • Two new guides (SHORTCUTS_GUIDE.md, SIRI_VOICE_GUIDE.md) document Shortcuts/Siri setup, but their deeplink examples pass a separate action JSON key that the command code never reads from props, so the documented action field is silently ignored and the device defaults to toggle.
  • A fuzzyMatchAction helper function is defined in control-device.tsx but never called, and two console.log debug statements were left in the shipped code.

Confidence Score: 3/5

The core deeplink mechanism works, but users following the documented shortcut examples with a separate action field will get unexpected toggle behavior instead of explicit on/off control.

The new command never reads props.arguments.action, yet both guides teach users to pass it as a separate deeplink key. Any shortcut built using the documented format will silently drop the action and toggle the device instead of turning it on.

src/control-device.tsx needs the action argument wired up, and both SHORTCUTS_GUIDE.md and SIRI_VOICE_GUIDE.md need their deeplink examples corrected to match actual behavior.

Important Files Changed

Filename Overview
extensions/tuya-smart/src/control-device.tsx New no-view command for deeplink/Shortcuts integration using Fuse.js fuzzy search; contains a logic bug where the documented action argument is never read from props, dead code in fuzzyMatchAction, and leftover debug logs.
extensions/tuya-smart/package.json Adds control-device no-view command and fuse.js dependency; action is not declared as an argument, which is consistent with how the code reads props but inconsistent with how the guides document the deeplink format.
extensions/tuya-smart/SHORTCUTS_GUIDE.md New guide for Apple Shortcuts integration; the deeplink examples use a separate action key that the command code never reads from props, making those examples misleading.
extensions/tuya-smart/SIRI_VOICE_GUIDE.md New guide for Siri voice control via Apple Shortcuts; same action argument inconsistency as SHORTCUTS_GUIDE.md, but overall setup instructions are clear and useful.
extensions/tuya-smart/CHANGELOG.md New changelog entry added at the top with {PR_MERGE_DATE} placeholder, correctly following the standard convention.
extensions/tuya-smart/package-lock.json Lock file updated to add [email protected] (resolving the ^7.1.0 range in package.json); no concerns.
Prompt To Fix All With AI
Fix 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

Comment on lines +61 to +97
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}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment on lines +134 to +169
}

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Comment on lines +19 to +40
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}"`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Debug console.log calls should be removed before shipping. They will appear in users' logs and add noise.

Suggested change
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.

Comment on lines +8 to +10
}

interface SwitchItem {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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 0xdhrv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😊

@0xdhrv
0xdhrv marked this pull request as draft July 17, 2026 07:51
@raycastbot

Copy link
Copy Markdown
Collaborator

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 😊

@raycastbot

Copy link
Copy Markdown
Collaborator

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.

@raycastbot raycastbot closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extension fix / improvement Label for PRs with extension's fix improvements extension: tuya-smart Issues related to the tuya-smart extension OP is contributor The OP of the PR is a contributor of the extension platform: macOS status: stalled Stalled due inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants