Add mock web build for Cloudflare Pages previews#21
Conversation
Deploying switchbotcontroller with
|
| Latest commit: |
5b633ea
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ad09a12e.switchbotcontroller.pages.dev |
| Branch Preview URL: | https://codex-add-cloudflare-pages-b-rtwv.switchbotcontroller.pages.dev |
Summary of ChangesHello @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 enhances the project's deployability and testability by introducing a dedicated web build for Cloudflare Pages. It establishes a robust mock mode that allows the application's renderer to function entirely with local, simulated data, effectively decoupling it from the SwitchBot API and Electron-specific functionalities. This enables developers to preview and test the application's UI and logic in a web browser environment without requiring actual API credentials or an Electron setup, streamlining the development and review process for the frontend. Highlights
🧠 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. Using Gemini Code AssistThe 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
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 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
|
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
switchbotcintroller | 5b633ea | Dec 27 2025, 10:38 PM |
There was a problem hiding this comment.
Code Review
This pull request introduces a mock web build for Cloudflare Pages previews, which is a great addition for testing and previews. The implementation is well-structured, introducing a bridge abstraction to switch between the real API and a mock implementation. The changes across the codebase, from the API client to Redux slices and build configuration, are consistent and correctly implement the mock mode. I've found a couple of minor issues in the mock bridge implementation that should be addressed to improve its correctness and type safety. Overall, this is a solid contribution.
| async sendCommand(deviceId: string, command: string, parameter?: any) { | ||
| const status = mockStatuses[deviceId]; | ||
| if (status) { | ||
| if (command === "turnOn") { | ||
| status.power = "on"; | ||
| status.moving = false; | ||
| } else if (command === "turnOff") { | ||
| status.power = "off"; | ||
| status.moving = false; | ||
| } else if (command === "setPosition") { | ||
| const parsed = typeof parameter === "string" ? Number(String(parameter).split(",").pop()) : Number(parameter); | ||
| if (!Number.isNaN(parsed)) { | ||
| status.slidePosition = Math.max(0, Math.min(100, Math.round(parsed))); | ||
| } | ||
| status.moving = false; | ||
| } else if (command === "press") { | ||
| status.lastAction = "pressed"; | ||
| } | ||
| } | ||
| return { success: true, data: successResponse({}) }; | ||
| }, |
There was a problem hiding this comment.
The sendCommand mock has a couple of issues:
- The function signature doesn't match the
SwitchBotBridgeLikeinterface, as it's missing thecommandTypeparameter. - It incorrectly returns a success response even when the
deviceIdis not found. It should return a failure response in that case.
Here's a suggested fix that addresses both points.
async sendCommand(deviceId: string, command: string, parameter?: any, commandType?: "command" | "customize") {
const status = mockStatuses[deviceId];
if (!status) {
return { success: false, error: "Device not found" };
}
if (command === "turnOn") {
status.power = "on";
status.moving = false;
} else if (command === "turnOff") {
status.power = "off";
status.moving = false;
} else if (command === "setPosition") {
const parsed = typeof parameter === "string" ? Number(String(parameter).split(",").pop()) : Number(parameter);
if (!Number.isNaN(parsed)) {
status.slidePosition = Math.max(0, Math.min(100, Math.round(parsed)));
}
status.moving = false;
} else if (command === "press") {
status.lastAction = "pressed";
}
return { success: true, data: successResponse({}) };
},| if (typeof window === "undefined") return; | ||
| if (!window.switchBotBridge) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| window.switchBotBridge = mockSwitchBotBridge as any; |
There was a problem hiding this comment.
Using as any for type assertion should be avoided as it bypasses TypeScript's type checking and hides potential type errors. The eslint-disable-next-line comment also indicates this is a known issue. With the proposed fix to mockSwitchBotBridge.sendCommand, the mock object's type will be compatible with the SwitchBotBridgeAPI interface, so as any is no longer necessary. Please remove it and the corresponding eslint-disable comment.
| window.switchBotBridge = mockSwitchBotBridge as any; | |
| window.switchBotBridge = mockSwitchBotBridge; |
Summary
Testing
Codex Task