Skip to content

Refactor version retrieval to async method#8

Closed
tempus2016 wants to merge 15 commits intovinnybad:masterfrom
tempus2016:master
Closed

Refactor version retrieval to async method#8
tempus2016 wants to merge 15 commits intovinnybad:masterfrom
tempus2016:master

Conversation

@tempus2016
Copy link
Copy Markdown

Prevent other integration resources from being removed.

Prevent other integration resources from being removed.
…nd coordinator improvements

1. Safe Lovelace resource registration (prevents resource wipe on restart)
Previously async_register_cards ran on every HA restart and called resources.async_create_item against the Lovelace storage collection. Under certain timing conditions during startup this could corrupt or wipe all Lovelace resources including those from other integrations.
Changed to a one-time registration pattern:

On first install, resources are registered and resources_registered: True is saved to the config entry data
On every subsequent restart, registration is skipped entirely — HA never touches Lovelace resources again
Detected via entry.data.get("resources_registered", False)


2. Coordinator shutdown on unload
async_unload_entry now calls coordinator.async_shutdown() before unloading platforms. This cleans up the midnight streak check listener and daily history prune listener registered in coordinator.async_initialize(), preventing listener leaks when the integration is reloaded.

3. New service: reject_reward
Added handle_reject_reward service handler and registered SERVICE_REJECT_REWARD. This completes the reward approval flow — parents can now reject a pending reward claim without deducting points (since points are no longer deducted at claim time, only at approval).
Added to _async_unregister_services to ensure clean unload.

4. New service: preview_sound
Added handle_preview_sound service handler and registered SERVICE_PREVIEW_SOUND. Fires a choremander_preview_sound HA bus event that the config-sounds JS module listens for, allowing parents to preview chore completion sounds from Developer Tools → Actions.
Added ATTR_SOUND and EVENT_PREVIEW_SOUND to imports from const.

5. Updated imports
Added to imports from .const:

ATTR_SOUND — for the preview_sound service
EVENT_PREVIEW_SOUND — for the preview_sound service
SERVICE_REJECT_REWARD — for the new reject_reward service
SERVICE_PREVIEW_SOUND — for the new preview_sound service

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. Scheduled midnight streak check
Added async_track_time_change listener firing at 00:00:05 daily. Checks each child's last_completion_date against yesterday — if they missed a day, behaviour depends on streak_reset_mode setting: reset sets current_streak to 0, pause sets streak_paused = True preserving the streak value until the next completion. Listener stored in _unsub_midnight and cleaned up in async_shutdown.

2. Scheduled daily history pruning
Added second async_track_time_change listener at 00:01:00 daily calling async_prune_history. Reads history_days setting (default 90) from storage. Keeps all pending (unapproved) completions regardless of age. Stored in _unsub_prune, cleaned up in async_shutdown.

3. async_shutdown method
New method cancels both scheduled listeners. Called from __init__.py async_unload_entry to prevent listener leaks on reload.

4. Streak pause mode in _award_points
_award_points now reads streak_reset_mode and streak_paused flag. In pause mode, when a child resumes completing chores after a gap their streak continues from where it was rather than resetting to 1. Removed the inline from datetime import — moved date to top-level imports.

5. Reward approval flow overhaul
async_claim_reward — removed immediate point deduction. Now only creates a RewardClaim with approved=False. Points are reserved but not deducted, mirroring the chore approval pattern
async_approve_reward — now deducts points on approval. Validates the child still has sufficient points at approval time. Raises ValueError if not
async_reject_reward — simplified. Since points were never deducted, rejection just deletes the claim record. Removed the refund logic entirely

6. async_prune_history method
New public method accepting a days parameter. Filters completions older than the cutoff, keeping all pending completions regardless of age. Logs how many were pruned.

7. async_set_setting method
New method for storing arbitrary key/value settings (e.g. streak_reset_mode, history_days) via storage.set_setting.

8. Settings exposed in coordinator data
Added "settings": self.storage._data.get("settings", {}) to _async_update_data so the sensor can read settings like streak_reset_mode and expose them as sensor attributes.

9. CALC_COSTS warnings → debug
Four _LOGGER.warning("CALC_COSTS...") calls changed to _LOGGER.debug. These fired every 30 seconds and polluted the HA logs with non-error information.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. Child.last_completion_date
New str | None field storing ISO date string of the child's most recent chore completion. Used by the coordinator's midnight streak check to determine if a day was missed. Included in from_dict and to_dict.

2. Child.streak_paused
New bool field (default False). Set to True by the midnight streak check when streak_reset_mode is pause and the child missed a day. Cleared to False when the child next completes a chore. Included in from_dict and to_dict.

3. PointsTransaction dataclass
New model representing a manual points adjustment (add or remove). Fields: child_id, points (positive = added, negative = removed), reason, created_at, id. Includes from_dict and to_dict. Used to build the activity feed history of manual point changes.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. points_transactions in default data
Added "points_transactions": [] to the default storage structure created for new installs.

2. get_points_transactions / add_points_transaction
New CRUD methods for PointsTransaction records. add_points_transaction caps the list at 200 entries to prevent unbounded storage growth.

3. get_setting / set_setting
New generic key/value settings store backed by a settings dict in storage. Used for streak_reset_mode and history_days. Avoids adding new top-level storage fields for every new configuration option.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. due_days and requires_approval in chores list
Both fields now included in the chores array exposed in sensor attributes, allowing frontend cards to filter chores by scheduled days and show approval requirements.

2. today_day_of_week attribute
New top-level attribute (e.g. "wednesday") set from dt_util.now() in the HA timezone. Used by the child card for due_days filtering without requiring client-side day calculation.

3. streak_reset_mode attribute
New top-level attribute exposing the current global streak reset setting so frontend cards can read it without needing a separate API call.

4. Extended children array
Each child now includes: current_streak, best_streak, total_points_earned, total_chores_completed, avatar, last_completion_date, streak_paused, committed_points. committed_points is the total points reserved by pending reward claims — used by the rewards card to prevent claiming when points are already reserved.

5. pending_reward_claims attribute
New attribute exposing the full list of pending (unapproved) reward claims, enriched with child_name, child_avatar, reward_name, reward_icon, and calculated cost per child. Used by the parent dashboard Claims tab.

6. recent_completions increased to 200
Was capped at 50, now 200 to support longer activity history in the graph and activity cards.

7. recent_transactions refactored
Previously only showed manual point adjustments. Now merged with reward claim events via _build_recent_transactions helper. Reward claims appear as reward_claimed (pending) or reward_approved events with points shown as negative (spent). Capped at 50 combined events.

8. _build_recent_transactions helper
New method building the unified activity feed from both points_transactions and reward_claims. Sorts all events newest-first and caps at 50.

9. _build_pending_reward_claims helper
New method building the enriched pending reward claims list. Handles cost calculation per child using calculate_dynamic_reward_costs, falling back to static cost on error.

10. Duplicate override_point_value key removed
Fixed a duplicate dict key in the rewards list that could cause silent data loss.

11. committed_points_by_child calculation
New calculation alongside pending_points_by_child that totals the points reserved by pending reward claims per child.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. SERVICE_REJECT_REWARD
New constant "reject_reward" for the reward rejection service.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. reject_reward service
New service definition documenting the claim_id field for rejecting a pending reward claim.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. Settings step — streak_reset_mode
New field label and description for the streak reset mode selector in the integration settings.

2. Settings step — history_days
New field label and description for the history retention days number input.

3. reject_reward service
New service entry with name, description, and claim_id field documentation.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
1. Settings step — streak_reset_mode
New field label and description for the streak reset mode selector in the integration settings.

2. Settings step — history_days
New field label and description for the history retention days number input.

3. reject_reward service
New service entry with name, description, and claim_id field documentation.

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
Header restyled to match overview/weekly/streak card pattern — dark navy gradient, compact avatar circle, points pill
Dark mode — all hardcoded white/grey colours replaced with CSS variables (--card-background-color, --primary-text-color, --divider-color, color-mix() for chore card tints)
Daily reset countdown — shows time to midnight beside "Today's Chores" heading, turns orange under 1 hour, configurable via editor toggle
due_days filtering — chores with due_days set can be hidden, dimmed, or shown normally based on editor setting. Reads today_day_of_week from sensor
Streak reset mode removed from card editor — moved to global integration settings
Editor restyled — uses ha-textfield for entity, native <select> for dropdowns, proper HA-style checkbox rows
Responsive breakpoints rewritten — five breakpoints from ≤380px to ≥1024px
Avatar reads from children array — no longer does a secondary hass.states lookup
Debug console logs removed — all console.debug and console.log calls stripped

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>

Claim button added — appears on each reward row when child_id is configured in the editor, calls claim_reward service
Pending approval state — after claiming, reward shows orange "Awaiting parent approval" label and claim button is hidden
canAfford uses available_points — deducts committed_points (points reserved by pending claims) from child.points before checking affordability, preventing double-claiming
_loading state — prevents double-taps on claim button

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
Editor updated — ha-combo-box replaced with native <select> for child dropdown

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
choremander-overview-card.js — parent at-a-glance showing all children's today progress, points, pending approvals chip, footer totals
choremander-activity-card.js — scrollable activity feed showing chore completions, manual point adjustments, and reward claim events (pending and approved). Filterable by child
choremander-streak-card.js — per-child streak display with dot history, current/best streak, achievement badges
choremander-weekly-card.js — Mon–Sun week view with bar chart, headline stats, per-child breakdown. All stats filtered to approved completions only
choremander-graph-card.js — canvas-based line graph tracking daily or cumulative points over a configurable date range. Supports multi-child with colour-coded lines. Hover/touch tooltip
choremander-reward-progress-card.js — full-screen motivational reward progress display with animated progress bar. Supports jackpot and regular rewards. Shows "Ready to claim!" when affordable
choremander-leaderboard-card.js — ranks children by all-time points, current streak, or this week's points. Top 3 get gold/silver/bronze. Solo mode shows personal bests for single-child households
choremander-parent-dashboard-card.js — unified parent view with four tabs: Overview (child progress), Approvals (chore approvals with inline ✓/✗), Claims (reward claims with approve/reject), Points (quick +/- buttons per child)

Signed-off-by: tempus2016 <40920327+tempus2016@users.noreply.github.com>
@tempus2016 tempus2016 closed this by deleting the head repository Mar 20, 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.

1 participant