Skip to content

Fix chamber target temperature for K2 Base via Moonraker fallback - #57

Merged
3dg1luk43 merged 1 commit into
3dg1luk43:mainfrom
PavelStoyan0v:main
Jan 23, 2026
Merged

Fix chamber target temperature for K2 Base via Moonraker fallback#57
3dg1luk43 merged 1 commit into
3dg1luk43:mainfrom
PavelStoyan0v:main

Conversation

@PavelStoyan0v

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @PavelStoyan0v, 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 enhances the Creality Home Assistant integration by improving the accuracy and control of chamber target temperatures, specifically for K2 Base printers. It introduces a robust fallback to Moonraker for missing telemetry data and refines the temperature setting process with optimistic updates and model-specific logic adjustments.

Highlights

  • K2 Base Chamber Temperature Fix: Implemented a fallback mechanism for K2 Base printers to accurately retrieve and set chamber target temperatures by polling the Moonraker API, addressing issues where the native WebSocket telemetry might report incorrect or missing data.
  • Telemetry Data Refinement: Added logic to suppress erroneous targetBoxTemp:0 values from K2 Base printers' native telemetry to prevent incorrect readings.
  • Optimistic UI Updates: Introduced optimistic updates for nozzle, bed, and chamber target temperatures, ensuring the Home Assistant UI reflects user-set values immediately, even before the printer confirms the change.
  • K2 Base Chamber Heater Logic: Modified the chamber heater control logic for K2 Base models to bypass the 40°C minimum activation restriction, allowing for more flexible temperature settings.
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
Contributor

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 introduces a fix for the chamber target temperature on K2 Base printers by implementing a fallback mechanism to poll Moonraker. It also improves the user experience by adding optimistic updates to the UI for temperature controls. The changes are logical and address the issue. My review includes suggestions to improve performance by caching the printer model detection result, which is currently re-evaluated frequently. I've also pointed out an opportunity to make the error handling in the new Moonraker polling logic more robust and a minor code style issue.

Comment on lines +300 to +301
if (payload.get("targetBoxTemp") == 0) and ModelDetection(self.data).is_k2_base:
payload.pop("targetBoxTemp")

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.

medium

The ModelDetection class is instantiated on every WebSocket message here and again on line 316. This is inefficient as the printer model is static and messages can arrive frequently. Consider detecting the model once and caching the result. For example, you could add a _is_k2_base attribute to the coordinator, initialize it to None, and then compute it once when model information becomes available in self.data.

Comment on lines +440 to +442
except Exception:
# Moonraker might be disabled or port 7125 blocked; fail silently
pass

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.

medium

The except Exception: block is too broad and will catch and silently pass any exception. This could hide bugs, for example a KeyError if the response format from Moonraker changes, or other unexpected issues. It's better to catch specific exceptions related to HTTP requests, or at a minimum, log the caught exception at a debug level to aid in troubleshooting.

Suggested change
except Exception:
# Moonraker might be disabled or port 7125 blocked; fail silently
pass
except Exception as e:
# Moonraker might be disabled or port 7125 blocked; fail silently
_LOGGER.debug("Failed to poll Moonraker for extras: %s", e)

# Chamber heater only activates when > 40°C (K2 Plus behavior)
v = 0 if value <= 40 else int(round(value))
# Bypass this restriction for the Base K2.
if ModelDetection(self.coordinator.data).is_k2_base:

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.

medium

The ModelDetection class is instantiated every time async_set_native_value is called. While less frequent than in the coordinator's message handler, this is still inefficient as the model is static. Consider using a cached model detection result from the coordinator, as suggested for coordinator.py.

# Optimistic update
self.coordinator.data["targetBoxTemp"] = v
self.coordinator.async_update_listeners()

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.

medium

This line is empty but contains indentation, which is unnecessary. Please remove it for code cleanliness.

@3dg1luk43
3dg1luk43 merged commit d8d3693 into 3dg1luk43:main Jan 23, 2026
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