Skip to content

🧹 Extract hardcoded command strings in DeviceControls.tsx#37

Merged
0suu merged 6 commits into
mainfrom
refactor/extract-device-controls-constants-16446796209692383861
Feb 20, 2026
Merged

🧹 Extract hardcoded command strings in DeviceControls.tsx#37
0suu merged 6 commits into
mainfrom
refactor/extract-device-controls-constants-16446796209692383861

Conversation

@0suu

@0suu 0suu commented Feb 7, 2026

Copy link
Copy Markdown
Owner
  • What: Extracted hardcoded command strings (e.g., "turnOn", "command", "default") from src/renderer/src/components/DeviceControls.tsx into a new constants file src/renderer/src/constants/commandConstants.ts.
  • Why: To improve maintainability, reduce the risk of typos, and make it easier to update command names in the future.
  • Verification:
    • Ran npm run build:vite (Success).
    • Ran npm test (Success). Added src/renderer/src/components/__tests__/DeviceControls.test.tsx.
    • Verified visually with Playwright script in mock mode (Success).
  • Result: The code is cleaner and more maintainable without any functional changes.

PR created automatically by Jules for task 16446796209692383861 started by @0suu

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Feb 7, 2026

Copy link
Copy Markdown

Deploying switchbotcontroller with  Cloudflare Pages  Cloudflare Pages

Latest commit: 248e7ad
Status: ✅  Deploy successful!
Preview URL: https://b60ab638.switchbotcontroller.pages.dev
Branch Preview URL: https://refactor-extract-device-cont.switchbotcontroller.pages.dev

View logs

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @0suu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the DeviceControls.tsx component by centralizing all hardcoded command strings into a new commandConstants.ts file. This change aims to enhance code maintainability, minimize potential errors from typos, and streamline future updates to command definitions, all while preserving existing functionality.

Highlights

  • Code Refactoring: Extracted hardcoded command strings (e.g., "turnOn", "command", "default") from src/renderer/src/components/DeviceControls.tsx into a new constants file src/renderer/src/constants/commandConstants.ts.
  • Maintainability and Error Reduction: The change improves maintainability, reduces the risk of typos, and simplifies future updates to command names by centralizing their definitions.
  • New Test File: Added a new test file, src/renderer/src/components/__tests__/DeviceControls.test.tsx, to ensure the DeviceControls component functions correctly with the new constants.
  • No Functional Changes: The refactoring was performed without introducing any functional changes, as verified by successful builds, tests, and visual inspection.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • package-lock.json
    • Removed the yaml dependency, which appears to be an unrelated cleanup.
  • src/renderer/src/components/DeviceControls.tsx
    • Imported a new set of command constants from ../constants/commandConstants.
    • Replaced numerous instances of hardcoded string literals like "turnOn", "default", "command", "customize", "press", "setMode", "setPosition", "setBrightness", "setColor", and "setColorTemperature" with their respective constant variables.
  • src/renderer/src/components/tests/DeviceControls.test.tsx
    • Added a new test suite for the DeviceControls component.
    • Includes a basic rendering test for a 'Bot' device, verifying that elements like the "Turn On" button are present and correctly rendered, implicitly using the new constants.
  • src/renderer/src/constants/commandConstants.ts
    • Introduced a new file to define and export various command-related string constants, categorizing them into command types, parameter values, and common commands.
Activity
  • The pull request was automatically generated by Jules for task [16446796209692383861].
  • The author, @0suu, initiated the task.
  • Verification steps included successful npm run build:vite, npm test, and visual verification with a Playwright script in mock mode.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request is a good step towards improving maintainability by extracting hardcoded command strings into constants. The changes are well-implemented for the targeted commands.

I've left a couple of suggestions to further improve the code quality and test coverage. Specifically, I've pointed out an opportunity to make type definitions more robust by deriving them from constants, and a suggestion to enhance the new test file with behavioral checks.

Also, it seems the refactoring of hardcoded strings is not exhaustive. Several command strings like "pause", "setAll", "volumeAdd", etc., remain hardcoded in DeviceControls.tsx. For consistency and to fully achieve the goal of this PR, it would be beneficial to extract these remaining strings into constants as well, perhaps in a follow-up PR if they are out of scope for this one.

const [customParameter, setCustomParameter] = useState("default");
const [customCommandType, setCustomCommandType] = useState<"command" | "customize">("command");
const [customParameter, setCustomParameter] = useState(DEFAULT_PARAMETER);
const [customCommandType, setCustomCommandType] = useState<"command" | "customize">(COMMAND_TYPE_COMMAND);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While you've correctly updated the initial value to use a constant, the type annotation "command" | "customize" is still using hardcoded string literals. To make this more robust and maintainable, you could define a CommandType in commandConstants.ts and use it here. This ensures that the type is always in sync with the constant values.

For example, in commandConstants.ts:

export const COMMAND_TYPE_COMMAND = "command" as const;
export const COMMAND_TYPE_CUSTOMIZE = "customize" as const;

export type CommandType = typeof COMMAND_TYPE_COMMAND | typeof COMMAND_TYPE_CUSTOMIZE;

And in this file:

import { CommandType, /* ...other imports */ } from '../constants/commandConstants';
// ...
const [customCommandType, setCustomCommandType] = useState<CommandType>(COMMAND_TYPE_COMMAND);

This change should then be propagated to other places where "command" | "customize" is used.

Comment on lines +64 to +79
it('renders Bot controls', () => {
const store = createTestStore();
render(
<Provider store={store}>
<DeviceControls device={mockDevice} />
</Provider>
);

// Check if "Bot" section is rendered
expect(screen.getByText('Bot')).toBeInTheDocument();

// Check if buttons with constant-derived labels/actions are present
// Note: The button text is translated key, e.g. "On", "Off"
// "Turn On" is the text in the button for Bot
expect(screen.getByText('Turn On')).toBeInTheDocument();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It's great that you've added a test for this component! This test is a good start as a smoke test to ensure the component renders without crashing.

To make it more robust, consider adding a test case that verifies the component's behavior. For example, you could check that clicking the 'Turn On' button dispatches the sendDeviceCommand action with the correct payload. This would provide more confidence that the controls are wired up correctly.

@0suu

0suu commented Feb 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

google-labs-jules Bot and others added 2 commits February 20, 2026 22:53
Co-authored-by: 0suu <46421931+0suu@users.noreply.github.com>
Co-authored-by: 0suu <46421931+0suu@users.noreply.github.com>
@0suu 0suu force-pushed the refactor/extract-device-controls-constants-16446796209692383861 branch from 4226d4a to 142ca92 Compare February 20, 2026 13:53
@0suu

0suu commented Feb 20, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@0suu 0suu merged commit 0e80d60 into main Feb 20, 2026
2 checks passed
@0suu 0suu deleted the refactor/extract-device-controls-constants-16446796209692383861 branch February 20, 2026 15:09
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

Successfully merging this pull request may close these issues.

1 participant