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
+4 -12
View File
@@ -16,7 +16,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
@@ -47,7 +46,6 @@ class FreshHarvestSkip(FreshHarvestEntity, SwitchEntity):
self, coordinator: FreshHarvestCoordinator, entry: FreshHarvestConfigEntry
) -> None:
super().__init__(coordinator, entry, DESCRIPTION.key)
self._entry = entry
@property
def available(self) -> bool:
@@ -70,9 +68,9 @@ class FreshHarvestSkip(FreshHarvestEntity, SwitchEntity):
order.delivery_date, dry_run=False
)
except FreshHarvestError as err:
self._fire("skip", False, str(order.delivery_date), str(err))
self.fire_action("skip", False, str(order.delivery_date), str(err))
raise HomeAssistantError(f"could not skip: {err}") from err
self._fire("skip", True, str(order.delivery_date), result.detail)
self.fire_action("skip", True, str(order.delivery_date), result.detail)
await self.coordinator.async_request_refresh()
async def async_turn_off(self, **kwargs: Any) -> None:
@@ -85,14 +83,8 @@ class FreshHarvestSkip(FreshHarvestEntity, SwitchEntity):
order.delivery_date, dry_run=False
)
except FreshHarvestError as err:
self._fire("restore", False, str(order.delivery_date), str(err))
self.fire_action("restore", False, str(order.delivery_date), str(err))
raise HomeAssistantError(f"could not restore: {err}") from err
self._fire("restore", True, str(order.delivery_date), result.detail)
self.fire_action("restore", True, str(order.delivery_date), result.detail)
await self.coordinator.async_request_refresh()
def _fire(self, action: str, ok: bool, target: str, detail: str) -> None:
self.hass.bus.async_fire(
EVENT_ACTION,
{"domain": DOMAIN, "entry_id": self._entry.entry_id, "action": action,
"success": ok, "target": target, "detail": detail},
)