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
+2 -11
View File
@@ -13,7 +13,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import FreshHarvestConfigEntry
from .api import FreshHarvestError
from .const import DOMAIN, EVENT_ACTION
from .coordinator import FreshHarvestCoordinator
from .entity import FreshHarvestEntity
@@ -42,7 +41,6 @@ class FreshHarvestDonate(FreshHarvestEntity, ButtonEntity):
self, coordinator: FreshHarvestCoordinator, entry: FreshHarvestConfigEntry
) -> None:
super().__init__(coordinator, entry, DESCRIPTION.key)
self._entry = entry
@property
def available(self) -> bool:
@@ -53,15 +51,8 @@ class FreshHarvestDonate(FreshHarvestEntity, ButtonEntity):
try:
result = await self.coordinator.actions.async_donate(dry_run=False)
except FreshHarvestError as err:
self._fire(False, str(err))
self.fire_action("donate", False, "open order", str(err))
raise HomeAssistantError(f"could not donate: {err}") from err
self._fire(True, result.detail)
self.fire_action("donate", True, "open order", result.detail)
await self.coordinator.async_request_refresh()
def _fire(self, ok: bool, detail: str) -> None:
self.hass.bus.async_fire(
EVENT_ACTION,
{"domain": DOMAIN, "entry_id": self._entry.entry_id,
"action": "donate", "success": ok, "target": "open order",
"detail": detail},
)