From faa9e0a6fcc5259aca14143070f280072207cf10 Mon Sep 17 00:00:00 2001 From: Alan Bishop Date: Tue, 10 Mar 2026 08:49:17 -0700 Subject: [PATCH] feat: Add current tide level to NOAA tide predictions Use the last and next high/low tide levels and tide factor to predict the current level. --- .../noaa_tides/api_clients/noaa_api_client.py | 9 +++++++++ custom_components/noaa_tides/const.py | 1 + 2 files changed, 10 insertions(+) diff --git a/custom_components/noaa_tides/api_clients/noaa_api_client.py b/custom_components/noaa_tides/api_clients/noaa_api_client.py index fb41147..916bfbb 100644 --- a/custom_components/noaa_tides/api_clients/noaa_api_client.py +++ b/custom_components/noaa_tides/api_clients/noaa_api_client.py @@ -27,6 +27,7 @@ ATTR_NEXT_TIDE_TYPE, ATTR_TIDE_FACTOR, ATTR_TIDE_PERCENTAGE, + ATTR_CURRENT_TIDE_LEVEL, UNIT_IMPERIAL, UNIT_METRIC, ) @@ -218,6 +219,13 @@ async def _fetch_tide_predictions(self) -> dict[str, Any]: if next_tide["type"] == "H": tide_percentage += 50 + # Calculate the current tide level + low_tide_level = min(last_tide["level"], next_tide["level"]) + high_tide_level = max(last_tide["level"], next_tide["level"]) + current_tide_level = low_tide_level + ( + (high_tide_level - low_tide_level) * (tide_factor / 100) + ) + # Format the tide state to show next tide and time next_tide_type = "High" if next_tide["type"] == "H" else "Low" next_tide_time = next_tide["time"].strftime(TIDE_TIME_FORMAT) @@ -246,6 +254,7 @@ async def _fetch_tide_predictions(self) -> dict[str, Any]: ATTR_LAST_TIDE_LEVEL: last_tide["level"], ATTR_TIDE_FACTOR: round(tide_factor, DECIMAL_PRECISION), ATTR_TIDE_PERCENTAGE: round(tide_percentage, DECIMAL_PRECISION), + ATTR_CURRENT_TIDE_LEVEL: round(current_tide_level, DECIMAL_PRECISION), }, } } diff --git a/custom_components/noaa_tides/const.py b/custom_components/noaa_tides/const.py index 32b9550..8923f1b 100644 --- a/custom_components/noaa_tides/const.py +++ b/custom_components/noaa_tides/const.py @@ -102,6 +102,7 @@ ATTR_LAST_TIDE_LEVEL: Final = "last_tide_level" ATTR_TIDE_FACTOR: Final = "tide_factor" ATTR_TIDE_PERCENTAGE: Final = "tide_percentage" +ATTR_CURRENT_TIDE_LEVEL: Final = "current_tide_level" ATTR_CURRENTS_SPEED: Final = "currents_speed" ATTR_CURRENTS_DIRECTION: Final = "currents_direction" ATTR_CURRENTS_TIME: Final = "currents_time"