* Initial commit * Second commit - with some coverage but errors abount * Updated testing coverage * Should be just about ready for PR * Adding some error handling for wonky acocunts * Adding USD hardcoded as this is all that is currently supported i believe * updating snapshots * updating entity descrition a little * Addign cashflow in * adding aggregate sensors * tweak icons * refactor some type stuff as well as initialize the pr comment addressing process * remove empty fields from manifest * Update homeassistant/components/monarchmoney/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * move stuff * get logging out of try block * get logging out of try block * using Subscription ID as stored in config entry for unique id soon * new unique id * giving cashflow a better unique id * Moving subscription id stuff into setup of coordinator * Update homeassistant/components/monarchmoney/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * ruff ruff * ruff ruff * split ot value and balance sensors... need to go tos leep * removed icons * Moved summary into a data class * efficenty increase * Update homeassistant/components/monarchmoney/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarchmoney/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarchmoney/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarchmoney/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * refactor continues * removed a comment * forgot to add a little bit of info * updated snapshot * Updates to monarch money using the new typed/wrapper setup * backing lib update * fixing manifest * fixing manifest * fixing manifest * Version 0.2.0 * fixing some types * more type fixes * cleanup and bump * no check * i think i got it all * the last thing * update domain name * i dont know what is in this commit * The Great Renaming * Moving to dict style accounting - as per request * updating backing deps * Update homeassistant/components/monarch_money/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/monarch_money/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/monarch_money/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/monarch_money/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/monarch_money/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * some changes * fixing capitalizaton * test test test * Adding dupe test * addressing pr stuff * forgot snapshot * Fix * Fix * Update homeassistant/components/monarch_money/sensor.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
"""Monarch money entity definition."""
|
|
|
|
from typedmonarchmoney.models import MonarchAccount, MonarchCashflowSummary
|
|
|
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|
from homeassistant.helpers.entity import EntityDescription
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import MonarchMoneyDataUpdateCoordinator
|
|
|
|
|
|
class MonarchMoneyEntityBase(CoordinatorEntity[MonarchMoneyDataUpdateCoordinator]):
|
|
"""Base entity for Monarch Money with entity name attribute."""
|
|
|
|
_attr_has_entity_name = True
|
|
|
|
|
|
class MonarchMoneyCashFlowEntity(MonarchMoneyEntityBase):
|
|
"""Entity for Cashflow sensors."""
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: MonarchMoneyDataUpdateCoordinator,
|
|
description: EntityDescription,
|
|
) -> None:
|
|
"""Initialize the Monarch Money Entity."""
|
|
super().__init__(coordinator)
|
|
self._attr_unique_id = (
|
|
f"{coordinator.subscription_id}_cashflow_{description.key}"
|
|
)
|
|
self.entity_description = description
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, str(coordinator.subscription_id))},
|
|
name="Cashflow",
|
|
)
|
|
|
|
@property
|
|
def summary_data(self) -> MonarchCashflowSummary:
|
|
"""Return cashflow summary data."""
|
|
return self.coordinator.cashflow_summary
|
|
|
|
|
|
class MonarchMoneyAccountEntity(MonarchMoneyEntityBase):
|
|
"""Entity for Account Sensors."""
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: MonarchMoneyDataUpdateCoordinator,
|
|
description: EntityDescription,
|
|
account: MonarchAccount,
|
|
) -> None:
|
|
"""Initialize the Monarch Money Entity."""
|
|
super().__init__(coordinator)
|
|
|
|
self.entity_description = description
|
|
self._account_id = account.id
|
|
self._attr_attribution = (
|
|
f"Data provided by Monarch Money API via {account.data_provider}"
|
|
)
|
|
self._attr_unique_id = (
|
|
f"{coordinator.subscription_id}_{account.id}_{description.translation_key}"
|
|
)
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, str(account.id))},
|
|
name=f"{account.institution_name} {account.name}",
|
|
entry_type=DeviceEntryType.SERVICE,
|
|
manufacturer=account.data_provider,
|
|
model=f"{account.institution_name} - {account.type_name} - {account.subtype_name}",
|
|
configuration_url=account.institution_url,
|
|
)
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
"""Return if entity is available."""
|
|
return super().available and (
|
|
self._account_id in self.coordinator.data.account_data
|
|
)
|
|
|
|
@property
|
|
def account_data(self) -> MonarchAccount:
|
|
"""Return the account data."""
|
|
return self.coordinator.data.account_data[self._account_id]
|