1 """Sensor config - monarch money."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
5 from datetime
import datetime
7 from typedmonarchmoney.models
import MonarchAccount, MonarchCashflowSummary
12 SensorEntityDescription,
20 from .
import MonarchMoneyConfigEntry
21 from .entity
import MonarchMoneyAccountEntity, MonarchMoneyCashFlowEntity
24 @dataclass(frozen=True, kw_only=True)
26 """Describe an account sensor entity."""
28 value_fn: Callable[[MonarchAccount], StateType | datetime]
29 picture_fn: Callable[[MonarchAccount], str |
None] |
None =
None
32 @dataclass(frozen=True, kw_only=True)
34 """Describe a cashflow sensor entity."""
36 summary_fn: Callable[[MonarchCashflowSummary], StateType]
40 MONARCH_MONEY_VALUE_SENSORS: tuple[MonarchMoneyAccountSensorEntityDescription, ...] = (
43 translation_key=
"value",
44 state_class=SensorStateClass.TOTAL,
45 device_class=SensorDeviceClass.MONETARY,
46 value_fn=
lambda account: account.balance,
47 picture_fn=
lambda account: account.logo_url,
48 native_unit_of_measurement=CURRENCY_DOLLAR,
53 MONARCH_MONEY_SENSORS: tuple[MonarchMoneyAccountSensorEntityDescription, ...] = (
56 translation_key=
"balance",
57 state_class=SensorStateClass.TOTAL,
58 device_class=SensorDeviceClass.MONETARY,
59 value_fn=
lambda account: account.balance,
60 picture_fn=
lambda account: account.logo_url,
61 native_unit_of_measurement=CURRENCY_DOLLAR,
65 MONARCH_MONEY_AGE_SENSORS: tuple[MonarchMoneyAccountSensorEntityDescription, ...] = (
68 translation_key=
"age",
69 device_class=SensorDeviceClass.TIMESTAMP,
70 entity_category=EntityCategory.DIAGNOSTIC,
71 value_fn=
lambda account: account.last_update,
75 MONARCH_CASHFLOW_SENSORS: tuple[MonarchMoneyCashflowSensorEntityDescription, ...] = (
78 translation_key=
"sum_income",
79 summary_fn=
lambda summary: summary.income,
80 state_class=SensorStateClass.TOTAL,
81 device_class=SensorDeviceClass.MONETARY,
82 native_unit_of_measurement=CURRENCY_DOLLAR,
86 translation_key=
"sum_expense",
87 summary_fn=
lambda summary: summary.expenses,
88 state_class=SensorStateClass.TOTAL,
89 device_class=SensorDeviceClass.MONETARY,
90 native_unit_of_measurement=CURRENCY_DOLLAR,
94 translation_key=
"savings",
95 summary_fn=
lambda summary: summary.savings,
96 state_class=SensorStateClass.TOTAL,
97 device_class=SensorDeviceClass.MONETARY,
98 native_unit_of_measurement=CURRENCY_DOLLAR,
102 translation_key=
"savings_rate",
103 summary_fn=
lambda summary: summary.savings_rate * 100,
104 suggested_display_precision=1,
105 native_unit_of_measurement=PERCENTAGE,
112 config_entry: MonarchMoneyConfigEntry,
113 async_add_entities: AddEntitiesCallback,
115 """Set up Monarch Money sensors for config entries."""
116 mm_coordinator = config_entry.runtime_data
118 entity_list: list[MonarchMoneySensor | MonarchMoneyCashFlowSensor] = [
123 for sensor_description
in MONARCH_CASHFLOW_SENSORS
131 for account
in mm_coordinator.balance_accounts
132 for sensor_description
in MONARCH_MONEY_SENSORS
140 for account
in mm_coordinator.accounts
141 for sensor_description
in MONARCH_MONEY_AGE_SENSORS
149 for account
in mm_coordinator.value_accounts
150 for sensor_description
in MONARCH_MONEY_VALUE_SENSORS
157 """Cashflow summary sensor."""
159 entity_description: MonarchMoneyCashflowSensorEntityDescription
163 """Return the state."""
168 """Define a monarch money sensor."""
170 entity_description: MonarchMoneyAccountSensorEntityDescription
174 """Return the state."""
179 """Return the picture of the account as provided by monarch money if it exists."""
MonarchAccount account_data(self)
MonarchCashflowSummary summary_data(self)
StateType native_value(self)
StateType|datetime native_value(self)
str|None entity_picture(self)
None async_setup_entry(HomeAssistant hass, MonarchMoneyConfigEntry config_entry, AddEntitiesCallback async_add_entities)