Skip to content

fix: follow established callback pattern for MonthlySpent sensor#55

Merged
dvejsada merged 1 commit into
dvejsada:devfrom
eMeF1:feature/monthly-spent-accumulation
Dec 14, 2025
Merged

fix: follow established callback pattern for MonthlySpent sensor#55
dvejsada merged 1 commit into
dvejsada:devfrom
eMeF1:feature/monthly-spent-accumulation

Conversation

@eMeF1
Copy link
Copy Markdown
Contributor

@eMeF1 eMeF1 commented Dec 11, 2025

Summary

Fixes the MonthlySpent sensor not updating by following the established callback pattern used by all other sensors in the codebase.

Problem

After PR #54, the MonthlySpent sensor was not updating because it used a custom async callback handler (_handle_coordinator_update) that didn't work with the synchronous callback system in RohlikAccount.publish_updates().

Solution

  • Remove custom _handle_coordinator_update method
  • Use async_write_ha_state directly as callback (matches all 40+ other sensors)
  • Move processing logic to native_value property (lazy evaluation pattern)
  • Follows the exact same pattern used by all other sensors in the codebase

Changes

  • ✅ Removed async callback handler that was incompatible with sync callback system
  • ✅ Changed callback registration to use async_write_ha_state directly
  • ✅ Moved _check_and_reset_month() and _process_new_orders() calls to native_value property
  • ✅ Updated async_will_remove_from_hass to remove correct callback

Testing

  • ✅ Verified sensor updates correctly after fix
  • ✅ Confirmed orders are processed when sensor value is read
  • ✅ Tested state persistence and order deduplication still works
  • 🔄 Additional real-world testing planned: Will validate with next actual order delivery

Related

Follow-up fix to #54 - addresses callback pattern issue discovered during testing.

- Remove custom _handle_coordinator_update method
- Use async_write_ha_state directly as callback (matches all other sensors)
- Move processing logic to native_value property (lazy evaluation)
- Follows the established pattern used by 40+ other sensors in codebase
@eMeF1
Copy link
Copy Markdown
Contributor Author

eMeF1 commented Dec 12, 2025

@dvejsada, all tested and working as expected.

@dvejsada dvejsada merged commit c7dc064 into dvejsada:dev Dec 14, 2025
2 checks passed
@eMeF1 eMeF1 deleted the feature/monthly-spent-accumulation branch December 16, 2025 06:08
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