mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Update integration Fints with activate mypy, use attr_variables (#53706)
* Please mypy. * Convert property to _attr_variables.
This commit is contained in:
parent
7a200a5d3b
commit
b0c650e088
@ -1,8 +1,10 @@
|
|||||||
"""Read the balance of your bank accounts via FinTS."""
|
"""Read the balance of your bank accounts via FinTS."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from fints.client import FinTS3PinTanClient
|
from fints.client import FinTS3PinTanClient
|
||||||
from fints.dialog import FinTSDialogError
|
from fints.dialog import FinTSDialogError
|
||||||
@ -164,46 +166,23 @@ class FinTsAccount(SensorEntity):
|
|||||||
"""Initialize a FinTs balance account."""
|
"""Initialize a FinTs balance account."""
|
||||||
self._client = client
|
self._client = client
|
||||||
self._account = account
|
self._account = account
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._balance: float = None
|
self._attr_icon = ICON
|
||||||
self._currency: str = None
|
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:
|
def update(self) -> None:
|
||||||
"""Get the current balance and currency for the account."""
|
"""Get the current balance and currency for the account."""
|
||||||
bank = self._client.client
|
bank = self._client.client
|
||||||
balance = bank.get_balance(self._account)
|
balance = bank.get_balance(self._account)
|
||||||
self._balance = balance.amount.amount
|
self._attr_state = balance.amount.amount
|
||||||
self._currency = balance.amount.currency
|
self._attr_unit_of_measurement = balance.amount.currency
|
||||||
_LOGGER.debug("updated balance of account %s", self.name)
|
_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):
|
class FinTsHoldingsAccount(SensorEntity):
|
||||||
"""Sensor for a FinTS holdings account.
|
"""Sensor for a FinTS holdings account.
|
||||||
@ -215,26 +194,17 @@ class FinTsHoldingsAccount(SensorEntity):
|
|||||||
def __init__(self, client: FinTsClient, account, name: str) -> None:
|
def __init__(self, client: FinTsClient, account, name: str) -> None:
|
||||||
"""Initialize a FinTs holdings account."""
|
"""Initialize a FinTs holdings account."""
|
||||||
self._client = client
|
self._client = client
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._account = account
|
self._account = account
|
||||||
self._holdings = []
|
self._holdings: list[Any] = []
|
||||||
self._total: float = None
|
self._attr_icon = ICON
|
||||||
|
self._attr_unit_of_measurement = "EUR"
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Get the current holdings for the account."""
|
"""Get the current holdings for the account."""
|
||||||
bank = self._client.client
|
bank = self._client.client
|
||||||
self._holdings = bank.get_holdings(self._account)
|
self._holdings = bank.get_holdings(self._account)
|
||||||
self._total = sum(h.total_value for h in self._holdings)
|
self._attr_state = 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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict:
|
||||||
@ -257,18 +227,3 @@ class FinTsHoldingsAccount(SensorEntity):
|
|||||||
attributes[price_name] = holding.market_value
|
attributes[price_name] = holding.market_value
|
||||||
|
|
||||||
return attributes
|
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"
|
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -1333,9 +1333,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.filter.*]
|
[mypy-homeassistant.components.filter.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.fints.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.fireservicerota.*]
|
[mypy-homeassistant.components.fireservicerota.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.entur_public_transport.*",
|
"homeassistant.components.entur_public_transport.*",
|
||||||
"homeassistant.components.evohome.*",
|
"homeassistant.components.evohome.*",
|
||||||
"homeassistant.components.filter.*",
|
"homeassistant.components.filter.*",
|
||||||
"homeassistant.components.fints.*",
|
|
||||||
"homeassistant.components.fireservicerota.*",
|
"homeassistant.components.fireservicerota.*",
|
||||||
"homeassistant.components.firmata.*",
|
"homeassistant.components.firmata.*",
|
||||||
"homeassistant.components.flo.*",
|
"homeassistant.components.flo.*",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user