Skip to content

Commit

Permalink
Add SimpleFin sensor to show age of data (home-assistant#122550)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor authored Jul 30, 2024
1 parent 6999c6b commit 067acce
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 5 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/simplefin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"integration_type": "service",
"iot_class": "cloud_polling",
"loggers": ["simplefin"],
"requirements": ["simplefin4py==0.0.16"]
"requirements": ["simplefin4py==0.0.18"]
}
13 changes: 11 additions & 2 deletions homeassistant/components/simplefin/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime

from simplefin4py import Account

Expand All @@ -13,6 +14,7 @@
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
Expand All @@ -25,7 +27,7 @@
class SimpleFinSensorEntityDescription(SensorEntityDescription):
"""Describes a sensor entity."""

value_fn: Callable[[Account], StateType]
value_fn: Callable[[Account], StateType | datetime]
icon_fn: Callable[[Account], str] | None = None
unit_fn: Callable[[Account], str] | None = None

Expand All @@ -40,6 +42,13 @@ class SimpleFinSensorEntityDescription(SensorEntityDescription):
unit_fn=lambda account: account.currency,
icon_fn=lambda account: account.inferred_account_type,
),
SimpleFinSensorEntityDescription(
key="age",
translation_key="age",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda account: account.balance_date,
),
)


Expand Down Expand Up @@ -70,7 +79,7 @@ class SimpleFinSensor(SimpleFinEntity, SensorEntity):
entity_description: SimpleFinSensorEntityDescription

@property
def native_value(self) -> StateType:
def native_value(self) -> StateType | datetime | None:
"""Return the state."""
return self.entity_description.value_fn(self.account_data)

Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/simplefin/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"sensor": {
"balance": {
"name": "Balance"
},
"age": {
"name": "Data age"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,7 @@ sharp_aquos_rc==0.3.2
shodan==1.28.0

# homeassistant.components.simplefin
simplefin4py==0.0.16
simplefin4py==0.0.18

# homeassistant.components.sighthound
simplehound==0.3
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ sfrbox-api==0.0.8
sharkiq==1.0.2

# homeassistant.components.simplefin
simplefin4py==0.0.16
simplefin4py==0.0.18

# homeassistant.components.sighthound
simplehound==0.3
Expand Down
Loading

0 comments on commit 067acce

Please sign in to comment.