Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions custom_components/noaa_tides/api_clients/noaa_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ATTR_NEXT_TIDE_TYPE,
ATTR_TIDE_FACTOR,
ATTR_TIDE_PERCENTAGE,
ATTR_CURRENT_TIDE_LEVEL,
UNIT_IMPERIAL,
UNIT_METRIC,
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
},
}
}
Expand Down
1 change: 1 addition & 0 deletions custom_components/noaa_tides/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down