Skip to content

fix: prevent print-job entities from showing as unavailable when idle#2014

Merged
AdrianGarside merged 1 commit into
greghesp:mainfrom
BenHornerTech:fix-unavailable-sensors
May 22, 2026
Merged

fix: prevent print-job entities from showing as unavailable when idle#2014
AdrianGarside merged 1 commit into
greghesp:mainfrom
BenHornerTech:fix-unavailable-sensors

Conversation

@BenHornerTech
Copy link
Copy Markdown
Contributor

Description

Fixes several entities becoming unavailable in Home Assistant when the printer is idle or a print finishes. Entities now remain available at all times, with safety guards added to prevent commands being sent when the printer isn't in the correct state.

Buttons (Pause / Resume / Stop) - button.py:

  • Remove available() overrides so buttons inherit CoordinatorEntity.available (still correctly returns False when MQTT/connectivity is lost)
  • Add state guards inside async_press() - commands are only published when the printer is in the correct gcode state; ignored presses log a warning

Printing Speed Select - select.py:

  • Remove available() override that restricted the select to gcode_state == 'RUNNING'
  • Add state guard inside async_select_option() checking for RUNNING or PAUSE before applying speed changes

Print-job Sensors - definitions.py:

  • start_time: Set available_fn to always return True; existing _start_time_value_fn() already safely returns None
  • end_time: Set available_fn to always return True; add null guard to value_fn to prevent dt_util.as_utc(None) raising an AttributeError
  • gcode_file / gcode_file_downloaded: Set available_fn to always return True; return None instead of empty string when no file is set

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Documentation

  • I have updated the relevant documentation to reflect these changes
  • No documentation updates were necessary for this change

Testing

  • I have added/updated tests that prove my fix is effective or that my feature works
  • All new and existing tests passed

Additional Notes

Claude was used to assist with these fixes and I have tested on my P1S with AMS. I verified the entities remain available when idle, show unavailable only when the printer is genuinely offline, and buttons/speed select still function correctly during a print.

@docs-page
Copy link
Copy Markdown

docs-page Bot commented May 19, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/greghesp/ha-bambulab~2014

Documentation is deployed and generated using docs.page.

Comment thread custom_components/bambu_lab/button.py
@BenHornerTech BenHornerTech force-pushed the fix-unavailable-sensors branch from 38042c0 to 8a83402 Compare May 20, 2026 09:25
Comment thread custom_components/bambu_lab/select.py
- start_time, end_time, gcode_file and gcode_file_downloaded sensors
  now always available with null-safe value functions that return None
  when no data exists (showing 'unknown' instead of 'unavailable').
@BenHornerTech BenHornerTech force-pushed the fix-unavailable-sensors branch from 8a83402 to 5d6f68b Compare May 20, 2026 15:27
@AdrianGarside AdrianGarside self-requested a review May 22, 2026 01:28
@AdrianGarside AdrianGarside merged commit 45400dc into greghesp:main May 22, 2026
2 checks passed
@BenHornerTech BenHornerTech deleted the fix-unavailable-sensors branch May 22, 2026 13:15
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