Skip to content

Commit 4f33b9b

Browse files
authored
docs and fixes from testing 7.3.0 together (#1122)
1 parent c3c3b4b commit 4f33b9b

14 files changed

Lines changed: 350 additions & 47 deletions

‎custom_components/taskmate/coord_rewards.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ async def async_add_reward(
101101
expires_at: str | None = None,
102102
refresh: bool = True,
103103
template_id: str = "",
104+
screen_minutes: int = 0,
104105
) -> Reward:
105106
"""Add a new reward. ``refresh=False`` defers the refresh to a batch.
106107
107-
``template_id`` names the 📚 library entry it came from, if any.
108+
``template_id`` names the 📚 library entry it came from, if any;
109+
``screen_minutes`` makes it a screen-time reward.
108110
"""
109111
reward = Reward(
110112
name=name,
@@ -117,6 +119,7 @@ async def async_add_reward(
117119
quantity=quantity,
118120
expires_at=expires_at,
119121
template_id=clean_template_id(template_id),
122+
screen_minutes=max(0, int(screen_minutes or 0)),
120123
)
121124
self.storage.add_reward(reward)
122125
await self.storage.async_save()

‎custom_components/taskmate/coord_setup.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .const import AGE_GROUPS
2323
from .coord_birthdays import normalize_birthday
2424
from .models import clean_template_id
25+
from .setup_catalogue import library_screen_minutes
2526

2627
_LOGGER = logging.getLogger(__name__)
2728

@@ -200,6 +201,11 @@ def resolve(who: str) -> str:
200201
icon=spec.get("icon") or "mdi:gift",
201202
refresh=False,
202203
template_id=spec.get("template_id", ""),
204+
# A library screen-time reward fills the bank only while the
205+
# bank is on; otherwise it stays a reward a parent hands over.
206+
screen_minutes=(
207+
library_screen_minutes(spec.get("template_id", "")) if self.screen_time_enabled() else 0
208+
),
203209
)
204210

205211
await self.async_refresh()

‎custom_components/taskmate/setup_catalogue.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,16 @@ def _top_pick(s: dict) -> dict:
376376
# Starter rewards in three tiers. ``picked`` ones are ticked when the wizard opens.
377377
REWARD_TIERS: tuple[str, ...] = ("small", "saving", "big")
378378
STARTER_REWARDS: list[dict] = [
379-
{"id": "screen_time", "tier": "small", "cost": 15, "icon": "mdi:television-play", "picked": True},
379+
# ``screen_minutes``: what the reward adds to the screen-time bank, when the
380+
# bank is on.
381+
{
382+
"id": "screen_time",
383+
"tier": "small",
384+
"cost": 15,
385+
"icon": "mdi:television-play",
386+
"picked": True,
387+
"screen_minutes": 15,
388+
},
380389
{"id": "pick_pudding", "tier": "small", "cost": 10, "icon": "mdi:cupcake", "picked": False},
381390
{"id": "car_music", "tier": "small", "cost": 10, "icon": "mdi:music", "picked": False},
382391
{"id": "choose_dinner", "tier": "saving", "cost": 40, "icon": "mdi:pizza", "picked": True},
@@ -481,3 +490,11 @@ def library_catalogue() -> dict[str, Any]:
481490
for t in BUILT_IN_TEMPLATES
482491
],
483492
}
493+
494+
495+
def library_screen_minutes(template_id: str) -> int:
496+
"""Minutes a library reward adds to the screen-time bank; 0 for most."""
497+
for r in (*STARTER_REWARDS, *LIBRARY_EXTRA_REWARDS):
498+
if r["id"] == template_id:
499+
return int(r.get("screen_minutes", 0) or 0)
500+
return 0

‎custom_components/taskmate/www/taskmate-kiosk-card.js‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,25 @@ class TaskMateKioskCard extends LitElement {
469469
const all = this._rows(child).filter(r => !(missedMode === "hide" && r.missed));
470470
const counted = all.filter(r => !r.phone && !(missedMode === "dim" && r.missed));
471471
const shown = r => !(hideDone && isDone(r));
472+
// A chore with set times counts once, in either layout, and only once
473+
// every time is done (waiting for a grown-up counts as done).
474+
let done = 0;
475+
let total = 0;
476+
const setTimeChores = new Set();
477+
for (const r of counted) {
478+
if (r.setTime) {
479+
if (setTimeChores.has(r.chore._baseId)) continue;
480+
setTimeChores.add(r.chore._baseId);
481+
total += 1;
482+
if (r.setTime.all.every(e => e.state === "done" || e.state === "pending")) done += 1;
483+
continue;
484+
}
485+
total += 1;
486+
if (isDone(r)) done += 1;
487+
}
472488
return {
473-
done: counted.filter(isDone).length,
474-
total: counted.length,
489+
done,
490+
total,
475491
rows: all.filter(r => !r.phone && shown(r)),
476492
phoneRows: all.filter(r => r.phone && shown(r)),
477493
};
@@ -541,16 +557,23 @@ class TaskMateKioskCard extends LitElement {
541557
// not a parent action: choose_avatar runs the same linked-child check as
542558
// complete_chore.
543559

544-
_headAvatar(child, tone) {
560+
// The season badge wraps only the face: the picker must position against
561+
// .km-head, not against a relatively positioned wrapper round the face.
562+
_headAvatar(child, tone, season) {
545563
const opts = child.avatar_options || [];
546564
const canChange = this.config.allow_avatar_change !== false && opts.filter(o => o.unlocked).length > 1;
547-
if (!canChange) return this._face(child, tone, "head");
565+
const face = html`
566+
<div class="km-face-wrap">
567+
${this._face(child, tone, "head")}
568+
${season ? html`<span class="tm-season-badge" aria-hidden="true">${season.emoji}</span>` : ""}
569+
</div>`;
570+
if (!canChange) return face;
548571
return html`
549572
<div class="km-av">
550573
<button class="km-av-btn" title="${this._t("child.avatar_change")}" aria-label="${this._t("child.avatar_change")}"
551574
aria-expanded="${this._avatarPicker ? "true" : "false"}"
552575
@click=${() => { this._avatarPicker = !this._avatarPicker; }}>
553-
${this._face(child, tone, "head")}
576+
${face}
554577
<span class="km-av-dot"><ha-icon icon="mdi:pencil"></ha-icon></span>
555578
</button>
556579
${this._avatarPicker ? html`
@@ -1589,10 +1612,7 @@ class TaskMateKioskCard extends LitElement {
15891612
return html`
15901613
<div class="km-child" style="--kc:${tone}">
15911614
<div class="km-head" style="${season ? `background:${season.grad}` : ""}">
1592-
<div class="km-face-wrap">
1593-
${this._headAvatar(child, tone)}
1594-
${season ? html`<span class="tm-season-badge" aria-hidden="true">${season.emoji}</span>` : ""}
1595-
</div>
1615+
${this._headAvatar(child, tone, season)}
15961616
<div class="km-grow">
15971617
<div class="km-head-name">${child.name}</div>
15981618
${showPoints && child.level ? html`

‎custom_components/taskmate/www/taskmate-panel.js‎

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,8 @@ class TaskMatePanel extends HTMLElement {
19291929
const chore = c && choreById[c.chore_id];
19301930
const bounty = c && c.bounty_id && (this._state.bounties || []).find(b => b.id === c.bounty_id);
19311931
name = (chore && chore.name) || (bounty && bounty.title) || this._t("panel.activity_deleted_chore");
1932+
const t = chore && c.time_id && (chore.times || []).find(x => x.id === c.time_id);
1933+
if (t) name = `${chore.name} (${t.name || t.start})`;
19321934
} else {
19331935
const c = (this._state.pending_reward_claims || []).find(x => x.id === id);
19341936
const reward = c && rewardById[c.reward_id];
@@ -5303,6 +5305,10 @@ class TaskMatePanel extends HTMLElement {
53035305
if (c.bonus_subtask_id && chore) {
53045306
const sub = (chore.bonus_subtasks || []).find(b => b.id === c.bonus_subtask_id);
53055307
if (sub) { choreName = `${chore.name} › ${sub.name}`; chorePoints = sub.points; }
5308+
} else if (c.time_id && chore) {
5309+
// Set times: name the time, as notifications and the sensor do.
5310+
const t = (chore.times || []).find(x => x.id === c.time_id);
5311+
if (t) { choreName = `${chore.name} (${t.name || t.start})`; chorePoints = Number(t.points) || 0; }
53065312
} else if (chore && chore.task_type === "timed" && (c.timed_duration_seconds || 0) > 0) {
53075313
// Timed chores accrue points by elapsed-time rate, so the actual
53085314
// earned points can be lower than chore.points. Mirror sensor.py.
@@ -5854,7 +5860,7 @@ class TaskMatePanel extends HTMLElement {
58545860
</div>
58555861
<div class="tm-setting-row">
58565862
<div class="tm-setting-label">${this._t("panel.screen_time_jar_opens")}<small>${this._t("panel.screen_time_jar_opens_hint")}</small></div>
5857-
<div class="tm-st-opens">
5863+
<div class="tm-scr-opens">
58585864
<select class="tm-select" data-setting="screen_time_jar_open_day">
58595865
${[0, 1, 2, 3, 4, 5, 6].map(d => `<option value="${d}" ${d === openDay ? "selected" : ""}>${this._esc(this._weekdayName(d))}</option>`).join("")}
58605866
</select>
@@ -5866,13 +5872,13 @@ class TaskMatePanel extends HTMLElement {
58665872
const field = `_list:screen_time_devices:${c.id}`;
58675873
const jar = Number(row.jar) || 0;
58685874
return `
5869-
<div class="tm-setting-row tm-setting-top tm-st-kid">
5870-
<div class="tm-setting-label"><span class="tm-st-name">${this._childAvatar(c)} ${this._esc(c.name)}</span></div>
5875+
<div class="tm-setting-row tm-setting-top tm-scr-kid">
5876+
<div class="tm-setting-label"><span class="tm-scr-name">${this._childAvatar(c)} ${this._esc(c.name)}</span></div>
58715877
<div class="tm-list-body">
5872-
<div class="tm-st-head">
5873-
<span class="tm-st-balance ${row.active ? "live" : ""}">📺 ${this._esc(this._screenMinutes(row.minutes))}${row.active ? ` · ${this._t("panel.screen_time_watching")}` : ""}${Number(row.allowance) > 0 ? ` · ${this._t("panel.screen_time_allowance_today", { time: this._esc(this._screenMinutes(row.allowance)) })}` : ""}</span>
5874-
${s.screen_time_jar_enabled || jar ? `<span class="tm-st-jar">🫙 ${this._esc(this._screenMinutes(jar))}${jar ? ` <button type="button" class="tm-btn tm-btn-sm" data-act="st-jar-open" data-child="${this._esc(c.id)}">${this._t("panel.screen_time_jar_open_now")}</button>` : ""}</span>` : ""}
5875-
<span class="tm-st-adjust">
5878+
<div class="tm-scr-head">
5879+
<span class="tm-scr-balance ${row.active ? "live" : ""}">📺 ${this._esc(this._screenMinutes(row.minutes))}${row.active ? ` · ${this._t("panel.screen_time_watching")}` : ""}${Number(row.allowance) > 0 ? ` · ${this._t("panel.screen_time_allowance_today", { time: this._esc(this._screenMinutes(row.allowance)) })}` : ""}</span>
5880+
${s.screen_time_jar_enabled || jar ? `<span class="tm-scr-jar">🫙 ${this._esc(this._screenMinutes(jar))}${jar ? ` <button type="button" class="tm-btn tm-btn-sm" data-act="st-jar-open" data-child="${this._esc(c.id)}">${this._t("panel.screen_time_jar_open_now")}</button>` : ""}</span>` : ""}
5881+
<span class="tm-scr-adjust">
58765882
${[-15, 15, 30].map(m => `<button type="button" class="tm-btn tm-btn-sm" data-act="st-adjust" data-child="${this._esc(c.id)}" data-minutes="${m}">${m > 0 ? "+" : "−"}${Math.abs(m)}</button>`).join("")}
58775883
</span>
58785884
</div>
@@ -5965,7 +5971,7 @@ class TaskMatePanel extends HTMLElement {
59655971
</div>
59665972
${kids.length < 2 ? `<span class="tm-field-hint">${this._t("panel.sibling_check_need_two")}</span>` : kids.map(checker => `
59675973
<div class="tm-setting-row tm-setting-top">
5968-
<div class="tm-setting-label"><span class="tm-st-name">${this._childAvatar(checker)} ${this._t("panel.sibling_check_can_check", { name: this._esc(checker.name) })}</span></div>
5974+
<div class="tm-setting-label"><span class="tm-scr-name">${this._childAvatar(checker)} ${this._t("panel.sibling_check_can_check", { name: this._esc(checker.name) })}</span></div>
59695975
<div class="tm-chip-row">
59705976
${kids.filter(c => c.id !== checker.id).map(c => {
59715977
const on = Array.isArray(pairs[checker.id]) && pairs[checker.id].includes(c.id);
@@ -8924,8 +8930,12 @@ class TaskMatePanel extends HTMLElement {
89248930
.tm-lib-more small { display: block; color: var(--tm-text-muted); margin-top: 2px; }
89258931
.tm-lib-more .tm-btn ha-icon { --mdc-icon-size: 16px; }
89268932
.tm-toolbar .tm-btn ha-icon { --mdc-icon-size: 16px; vertical-align: -3px; margin-inline-end: 4px; }
8933+
/* Full screen like every other dialog at this width, so it covers the
8934+
phone's bottom bar instead of leaving it dimmed underneath. */
8935+
@media (max-width: 900px) {
8936+
.tm-dialog.tm-lib { height: 100vh; }
8937+
}
89278938
@media (max-width: 760px) {
8928-
.tm-dialog.tm-lib { height: calc(100vh - 40px); }
89298939
.tm-lib-main { flex-direction: column; }
89308940
.tm-lib-rail { width: auto; display: flex; gap: 4px; overflow-x: auto; border-inline-end: 0; border-bottom: 1px solid var(--tm-border-soft); flex: none; }
89318941
.tm-lib-cat { width: auto; white-space: nowrap; }
@@ -16786,13 +16796,13 @@ class TaskMatePanel extends HTMLElement {
1678616796
.tm-list-body .tm-allowlist { margin-top: 0; }
1678716797
.tm-list-body .tm-allow-chip { font-family: inherit; }
1678816798
.tm-list-body .tm-field { margin: 0; }
16789-
.tm-st-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
16790-
.tm-st-name { font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
16791-
.tm-st-balance { background: #e9f6fb; color: #0f4a60; border-radius: 999px; padding: 3px 10px; font-weight: 600; font-size: .85rem; }
16792-
.tm-st-balance.live { background: #fdecec; color: #7a1f1f; }
16793-
.tm-st-adjust { margin-inline-start: auto; display: inline-flex; gap: 4px; }
16794-
.tm-st-jar { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .85rem; }
16795-
.tm-st-opens { display: flex; gap: 8px; flex-wrap: wrap; }
16799+
.tm-scr-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
16800+
.tm-scr-name { font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
16801+
.tm-scr-balance { background: #e9f6fb; color: #0f4a60; border-radius: 999px; padding: 3px 10px; font-weight: 600; font-size: .85rem; }
16802+
.tm-scr-balance.live { background: #fdecec; color: #7a1f1f; }
16803+
.tm-scr-adjust { margin-inline-start: auto; display: inline-flex; gap: 4px; }
16804+
.tm-scr-jar { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .85rem; }
16805+
.tm-scr-opens { display: flex; gap: 8px; flex-wrap: wrap; }
1679616806
.tm-reward-screen { margin-top: 14px; }
1679716807
.tm-bin-preview { display: flex; flex-direction: column; align-items: flex-start; }
1679816808
.tm-bin-preview ul { margin: 8px 0 0; padding-inline-start: 18px; line-height: 1.6; }
@@ -16923,7 +16933,17 @@ class TaskMatePanel extends HTMLElement {
1692316933
.tm-st-d.st-pending { background: var(--tm-warning); border-color: var(--tm-warning); }
1692416934
.tm-st-d.st-missed { background: var(--tm-danger-soft, #fde3e3); border-color: var(--tm-danger, #c4282e); }
1692516935
.tm-st-d.st-now { border-color: var(--tm-accent); }
16926-
@media (max-width: 560px) { .tm-st-row { grid-template-columns: minmax(0, 1fr) minmax(104px, 1fr) minmax(104px, 1fr) 52px 28px; } }
16936+
/* Phone: name, points and remove on the first line; From and Until
16937+
share the second line, half each, wide enough for a 12-hour "07:00 AM".
16938+
Every cell has a fixed place, so the layout can't reflow wrongly. */
16939+
@media (max-width: 560px) {
16940+
.tm-st-row { grid-template-columns: calc(50% - 3px) minmax(0, 1fr) 56px 32px; }
16941+
.tm-st-row > :nth-child(1) { grid-area: 1 / 1 / 2 / 3; }
16942+
.tm-st-row > :nth-child(4) { grid-area: 1 / 3 / 2 / 4; }
16943+
.tm-st-row > :nth-child(5) { grid-area: 1 / 4 / 2 / 5; }
16944+
.tm-st-row > :nth-child(2) { grid-area: 2 / 1 / 3 / 2; }
16945+
.tm-st-row > :nth-child(3) { grid-area: 2 / 2 / 3 / 5; }
16946+
}
1692716947

1692816948
.tm-check-row {
1692916949
display: flex; align-items: flex-start; gap: 14px;

‎mkdocs.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ nav:
5858
- "Chores":
5959
- "Chores": "Chores.md"
6060
- "Chore Scheduling": "Chore-Scheduling.md"
61+
- "Chores at Set Times": "Set-Times.md"
62+
- "Chore & Reward Library": "Chore-Library.md"
6163
- "Mandatory Chores": "Mandatory-Chores.md"
6264
- "Difficulty Tiers": "Difficulty-Tiers.md"
6365
- "Timed Tasks": "Timed-Tasks.md"

‎tests/frontend/taskmate-kiosk-card.test.cjs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,3 +791,35 @@ test("the editor offers both list filters, 'show' by default, and stores only a
791791
const back = editor.dispatched.at(-1).detail.config;
792792
assert.equal("completed_mode" in back || "elapsed_time_mode" in back, false);
793793
});
794+
795+
// ── set times: the ring counts the chore once ─────────────────────────────
796+
797+
const SET_TIME_CHORES = [
798+
chore("dishes"),
799+
chore("hands", { times: [{ id: "am", name: "Breakfast", start: "07:00", end: "09:00", points: 2 }, { id: "pm", name: "Dinner", start: "17:00", end: "19:00", points: 2 }] }),
800+
];
801+
802+
function withSetTimes(layout, states, fn) {
803+
const before = cardWindow.__taskmate_set_times;
804+
cardWindow.__taskmate_set_times = {
805+
states: (c) => c.times.map((t, i) => ({ time: t, state: states[i], opens: t.start })),
806+
focus: (entries) => entries.find((e) => e.state === "now") || entries[0],
807+
layout: () => layout,
808+
nowMinutes: () => 0,
809+
};
810+
return fn().finally(() => { cardWindow.__taskmate_set_times = before; });
811+
}
812+
813+
for (const layout of ["rows", "pills"]) {
814+
test(`set times count once in the done ring (${layout})`, () => withSetTimes(layout, ["done", "now"], async () => {
815+
const card = await childView({ chores: SET_TIME_CHORES, status: phoneStatus(["dishes", "hands"]) });
816+
const { done, total } = card._progress(card._entry("vaiha").child);
817+
assert.deepEqual([done, total], [0, 2], "one of two times done is not the chore done");
818+
}));
819+
820+
test(`set times count as done once every time is done or waiting (${layout})`, () => withSetTimes(layout, ["done", "pending"], async () => {
821+
const card = await childView({ chores: SET_TIME_CHORES, status: phoneStatus(["dishes", "hands"]) });
822+
const { done, total } = card._progress(card._entry("vaiha").child);
823+
assert.deepEqual([done, total], [1, 2]);
824+
}));
825+
}

‎tests/test_library.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ def test_library_add_keeps_the_template_ids_with_one_refresh(coord):
273273
coord.async_refresh.assert_awaited_once()
274274

275275

276+
@pytest.mark.parametrize(("bank_on", "minutes"), [(True, 15), (False, 0)])
277+
def test_library_screen_time_reward_fills_the_bank_only_while_it_is_on(coord, bank_on, minutes):
278+
coord.storage.set_setting("screen_time_enabled", bank_on)
279+
run(
280+
coord.async_apply_setup_wizard(
281+
rewards=[
282+
{"name": "15 min extra screen time", "cost": 15, "template_id": "screen_time"},
283+
{"name": "Sleepover", "cost": 250, "template_id": "sleepover"},
284+
],
285+
)
286+
)
287+
rewards = {r.template_id: r for r in coord.storage.get_rewards()}
288+
assert rewards["screen_time"].screen_minutes == minutes
289+
assert rewards["sleepover"].screen_minutes == 0
290+
291+
276292
def test_already_added_by_template_even_after_a_rename(coord):
277293
coord.storage.add_chore(Chore(name="Bed!", template_id="make_bed"))
278294
coord.storage.add_reward(Reward(name="Big sleepover", cost=300, template_id="sleepover"))

0 commit comments

Comments
 (0)