Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ad-ha/atw
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.0
Choose a base ref
...
head repository: ad-ha/atw
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 9 commits
  • 17 files changed
  • 1 contributor

Commits on Sep 25, 2024

  1. Update Name

    ad-ha authored Sep 25, 2024
    Copy the full SHA
    b86c939 View commit details
  2. Update README.md

    ad-ha authored Sep 25, 2024
    Copy the full SHA
    1f5380f View commit details
  3. Add missing services

    ad-ha authored Sep 25, 2024
    Copy the full SHA
    a73adf4 View commit details
  4. Update README.md

    ad-ha authored Sep 25, 2024
    Copy the full SHA
    d02651b View commit details
  5. Copy the full SHA
    f1f7de6 View commit details
  6. Create FUNDING.yml

    ad-ha authored Sep 25, 2024
    Copy the full SHA
    46021ed View commit details

Commits on Nov 12, 2024

  1. Update README.md

    ad-ha authored Nov 12, 2024
    Copy the full SHA
    a17efc4 View commit details
  2. 0.1.2

    ad-ha authored Nov 12, 2024
    Copy the full SHA
    05e4d49 View commit details
  3. Merge pull request #1 from ad-ha/ad-ha-0.1.2

    0.1.2
    ad-ha authored Nov 12, 2024
    Copy the full SHA
    e3d1528 View commit details
15 changes: 15 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: varetas3d
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
![GitHub Release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/ad-ha/atw?include_prereleases)
![GitHub Downloads (all assets, latest release)](https://img.shields.io/github/downloads/ad-ha/atw/latest/total)

[![HACS Action](https://github.com/ad-ha/atw/actions/workflows/validate.yaml/badge.svg)](https://github.com/ad-ha/atw/actions/workflows/validate.yaml)
[![HACS Action](https://github.com/ad-ha/atw/actions/workflows/validate.yml/badge.svg)](https://github.com/ad-ha/atw/actions/workflows/validate.yml)
[![Hassfest](https://github.com/ad-ha/atw/actions/workflows/hassfest.yaml/badge.svg)](https://github.com/ad-ha/atw/actions/workflows/hassfest.yaml)

![logo-512](https://github.com/user-attachments/assets/489dda3f-d008-490b-88fe-331af026ad27)
@@ -29,6 +29,9 @@ The Advanced Trading Wallet (ATW) integration brings your financial portfolio in
- **Localization**: Support for multiple languages, including English and Spanish.
- **Customizable Update Intervals**: Set how often the integration fetches data from API providers.

- **Historical Data Import**: Available as a service, you may import historical data from each API for a specific asset. _(still under testing)_


## Installation

### HACS (Recommended)
@@ -96,13 +99,23 @@ data:
purchase_price: 150.25
```
#### Sell Stock
```yaml
service: advanced_trading_wallet.sell_crypto
data:
crypto_symbol: "bitcoin"
amount: 0.5
```
#### Historical Data
```yaml
service: advanced_trading_wallet.gest_historical_data
data:
crypto_symbol: AAPL
asset_type: stock
interval: 1mo
```
## Sensors and Entities
The integration creates various sensors to help you monitor your portfolio:
@@ -120,6 +133,8 @@ The integration creates various sensors to help you monitor your portfolio:
* Purchase Price (sensor.{symbol}_purchase_price)
### Lovelace Cards
**IMPORTANT NOTE: Lovelace cards will be moved into a specific frontend integration to ease the setup process. WIP**
Enhance your Home Assistant dashboard with custom Lovelace cards designed for the Advanced Trading Wallet integration.
Add the resources to your Lovelace configuration:
@@ -136,20 +151,26 @@ resources:
Restart Home Assistant or reload the Lovelace resources.
Usage
Portfolio Summary Card
#### Portfolio Summary Card
![image](https://github.com/user-attachments/assets/47462fba-45fd-4f0e-872a-80c3a3cf8ab3)
```yaml
type: 'custom:portfolio-card'
```
Transaction Recorder Card
#### Transaction Recorder Card
![image](https://github.com/user-attachments/assets/7b1692d7-b69b-497d-ad1b-69190b3518c9)
```yaml
type: 'custom:transaction-card'
```
Asset Summary Card
#### Asset Summary Card
![image](https://github.com/user-attachments/assets/b3dc6d34-96a9-4e0b-8df9-22c81eda48c7)
```yaml
type: 'custom:asset-summary-card'
@@ -168,6 +189,14 @@ Contributions are welcome! If you have suggestions, encounter issues, or wish to
## Changelog
```
0.1.2
* Fix sensor updating intervals
* Refactor Coordinator and Sensors Deployement
* Fix additional transactions not being kept after restart
* Fix translation files
```

```
0.1.0
* Initial release of the Advanced Trading Wallet integration.
49 changes: 44 additions & 5 deletions custom_components/advanced_trading_wallet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import timedelta
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType
@@ -26,22 +27,33 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b

# If global coordinator doesn't exist, create it
if "coordinator" not in hass.data[DOMAIN]:
update_interval = config_entry.options.get(
"update_interval", DEFAULT_SCAN_INTERVAL
)
coordinator = ATWCoordinator(
hass,
preferred_currency=config_entry.data.get("preferred_currency", "usd"),
update_interval=config_entry.data.get(
"update_interval", DEFAULT_SCAN_INTERVAL
),
preferred_currency=config_entry.data.get("preferred_currency", "USD"),
update_interval=update_interval,
)
hass.data[DOMAIN]["coordinator"] = coordinator
LOGGER.debug("Created global coordinator")
await coordinator.data_store.async_load()
await coordinator.async_config_entry_first_refresh()
else:
coordinator = hass.data[DOMAIN]["coordinator"]
# Update coordinator's update interval if changed
update_interval = config_entry.options.get(
"update_interval", DEFAULT_SCAN_INTERVAL
)
await coordinator.async_set_update_interval(timedelta(minutes=update_interval))

# Store per-entry data
hass.data[DOMAIN][config_entry.entry_id] = {
entry_id = config_entry.entry_id
entry_data = {
"api_provider": config_entry.data.get("api_provider", DEFAULT_API_PROVIDER),
"preferred_currency": config_entry.data.get(
"preferred_currency", "USD"
).upper(),
"stocks_to_track": config_entry.data.get("stocks_to_track", ""),
"crypto_to_track": config_entry.data.get("crypto_to_track", ""),
"stock_amount_owned": config_entry.data.get("stock_amount_owned", 0),
@@ -50,6 +62,13 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
"crypto_purchase_price": config_entry.data.get("crypto_purchase_price", 0),
}

# Update entry_data with stored data if available
stored_entry_data = coordinator.data_store.get_entry_data(entry_id)
if stored_entry_data:
entry_data.update(stored_entry_data)

hass.data[DOMAIN][entry_id] = entry_data

# Update coordinator's list of symbols and API providers
coordinator.update_symbols(hass.data[DOMAIN])

@@ -58,9 +77,28 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
# Pass the coordinator when setting up services
await async_setup_services(hass, coordinator)

# Add update listener for options
config_entry.async_on_unload(
config_entry.add_update_listener(async_options_updated)
)

return True


async def async_options_updated(hass: HomeAssistant, config_entry: ConfigEntry):
"""Handle options update."""
# Retrieve the coordinator
coordinator = hass.data[DOMAIN]["coordinator"]

# Get the new update_interval from options
update_interval = config_entry.options.get("update_interval", DEFAULT_SCAN_INTERVAL)
new_interval = timedelta(minutes=update_interval)
LOGGER.debug(f"Options updated: new update_interval={new_interval}")

# Update the coordinator's update_interval
await coordinator.async_set_update_interval(new_interval)


async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(
@@ -75,6 +113,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

# If no other entries remain, remove the coordinator and services
if len(hass.data[DOMAIN]) == 1: # Only 'coordinator' remains
await coordinator.async_close()
hass.data[DOMAIN].pop("coordinator")
await async_unload_services(hass)

Loading