Update integration Fints with activate mypy, use attr_variables (#53706)

* Please mypy.

* Convert property to _attr_variables.
This commit is contained in:
jan iversen 2021-07-30 19:23:16 +02:00 committed by GitHub
parent 7a200a5d3b
commit b0c650e088
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 66 deletions

View file

@ -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"

View file

@ -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

View file

@ -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.*",