Suu/add night light button#23
Conversation
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 introduces a new 'Night Light' functionality, primarily targeting ceiling light devices. It allows users to associate a specific scene with a dedicated 'Night Light' button within the device controls. The chosen scene can then be executed with a single click, and these assignments are saved locally for convenience. This enhancement improves usability for ceiling lights by providing quick access to a common lighting configuration. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a 'Night Light' feature for ceiling light devices, which allows executing a pre-assigned scene. The changes are well-implemented across the UI component (DeviceControls.tsx), Redux state (sceneSlice.ts), and app initialization (App.tsx), including persistence and internationalization. The new UI provides good feedback to the user. I've added a couple of review comments with suggestions to improve the robustness of data loading from storage and to follow React-Redux best practices for selecting state, which will enhance performance and prevent potential issues with stale data.
| const assignedNightLightSceneId = useSelector((state: RootState) => | ||
| selectNightLightSceneForDevice(state, device.deviceId) | ||
| ); | ||
| const nightLightExecuting = useSelector((state: RootState) => | ||
| assignedNightLightSceneId ? selectSceneIsExecuting(state, assignedNightLightSceneId) : false | ||
| ); | ||
| const nightLightExecutionError = useSelector((state: RootState) => | ||
| assignedNightLightSceneId ? selectSceneExecutionError(state, assignedNightLightSceneId) : null | ||
| ); |
There was a problem hiding this comment.
These consecutive useSelector hooks, where some depend on the output of others from the previous render, can lead to stale data and unnecessary re-renders. It's a best practice to derive all related state within a single useSelector hook. This ensures data consistency for a single render and can be more performant, especially when providing a custom equality check to prevent re-renders if the derived data hasn't functionally changed.
| const assignedNightLightSceneId = useSelector((state: RootState) => | |
| selectNightLightSceneForDevice(state, device.deviceId) | |
| ); | |
| const nightLightExecuting = useSelector((state: RootState) => | |
| assignedNightLightSceneId ? selectSceneIsExecuting(state, assignedNightLightSceneId) : false | |
| ); | |
| const nightLightExecutionError = useSelector((state: RootState) => | |
| assignedNightLightSceneId ? selectSceneExecutionError(state, assignedNightLightSceneId) : null | |
| ); | |
| const { assignedNightLightSceneId, nightLightExecuting, nightLightExecutionError } = useSelector((state: RootState) => { | |
| const sceneId = selectNightLightSceneForDevice(state, device.deviceId); | |
| return { | |
| assignedNightLightSceneId: sceneId, | |
| nightLightExecuting: sceneId ? selectSceneIsExecuting(state, sceneId) : false, | |
| nightLightExecutionError: sceneId ? selectSceneExecutionError(state, sceneId) : null | |
| }; | |
| }, (left, right) => | |
| left.assignedNightLightSceneId === right.assignedNightLightSceneId && | |
| left.nightLightExecuting === right.nightLightExecuting && | |
| left.nightLightExecutionError === right.nightLightExecutionError | |
| ); |
| async () => { | ||
| try { | ||
| const stored = await window.electronStore.get(NIGHT_LIGHT_SCENE_STORAGE_KEY); | ||
| if (stored && typeof stored === "object") { |
There was a problem hiding this comment.
The check typeof stored === "object" is also true for arrays. If an array is somehow stored in NIGHT_LIGHT_SCENE_STORAGE_KEY (e.g., due to a bug or a previous data format), Object.entries will iterate over its indices, which is not the intended behavior for a key-value map. To make this data loading more robust, you should add a check to ensure the stored value is not an array.
| if (stored && typeof stored === "object") { | |
| if (stored && typeof stored === "object" && !Array.isArray(stored)) { |
No description provided.