1 """Platform for sensor integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from datetime
import datetime
9 from simplefin4py
import Account
14 SensorEntityDescription,
22 from .
import SimpleFinConfigEntry
23 from .entity
import SimpleFinEntity
26 @dataclass(frozen=True, kw_only=True)
28 """Describes a sensor entity."""
30 value_fn: Callable[[Account], StateType | datetime]
31 icon_fn: Callable[[Account], str] |
None =
None
32 unit_fn: Callable[[Account], str] |
None =
None
35 SIMPLEFIN_SENSORS: tuple[SimpleFinSensorEntityDescription, ...] = (
38 translation_key=
"balance",
39 state_class=SensorStateClass.TOTAL,
40 device_class=SensorDeviceClass.MONETARY,
41 value_fn=
lambda account: account.balance,
42 unit_fn=
lambda account: account.currency,
43 icon_fn=
lambda account: account.inferred_account_type,
47 translation_key=
"age",
48 device_class=SensorDeviceClass.TIMESTAMP,
49 entity_category=EntityCategory.DIAGNOSTIC,
50 value_fn=
lambda account: account.balance_date,
57 config_entry: SimpleFinConfigEntry,
58 async_add_entities: AddEntitiesCallback,
60 """Set up SimpleFIN sensors for config entries."""
62 sf_coordinator = config_entry.runtime_data
63 accounts = sf_coordinator.data.accounts
71 for account
in accounts
72 for sensor_description
in SIMPLEFIN_SENSORS
77 """Defines a SimpleFIN sensor."""
79 entity_description: SimpleFinSensorEntityDescription
83 """Return the state."""
87 def icon(self) -> str | None:
88 """Return the icon of this account."""
96 """Return the currency of this account."""
Account account_data(self)
str|None native_unit_of_measurement(self)
StateType|datetime|None native_value(self)
None async_setup_entry(HomeAssistant hass, SimpleFinConfigEntry config_entry, AddEntitiesCallback async_add_entities)