Refactor: real mixin, shared event helper, structural tests
Validate / hassfest (push) Failing after 6s
Validate / HACS (push) Failing after 17s
Validate / pytest (push) Failing after 8s

FreshHarvestActions inherited from itself to graft on basket switching, which
is legal Python and a trap. BasketMixin now sits above it and is inherited
normally.

The four control platforms each carried an identical private _fire; it moves to
the base entity as fire_action. Rewriting those call sites mechanically broke
two of them - select fired 'donate' instead of 'change_basket', and button lost
an argument entirely, a TypeError reachable only by pressing it. Both fixed,
and two tests now assert call arity and that no class inherits from itself,
because neither fault is reachable from a unit test.
This commit is contained in:
flan
2026-08-03 20:40:17 +00:00
parent 6ec06ee31a
commit 73a3409353
7 changed files with 171 additions and 168 deletions
+19 -1
View File
@@ -15,7 +15,7 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .api import AccountSnapshot, DeliveryOrder
from .const import DOMAIN
from .const import DOMAIN, EVENT_ACTION
from .coordinator import FreshHarvestCoordinator
Scope = Literal["account", "next_order", "open_order"]
@@ -54,3 +54,21 @@ class FreshHarvestEntity(CoordinatorEntity[FreshHarvestCoordinator]):
def target(self, scope: Scope) -> AccountSnapshot | DeliveryOrder | None:
"""Resolve this entity's scope against the latest snapshot."""
return resolve_scope(self.coordinator.data, scope)
def fire_action(self, action: str, ok: bool, target: str, detail: str) -> None:
"""Announce a write action's outcome so automations can notify on it.
Lives here because all four control platforms need it identically; four
private copies drifted apart the moment one of them gained a field.
"""
self.hass.bus.async_fire(
EVENT_ACTION,
{
"domain": DOMAIN,
"entry_id": self.coordinator.config_entry.entry_id,
"action": action,
"success": ok,
"target": target,
"detail": detail,
},
)