From b0c650e088de4065875285031f2e47e4e6db1ac1 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 30 Jul 2021 19:23:16 +0200 Subject: [PATCH] Update integration Fints with activate mypy, use attr_variables (#53706) * Please mypy. * Convert property to _attr_variables. --- homeassistant/components/fints/sensor.py | 79 +++++------------------- mypy.ini | 3 - script/hassfest/mypy_config.py | 1 - 3 files changed, 17 insertions(+), 66 deletions(-) diff --git a/homeassistant/components/fints/sensor.py b/homeassistant/components/fints/sensor.py index 3487444c735..9159e0df49a 100644 --- a/homeassistant/components/fints/sensor.py +++ b/homeassistant/components/fints/sensor.py @@ -1,8 +1,10 @@ """Read the balance of your bank accounts via FinTS.""" +from __future__ import annotations from collections import namedtuple from datetime import timedelta import logging +from typing import Any from fints.client import FinTS3PinTanClient from fints.dialog import FinTSDialogError @@ -164,46 +166,23 @@ class FinTsAccount(SensorEntity): """Initialize a FinTs balance account.""" self._client = client self._account = account - self._name = name - self._balance: float = None - self._currency: str = None + self._attr_name = name + self._attr_icon = ICON + self._attr_extra_state_attributes = { + ATTR_ACCOUNT: self._account.iban, + ATTR_ACCOUNT_TYPE: "balance", + } + if self._client.name: + self._attr_extra_state_attributes[ATTR_BANK] = self._client.name def update(self) -> None: """Get the current balance and currency for the account.""" bank = self._client.client balance = bank.get_balance(self._account) - self._balance = balance.amount.amount - self._currency = balance.amount.currency + self._attr_state = balance.amount.amount + self._attr_unit_of_measurement = balance.amount.currency _LOGGER.debug("updated balance of account %s", self.name) - @property - def name(self) -> str: - """Friendly name of the sensor.""" - return self._name - - @property - def state(self) -> float: - """Return the balance of the account as state.""" - return self._balance - - @property - def unit_of_measurement(self) -> str: - """Use the currency as unit of measurement.""" - return self._currency - - @property - def extra_state_attributes(self) -> dict: - """Additional attributes of the sensor.""" - attributes = {ATTR_ACCOUNT: self._account.iban, ATTR_ACCOUNT_TYPE: "balance"} - if self._client.name: - attributes[ATTR_BANK] = self._client.name - return attributes - - @property - def icon(self) -> str: - """Set the icon for the sensor.""" - return ICON - class FinTsHoldingsAccount(SensorEntity): """Sensor for a FinTS holdings account. @@ -215,26 +194,17 @@ class FinTsHoldingsAccount(SensorEntity): def __init__(self, client: FinTsClient, account, name: str) -> None: """Initialize a FinTs holdings account.""" self._client = client - self._name = name + self._attr_name = name self._account = account - self._holdings = [] - self._total: float = None + self._holdings: list[Any] = [] + self._attr_icon = ICON + self._attr_unit_of_measurement = "EUR" def update(self) -> None: """Get the current holdings for the account.""" bank = self._client.client self._holdings = bank.get_holdings(self._account) - self._total = sum(h.total_value for h in self._holdings) - - @property - def state(self) -> float: - """Return total market value as state.""" - return self._total - - @property - def icon(self) -> str: - """Set the icon for the sensor.""" - return ICON + self._attr_state = sum(h.total_value for h in self._holdings) @property def extra_state_attributes(self) -> dict: @@ -257,18 +227,3 @@ class FinTsHoldingsAccount(SensorEntity): attributes[price_name] = holding.market_value return attributes - - @property - def name(self) -> str: - """Friendly name of the sensor.""" - return self._name - - @property - def unit_of_measurement(self) -> str: - """Get the unit of measurement. - - Hardcoded to EUR, as the library does not provide the currency for the - holdings. And as FinTS is only used in Germany, most accounts will be - in EUR anyways. - """ - return "EUR" diff --git a/mypy.ini b/mypy.ini index cb10dee585b..8c5882b720d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1333,9 +1333,6 @@ ignore_errors = true [mypy-homeassistant.components.filter.*] ignore_errors = true -[mypy-homeassistant.components.fints.*] -ignore_errors = true - [mypy-homeassistant.components.fireservicerota.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index e507e906964..62da8b4fb5f 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -44,7 +44,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.entur_public_transport.*", "homeassistant.components.evohome.*", "homeassistant.components.filter.*", - "homeassistant.components.fints.*", "homeassistant.components.fireservicerota.*", "homeassistant.components.firmata.*", "homeassistant.components.flo.*",