Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/monzo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class MonzoSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.MONETARY,
suggested_display_precision=2,
),
MonzoSensorEntityDescription(
key="spend_today",
translation_key="spend_today",
value_fn=lambda data: abs(data["balance"]["spend_today"]) / 100,
device_class=SensorDeviceClass.MONETARY,
suggested_display_precision=2,
),
)

POT_SENSORS = (
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/monzo/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"pot_balance": {
"name": "[%key:component::monzo::entity::sensor::balance::name%]"
},
"spend_today": {
"name": "Spent today"
},
"total_balance": {
"name": "Total balance"
}
Expand Down
14 changes: 12 additions & 2 deletions tests/components/monzo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@
"id": "acc_curr",
"name": "Current Account",
"type": "uk_retail",
"balance": {"balance": 123, "total_balance": 321, "currency": "GBP"},
"balance": {
"balance": 123,
"total_balance": 321,
"spend_today": -45,
"currency": "GBP",
},
},
{
"id": "acc_flex",
"name": "Flex",
"type": "uk_monzo_flex",
"balance": {"balance": 123, "total_balance": 321, "currency": "EUR"},
"balance": {
"balance": 123,
"total_balance": 321,
"spend_today": -67,
"currency": "EUR",
},
},
]
TEST_POTS = [
Expand Down
112 changes: 112 additions & 0 deletions tests/components/monzo/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,62 @@
'state': '1.23',
})
# ---
# name: test_all_entities[sensor.current_account_spent_today-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.current_account_spent_today',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Spent today',
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Spent today',
'platform': 'monzo',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'spend_today',
'unique_id': 'acc_curr_spend_today',
'unit_of_measurement': 'GBP',
})
# ---
# name: test_all_entities[sensor.current_account_spent_today-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.ATTRIBUTION: 'attribution'>: 'Data provided by Monzo',
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'monetary',
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Current Account Spent today',
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: 'GBP',
}),
'context': <ANY>,
'entity_id': 'sensor.current_account_spent_today',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.45',
})
# ---
# name: test_all_entities[sensor.current_account_total_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
Expand Down Expand Up @@ -167,6 +223,62 @@
'state': '1.23',
})
# ---
# name: test_all_entities[sensor.flex_spent_today-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.flex_spent_today',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Spent today',
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
'original_icon': None,
'original_name': 'Spent today',
'platform': 'monzo',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'spend_today',
'unique_id': 'acc_flex_spend_today',
'unit_of_measurement': 'EUR',
})
# ---
# name: test_all_entities[sensor.flex_spent_today-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.ATTRIBUTION: 'attribution'>: 'Data provided by Monzo',
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'monetary',
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Flex Spent today',
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: 'EUR',
}),
'context': <ANY>,
'entity_id': 'sensor.flex_spent_today',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.67',
})
# ---
# name: test_all_entities[sensor.flex_total_balance-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
Expand Down
1 change: 1 addition & 0 deletions tests/components/monzo/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
EXPECTED_VALUE_GETTERS = {
"balance": lambda x: x["balance"]["balance"] / 100,
"total_balance": lambda x: x["balance"]["total_balance"] / 100,
"spend_today": lambda x: abs(x["balance"]["spend_today"]) / 100,
"pot_balance": lambda x: x["balance"] / 100,
}

Expand Down
Loading