Skip to content

Refactor DeviceControls into sub-components#38

Merged
0suu merged 5 commits into
mainfrom
refactor-device-controls-5484754664553043235
Feb 20, 2026
Merged

Refactor DeviceControls into sub-components#38
0suu merged 5 commits into
mainfrom
refactor-device-controls-5484754664553043235

Conversation

@0suu

@0suu 0suu commented Feb 7, 2026

Copy link
Copy Markdown
Owner

Split the monolithic DeviceControls.tsx component into smaller, device-specific components to improve code health, maintainability, and readability.

Changes:

  • Created src/renderer/src/components/device-controls/ directory.
  • Extracted logic for each device type (Bot, Plug, Curtain, Light, Humidifier, Fan, Vacuum, Lock, Infrared Remote) into separate components.
  • Created src/renderer/src/hooks/useDeviceType.ts to centralize device type detection logic.
  • Created src/renderer/src/components/device-controls/utils.ts for shared utility functions.
  • Created src/renderer/src/components/device-controls/DeviceControls.types.ts for shared type definitions.
  • Refactored DeviceControls.tsx to use these new components and hooks.

Verified via tsc to ensure type safety and correct imports.


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

- Split DeviceControls.tsx into multiple device-specific components in src/renderer/src/components/device-controls/
- Create useDeviceType hook for device capability detection
- Create shared types and utility functions
- Improve maintainability and readability by reducing monolithic component size

Co-authored-by: 0suu <46421931+0suu@users.noreply.github.com>
@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.

@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 focuses on a significant refactoring effort to enhance the maintainability and readability of the device control interface. By decomposing a large, single component into a set of specialized sub-components, the changes aim to create a more modular and scalable architecture. This approach makes it easier to understand, test, and extend controls for individual device types without impacting the entire system, ultimately improving the overall code health of the application.

Highlights

  • Code Structure Refinement: The monolithic DeviceControls.tsx component has been broken down into smaller, more manageable, and device-specific sub-components, significantly improving code organization.
  • Modular Device Controls: Dedicated components have been created for various device types including Bot, Plug, Curtain, Light, Humidifier, Fan, Vacuum, Lock, and Infrared Remote, centralizing their respective control logic and UI.
  • Centralized Device Type Detection: A new useDeviceType.ts hook has been introduced to encapsulate and centralize the logic for detecting and categorizing device types, promoting reusability and consistency.
  • Shared Utilities and Types: Common utility functions and type definitions have been extracted into utils.ts and DeviceControls.types.ts respectively, reducing redundancy and improving maintainability.
  • Main Component Simplification: The original DeviceControls.tsx component has been refactored to act as an orchestrator, importing and rendering the appropriate sub-components based on the device type, leading to a cleaner and more readable main file.
  • Dependency Cleanup: The package-lock.json file was updated to remove an unused yaml dependency.

🧠 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 from the lock file.
  • src/renderer/src/components/DeviceControls.tsx
    • Removed numerous imports for UI components (e.g., Chip, Divider, MenuItem, Slider, TextField) and Redux selectors/actions that are now handled within sub-components.
    • Eliminated many state variables related to specific device controls (e.g., position, brightness, color, customCommand, AC settings, TV channel, humidifier settings, vacuum power level).
    • Removed utility functions like clamp, hexToRgbParameter, and getConfirmCommandStorageKey, which have been moved to src/renderer/src/components/device-controls/utils.ts.
    • Integrated the new useDeviceType hook to determine device characteristics.
    • Imported and conditionally rendered new device-specific control components (BotControls, PlugControls, CurtainControls, LightControls, HumidifierControls, FanControls, VacuumControls, LockControls, InfraredRemoteControls, DynamicControls, CustomCommandControls).
    • Simplified the sendCommand function signature and logic, now accepting an optional commandType.
    • The component now primarily acts as a wrapper, passing common props to the specialized control components.
  • src/renderer/src/components/device-controls/BotControls.tsx
    • New component created to encapsulate the UI and logic for 'Bot' devices, including mode display and control buttons.
  • src/renderer/src/components/device-controls/CurtainControls.tsx
    • New component created to encapsulate the UI and logic for 'Curtain' and 'Blind' devices, including open/close/pause buttons and a position slider.
  • src/renderer/src/components/device-controls/CustomCommandControls.tsx
    • New component created to provide a generic interface for sending custom commands, with specific handling for infrared remotes.
  • src/renderer/src/components/device-controls/DeviceControls.types.ts
    • New file defining shared types, including SendCommand function signature and DeviceControlProps interface for consistent prop passing to sub-components.
  • src/renderer/src/components/device-controls/DynamicControls.tsx
    • New component created to render controls dynamically based on device command definitions, supporting range, enum, and text parameters.
  • src/renderer/src/components/device-controls/FanControls.tsx
    • New component created to encapsulate the UI and logic for 'Fan' devices, including on/off, wind mode, nightlight mode buttons, and a wind speed slider.
  • src/renderer/src/components/device-controls/HumidifierControls.tsx
    • New component created to encapsulate the UI and logic for 'Humidifier' devices, supporting different modes (evaporative/standard), child lock, and target humidity/atomization efficiency sliders.
  • src/renderer/src/components/device-controls/InfraredRemoteControls.tsx
    • New component created to encapsulate the UI and logic for 'Infrared Remote' devices, including common power controls, and specialized controls for AC, TV, Speaker, Fan, and Light remotes.
  • src/renderer/src/components/device-controls/LightControls.tsx
    • New component created to encapsulate the UI and logic for 'Light' devices, including on/off/toggle, brightness, color temperature, color pickers, and night light scene management.
  • src/renderer/src/components/device-controls/LockControls.tsx
    • New component created to encapsulate the UI and logic for 'Lock' devices, including lock/unlock buttons and a deadbolt control.
  • src/renderer/src/components/device-controls/PlugControls.tsx
    • New component created to encapsulate the UI and logic for 'Plug' devices, providing simple on/off controls.
  • src/renderer/src/components/device-controls/utils.ts
    • New file containing shared utility functions: clamp, hexToRgbParameter, getConfirmCommandStorageKey, and a SectionLabel component for consistent section headings.
  • src/renderer/src/hooks/useDeviceType.ts
    • New custom hook created to centralize the logic for determining various device-specific properties and capabilities (e.g., isBot, isLight, supportsLightBrightness, isRemoteAC).
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.

@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: 301e263
Status: ✅  Deploy successful!
Preview URL: https://258fe6e3.switchbotcontroller.pages.dev
Branch Preview URL: https://refactor-device-controls-548.switchbotcontroller.pages.dev

View logs

@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 significant and well-executed refactoring of the monolithic DeviceControls.tsx component. Splitting the logic into device-specific components and a useDeviceType hook greatly improves code organization, readability, and maintainability. The changes are clean and follow good React practices.

My main feedback is to avoid redundant calls to the useDeviceType hook in the newly created sub-components. The device type information can be determined once in the parent DeviceControls component and passed down as props. This will make the code more efficient and enforce a clearer data flow from parent to child components.

Comment on lines +15 to +22
export const CustomCommandControls: React.FC<DeviceControlProps> = ({
device,
sendCommand,
controlsDisabled,
dense,
}) => {
const { t } = useTranslation();
const { isInfraredRemote } = useDeviceType(device);

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

The useDeviceType hook is called in multiple sub-components (CustomCommandControls, DynamicControls, HumidifierControls, InfraredRemoteControls, LightControls, LockControls), which is redundant as the parent DeviceControls component already has this information. This can be optimized by calling the hook once in the parent and passing the result down as a prop.

Here's a summary of the recommended refactoring:

  1. In useDeviceType.ts, export the return type of the hook:

    export type DeviceTypeInfo = ReturnType<typeof useDeviceType>;
  2. In DeviceControls.types.ts, add deviceTypeInfo to DeviceControlProps:

    import { DeviceTypeInfo } from '../../hooks/useDeviceType';
    
    export interface DeviceControlProps {
      // ... other props
      deviceTypeInfo: DeviceTypeInfo;
    }
  3. In DeviceControls.tsx, call the hook once and pass the result object in controlProps:

    const deviceTypeInfo = useDeviceType(device);
    // ...
    const controlProps = {
      // ... other props
      deviceTypeInfo,
    };
  4. In this component and other affected sub-components, destructure deviceTypeInfo from props instead of calling the hook.

Suggested change
export const CustomCommandControls: React.FC<DeviceControlProps> = ({
device,
sendCommand,
controlsDisabled,
dense,
}) => {
const { t } = useTranslation();
const { isInfraredRemote } = useDeviceType(device);
export const CustomCommandControls: React.FC<DeviceControlProps> = ({
sendCommand,
controlsDisabled,
dense,
deviceTypeInfo,
}) => {
const { t } = useTranslation();
const { isInfraredRemote } = deviceTypeInfo;

@0suu

0suu commented Feb 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Reviewed PR comments and determined that no code changes were necessary as the only comment was directed at another bot.

Co-authored-by: 0suu <46421931+0suu@users.noreply.github.com>
@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".

Copilot AI left a comment

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.

Pull request overview

This PR refactors the monolithic DeviceControls.tsx component (previously over 1300 lines) into smaller, focused components organized in a new device-controls/ directory. The refactoring improves maintainability by separating concerns and reducing complexity, making the codebase easier to test, debug, and extend.

Changes:

  • Created a custom hook useDeviceType to centralize device type detection logic
  • Extracted device-specific UI logic into 11 separate control components (Bot, Plug, Curtain, Light, Humidifier, Fan, Vacuum, Lock, Infrared Remote, Dynamic, and Custom Command controls)
  • Created shared utilities and type definitions to support the new component structure

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/renderer/src/hooks/useDeviceType.ts New hook that centralizes device type detection and feature support logic
src/renderer/src/components/device-controls/utils.tsx Shared utility functions (clamp, hexToRgbParameter, etc.) and common UI components
src/renderer/src/components/device-controls/DeviceControls.types.ts Type definitions for the control components interface
src/renderer/src/components/device-controls/BotControls.tsx Extracted Bot device control UI
src/renderer/src/components/device-controls/PlugControls.tsx Extracted Plug device control UI
src/renderer/src/components/device-controls/CurtainControls.tsx Extracted Curtain/Blind device control UI
src/renderer/src/components/device-controls/LightControls.tsx Extracted lighting device control UI with night light scene functionality
src/renderer/src/components/device-controls/HumidifierControls.tsx Extracted humidifier control UI for both standard and evaporative models
src/renderer/src/components/device-controls/FanControls.tsx Extracted fan device control UI
src/renderer/src/components/device-controls/VacuumControls.tsx Extracted vacuum cleaner control UI
src/renderer/src/components/device-controls/LockControls.tsx Extracted lock device control UI
src/renderer/src/components/device-controls/InfraredRemoteControls.tsx Extracted infrared remote control UI for various device types (AC, TV, Speaker, Fan, Light)
src/renderer/src/components/device-controls/DynamicControls.tsx Extracted dynamic command rendering based on device definitions
src/renderer/src/components/device-controls/CustomCommandControls.tsx Extracted custom command input UI
src/renderer/src/components/DeviceControls.tsx Refactored main component to orchestrate the sub-components
package-lock.json Unrelated removal of yaml dependency entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/renderer/src/hooks/useDeviceType.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@0suu 0suu merged commit 043e572 into main Feb 20, 2026
2 checks passed
@0suu 0suu deleted the refactor-device-controls-5484754664553043235 branch February 20, 2026 13:49
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.

2 participants