Files
up-ha/custom_components/up_banking/models.py
T
git 4dcf2f04c5
Validate / syntax (push) Canceled after 0s
Fix currency presentation and update resilience
2026-09-27 17:56:08 +10:00

29 lines
1.1 KiB
Python

"""Pure data conversion helpers kept independent of Home Assistant."""
from __future__ import annotations
from typing import Any
def account_label(account: dict[str, Any]) -> str:
"""Human friendly account label used only in UI, never as an identifier."""
attrs = account["attributes"]
return f"{attrs['displayName']} ({attrs['accountType'].title()}, {attrs['ownershipType'].title()})"
def transaction_event(transaction: dict[str, Any], event_type: str) -> dict[str, Any]:
"""Return the deliberately small, automation-oriented event payload."""
attrs = transaction["attributes"]
money = attrs["amount"]
account = transaction.get("relationships", {}).get("account", {}).get("data", {})
return {
"transaction_id": transaction["id"],
"event_type": event_type,
"status": attrs["status"].lower(),
"account_id": account.get("id"),
"amount": money["value"],
"currency": "$",
"description": attrs.get("description", ""),
"created_at": attrs.get("createdAt"),
"raw_text": attrs.get("rawText"),
}