Expose every order component as its own entity and prepare for release
Each cost line is now an entity rather than an attribute: subtotal, box price, add-ons, tax and delivery fee, plus a total and free-delivery-remaining for the open order, a delivery-day sensor, and a binary sensor that turns off at the cutoff. Entities share a base class and declare a scope, so a description states only the field it reads. Also parses the driver tip, Bounty savings and the free-delivery threshold. The threshold is carried across orders because the progress bar only renders on carts that have not met it. Adds LICENSE, hacs.json, a CI workflow, a pre-publish audit script, and a test that cross-checks every entity's translation_key against both translation files. Manifest URLs now point at GitHub rather than a private forge.
This commit is contained in:
Vendored
+26
-15
@@ -6,34 +6,43 @@
|
||||
<html>
|
||||
<body>
|
||||
<div class='nav-main-cart'>
|
||||
<div class='cart-selector-options-wrapper' data-cart-select='2772590'>
|
||||
<div data-cart-select='2772590'>Tue 8/4</div>
|
||||
<div class='cart-selector-options-wrapper' data-cart-select='1000001'>
|
||||
<div data-cart-select='1000001'>Tue 8/4</div>
|
||||
</div>
|
||||
<div class='cart-selector-options-wrapper' data-cart-select='2778336'>
|
||||
<div data-cart-select='2778336'>Tue 8/11</div>
|
||||
<div class='cart-selector-options-wrapper' data-cart-select='1000002'>
|
||||
<div data-cart-select='1000002'>Tue 8/11</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Open cart: still customizable, contents not yet assigned. -->
|
||||
<div class='cart-contents' data-cart-select='2778336'>
|
||||
<div class='cart-contents' data-cart-select='1000002'>
|
||||
<div class='cart-basket-columns'>
|
||||
<h6>Georgia Grown Small Box</h6>
|
||||
<div class='item-total'>$33.00</div>
|
||||
<div class='cart-customize-wrapper'><div>Shop tomorrow</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='OrderTotals-2778336'>
|
||||
<!-- The free-delivery bar is only rendered on carts BELOW the threshold, which
|
||||
is why the threshold is read once and applied to every order. -->
|
||||
<div id='DeliveryProgressBar-1000002' class='basket-progress'>
|
||||
<div class='progress-message'>You're so close! $37.00 away from free delivery!</div>
|
||||
<div class='progress'>
|
||||
<progress id='DeliveryProgress-1000002' class='progress-free-delivery' value='33' max='70.00'></progress>
|
||||
</div>
|
||||
</div>
|
||||
<div id='OrderTotals-1000002'>
|
||||
<div class='cart-summary'>
|
||||
<span class='summary-item label'>Subtotal</span><span class='summary-item value'>$33.00</span>
|
||||
<span class='summary-item label'>Driver Tip</span><span class='summary-item value'>Add Tip</span>
|
||||
<span class='summary-item label'>Tax</span><span class='summary-item value'>$0.99</span>
|
||||
<span class='summary-item label'>Delivery</span><span class='summary-item value'>$5.99</span>
|
||||
<span class='summary-item label demi-bold total'>Order Total <span class='order-total-see-details'>See Details</span></span><span class='summary-item value'>$39.98</span>
|
||||
<span class='summary-item label'>Potential Bounty Savings</span><span class='summary-item value'>$5.99</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Locked cart: past its cutoff, arriving next, contents final. -->
|
||||
<div class='cart-contents cart-contents-skipped' data-cart-select='2772590'>
|
||||
<div class='cart-contents cart-contents-skipped' data-cart-select='1000001'>
|
||||
<div class='cart-basket-columns'>
|
||||
<h6>Georgia Grown Small Box</h6>
|
||||
<div class='item-total'>$33.00</div>
|
||||
@@ -55,7 +64,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='DODRow-3' class='cart-item qv-button shop-item-cursor' data-qvid='8961'>
|
||||
<div id='DODRow-3' class='cart-item qv-button shop-item-cursor' data-qvid='5001'>
|
||||
<img class='cart-item-img' src='https://cdn.freshharvest.com/x.jpg' alt='Black Mission Figs' />
|
||||
<div class='item-details'>
|
||||
<span class='item-name'><div>Black Mission Figs</div></span>
|
||||
@@ -64,14 +73,14 @@
|
||||
<div class='item-order-wrapper'>
|
||||
<div class='item-order item-order-disabled'>
|
||||
<div class='btn-round item-order-remove qv-ignore'></div>
|
||||
<span class='item-order-quantity qv-ignore' data-item-quantity='8961'>1</span>
|
||||
<span class='item-order-quantity qv-ignore' data-item-quantity='5001'>1</span>
|
||||
<div class='btn-round item-order-add qv-ignore'></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Multi-quantity add-on: item-total is the EXTENDED price, 4 x $4.49. -->
|
||||
<div id='DODRow-4' class='cart-item qv-button shop-item-cursor' data-qvid='9012'>
|
||||
<div id='DODRow-4' class='cart-item qv-button shop-item-cursor' data-qvid='5002'>
|
||||
<img class='cart-item-img' src='https://cdn.freshharvest.com/y.jpg' alt='Complete Recovery Smoothie' />
|
||||
<div class='item-details'>
|
||||
<span class='item-name'><div>Complete Recovery Smoothie</div></span>
|
||||
@@ -80,13 +89,13 @@
|
||||
<div class='item-order-wrapper'>
|
||||
<div class='item-order item-order-disabled'>
|
||||
<div class='btn-round item-order-remove qv-ignore'></div>
|
||||
<span class='item-order-quantity qv-ignore' data-item-quantity='9012'>4</span>
|
||||
<span class='item-order-quantity qv-ignore' data-item-quantity='5002'>4</span>
|
||||
<div class='btn-round item-order-add qv-ignore'></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='DODRow-5' class='cart-item qv-button shop-item-cursor' data-qvid='9105'>
|
||||
<div id='DODRow-5' class='cart-item qv-button shop-item-cursor' data-qvid='5003'>
|
||||
<img class='cart-item-img' src='https://cdn.freshharvest.com/z.jpg' alt='Organic Fruit Punch Juice Boxes' />
|
||||
<div class='item-details'>
|
||||
<span class='item-name'><div>Organic Fruit Punch Juice Boxes</div></span>
|
||||
@@ -95,21 +104,23 @@
|
||||
<div class='item-order-wrapper'>
|
||||
<div class='item-order item-order-disabled'>
|
||||
<div class='btn-round item-order-remove qv-ignore'></div>
|
||||
<span class='item-order-quantity qv-ignore' data-item-quantity='9105'>2</span>
|
||||
<span class='item-order-quantity qv-ignore' data-item-quantity='5003'>2</span>
|
||||
<div class='btn-round item-order-add qv-ignore'></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='OrderTotals-2772590'>
|
||||
<div id='OrderTotals-1000001'>
|
||||
<div class='cart-summary'>
|
||||
<!-- Self-consistent: box 33.00 + add-ons 39.93 = 72.93 subtotal, which is
|
||||
over the $70 free-delivery threshold, hence the $0.00 fee. -->
|
||||
<span class='summary-item label'>Subtotal</span><span class='summary-item value'>$72.93</span>
|
||||
<span class='summary-item label'>Driver Tip</span><span class='summary-item value'>$4.00</span>
|
||||
<span class='summary-item label'>Tax</span><span class='summary-item value'>$2.19</span>
|
||||
<span class='summary-item label'>Delivery</span><span class='summary-item value'>$0.00</span>
|
||||
<span class='summary-item label demi-bold total'>Order Total <span>See Details</span></span><span class='summary-item value'>$75.12</span>
|
||||
<span class='summary-item label demi-bold total'>Order Total <span>See Details</span></span><span class='summary-item value'>$79.12</span>
|
||||
<span class='summary-item label'>Potential Bounty Savings</span><span class='summary-item value'>$5.69</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+25
-3
@@ -62,7 +62,7 @@ def test_next_order_is_the_locked_one(snapshot):
|
||||
class `cart-contents-skipped`, which does not mean the user skipped it.
|
||||
"""
|
||||
order = snapshot.next_order
|
||||
assert order.delivery_id == "2772590"
|
||||
assert order.delivery_id == "1000001"
|
||||
assert order.delivery_date == date(2026, 8, 4)
|
||||
assert order.is_open is False
|
||||
|
||||
@@ -71,7 +71,9 @@ def test_next_order_totals_and_contents(snapshot):
|
||||
order = snapshot.next_order
|
||||
assert order.box_name == "Georgia Grown Small Box"
|
||||
assert (order.subtotal, order.tax, order.delivery_fee) == (72.93, 2.19, 0.0)
|
||||
assert order.total == 75.12
|
||||
assert order.driver_tip == 4.00
|
||||
assert order.bounty_savings == 5.69
|
||||
assert order.total == 79.12
|
||||
assert [(i.quantity, i.name, i.unit) for i in order.items] == [
|
||||
(1, "Bolero Carrots", ".5 lb"),
|
||||
(2, "Georgia Peaches", "6 count"),
|
||||
@@ -98,13 +100,33 @@ def test_addons_total_is_zero_when_nothing_is_added(snapshot):
|
||||
|
||||
def test_open_order(snapshot):
|
||||
order = snapshot.open_order
|
||||
assert order.delivery_id == "2778336"
|
||||
assert order.delivery_id == "1000002"
|
||||
assert order.delivery_date == date(2026, 8, 11)
|
||||
assert order.is_open is True
|
||||
assert order.shop_window == "Shop tomorrow"
|
||||
assert order.total == 39.98
|
||||
|
||||
|
||||
def test_free_delivery_threshold_applies_to_every_order(snapshot):
|
||||
"""The bar renders only on carts below the threshold, so it must carry over."""
|
||||
assert snapshot.free_delivery_threshold == 70.0
|
||||
# This cart has the bar: $70.00 - $33.00 matches the portal's own message.
|
||||
assert snapshot.open_order.free_delivery_remaining == 37.0
|
||||
# This one does not, and must still resolve rather than staying unknown.
|
||||
assert snapshot.next_order.free_delivery_remaining == 0.0
|
||||
|
||||
|
||||
def test_free_delivery_remaining_agrees_with_the_fee_charged(snapshot):
|
||||
"""Nothing left to spend must mean nothing was charged for delivery."""
|
||||
for order in snapshot.orders:
|
||||
assert (order.free_delivery_remaining == 0.0) == (order.delivery_fee == 0.0)
|
||||
|
||||
|
||||
def test_unset_driver_tip_is_none_not_zero(snapshot):
|
||||
"""An untipped order reads 'Add Tip'; that is unknown, not a $0.00 tip."""
|
||||
assert snapshot.open_order.driver_tip is None
|
||||
|
||||
|
||||
def test_driver_tip_placeholder_is_not_money(snapshot):
|
||||
"""'Add Tip' sits in a value slot but is not an amount."""
|
||||
assert api._money("Add Tip") is None
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"""Every entity's translation_key must exist, and nothing may be orphaned.
|
||||
|
||||
These parse the platform sources with `ast` rather than importing them, so the
|
||||
suite still runs without Home Assistant installed.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
COMPONENT = Path(__file__).parent.parent / "custom_components" / "freshharvest"
|
||||
PLATFORMS = {"sensor": "sensor.py", "binary_sensor": "binary_sensor.py"}
|
||||
|
||||
|
||||
def declared_keys(filename: str) -> set[str]:
|
||||
"""Collect every `translation_key="..."` literal in a module."""
|
||||
tree = ast.parse((COMPONENT / filename).read_text(encoding="utf-8"))
|
||||
return {
|
||||
node.value.value
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.keyword)
|
||||
and node.arg == "translation_key"
|
||||
and isinstance(node.value, ast.Constant)
|
||||
and isinstance(node.value.value, str)
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="strings")
|
||||
def strings_fixture() -> dict:
|
||||
return json.loads((COMPONENT / "strings.json").read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def test_en_matches_strings(strings):
|
||||
"""Custom integrations read translations/en.json; it must not drift."""
|
||||
english = json.loads(
|
||||
(COMPONENT / "translations" / "en.json").read_text(encoding="utf-8")
|
||||
)
|
||||
assert english == strings
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform,filename", PLATFORMS.items())
|
||||
def test_every_entity_has_a_name(strings, platform, filename):
|
||||
missing = declared_keys(filename) - set(strings["entity"][platform])
|
||||
assert not missing, f"{platform} keys with no translation: {sorted(missing)}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform,filename", PLATFORMS.items())
|
||||
def test_no_orphaned_translations(strings, platform, filename):
|
||||
orphans = set(strings["entity"][platform]) - declared_keys(filename)
|
||||
assert not orphans, f"{platform} translations with no entity: {sorted(orphans)}"
|
||||
|
||||
|
||||
def test_manifest_is_well_formed():
|
||||
manifest = json.loads((COMPONENT / "manifest.json").read_text(encoding="utf-8"))
|
||||
for key in ("domain", "name", "version", "documentation", "issue_tracker"):
|
||||
assert manifest.get(key), f"manifest missing {key}"
|
||||
assert manifest["domain"] == "freshharvest"
|
||||
# A private forge URL would be unreachable for anyone installing this.
|
||||
for key in ("documentation", "issue_tracker"):
|
||||
assert manifest[key].startswith("https://github.com/"), (
|
||||
f"{key} must be a public URL, got {manifest[key]}"
|
||||
)
|
||||
Reference in New Issue
Block a user