From e855529f73705d58a5533a268239268cb14e9f74 Mon Sep 17 00:00:00 2001 From: Waldemar Tomme Date: Thu, 23 Jun 2022 01:08:51 +0200 Subject: [PATCH] Fix fints integration (#69041) --- homeassistant/components/fints/manifest.json | 4 +-- homeassistant/components/fints/sensor.py | 30 ++++++++++---------- requirements_all.txt | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/fints/manifest.json b/homeassistant/components/fints/manifest.json index ede1025a6db..11d673a2837 100644 --- a/homeassistant/components/fints/manifest.json +++ b/homeassistant/components/fints/manifest.json @@ -2,8 +2,8 @@ "domain": "fints", "name": "FinTS", "documentation": "https://www.home-assistant.io/integrations/fints", - "requirements": ["fints==1.0.1"], + "requirements": ["fints==3.1.0"], "codeowners": [], - "iot_class": "local_push", + "iot_class": "cloud_polling", "loggers": ["fints", "mt_940", "sepaxml"] } diff --git a/homeassistant/components/fints/sensor.py b/homeassistant/components/fints/sensor.py index 4b6cb336bde..2e2ccd8e6b6 100644 --- a/homeassistant/components/fints/sensor.py +++ b/homeassistant/components/fints/sensor.py @@ -7,7 +7,6 @@ import logging from typing import Any from fints.client import FinTS3PinTanClient -from fints.dialog import FinTSDialogError import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity @@ -128,6 +127,9 @@ class FinTsClient: As the fints library is stateless, there is not benefit in caching the client objects. If that ever changes, consider caching the client object and also think about potential concurrency problems. + + Note: As of version 2, the fints library is not stateless anymore. + This should be considered when reworking this integration. """ return FinTS3PinTanClient( @@ -140,24 +142,22 @@ class FinTsClient: def detect_accounts(self): """Identify the accounts of the bank.""" + bank = self.client + accounts = bank.get_sepa_accounts() + account_types = { + x["iban"]: x["type"] + for x in bank.get_information()["accounts"] + if x["iban"] is not None + } + balance_accounts = [] holdings_accounts = [] - for account in self.client.get_sepa_accounts(): - try: - self.client.get_balance(account) + for account in accounts: + account_type = account_types[account.iban] + if 1 <= account_type <= 9: # 1-9 is balance account balance_accounts.append(account) - except IndexError: - # account is not a balance account. - pass - except FinTSDialogError: - # account is not a balance account. - pass - try: - self.client.get_holdings(account) + elif 30 <= account_type <= 39: # 30-39 is holdings account holdings_accounts.append(account) - except FinTSDialogError: - # account is not a holdings account. - pass return balance_accounts, holdings_accounts diff --git a/requirements_all.txt b/requirements_all.txt index 75dd9dfad8a..c40ecd7dc6d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -638,7 +638,7 @@ feedparser==6.0.2 fiblary3==0.1.8 # homeassistant.components.fints -fints==1.0.1 +fints==3.1.0 # homeassistant.components.fitbit fitbit==0.3.1