diff --git a/examples/workout_examples.py b/examples/workout_examples.py index 36bed89..a92459c 100644 --- a/examples/workout_examples.py +++ b/examples/workout_examples.py @@ -155,7 +155,7 @@ async def main(): # telemetry is a detailed record of a specific workout - minute by minute, or more granular if desired # this endpoint takes a class_history_uuid, as well as a number of max data points - if you do not pass # this value it will attempt to return enough data points for 30 second intervals - telemetry = await otf.dna_api.get_telemetry(workouts.workouts[0].class_history_uuid) + telemetry = await otf.telemetry_api.get_telemetry(workouts.workouts[0].class_history_uuid) print(json.dumps(telemetry.model_dump(), indent=4, default=str)) """ diff --git a/src/otf_api/__init__.py b/src/otf_api/__init__.py index 4b58a56..642b9fd 100644 --- a/src/otf_api/__init__.py +++ b/src/otf_api/__init__.py @@ -1,4 +1,4 @@ -from . import classes_api, dna_api, member_api, studio_api +from . import classes_api, member_api, studios_api, telemetry_api from .api import Api from .models.auth import User from .models.responses import ( @@ -10,9 +10,6 @@ ChallengeTrackerContent, ChallengeTrackerDetailList, ChallengeType, - DnaHrHistory, - DnaMaxHr, - DnaTelemetry, EquipmentType, FavoriteStudioList, HistoryClassStatus, @@ -28,6 +25,9 @@ StudioDetailList, StudioServiceList, StudioStatus, + TelemetryHrHistory, + TelemetryItem, + TelemetryMaxHr, TotalClasses, WorkoutList, ) @@ -55,11 +55,11 @@ "FavoriteStudioList", "OtfClassList", "classes_api", - "studio_api", - "dna_api", - "DnaHrHistory", - "DnaTelemetry", - "DnaMaxHr", + "studios_api", + "telemetry_api", + "TelemetryHrHistory", + "TelemetryItem", + "TelemetryMaxHr", "StudioDetail", "StudioDetailList", "ALL_CLASS_STATUS", diff --git a/src/otf_api/api.py b/src/otf_api/api.py index f4676ab..5c4c71d 100644 --- a/src/otf_api/api.py +++ b/src/otf_api/api.py @@ -12,6 +12,7 @@ from otf_api.models.auth import User from otf_api.performance_api import PerformanceApi from otf_api.studio_api import StudiosApi +from otf_api.telemetry_api import TelemtryApi if typing.TYPE_CHECKING: from loguru import Logger @@ -21,7 +22,7 @@ API_BASE_URL = "api.orangetheory.co" API_IO_BASE_URL = "api.orangetheory.io" -API_DNA_BASE_URL = "api.yuzu.orangetheory.com" +API_TELEMETRY_BASE_URL = "api.yuzu.orangetheory.com" REQUEST_HEADERS = {"Authorization": None, "Content-Type": "application/json", "Accept": "application/json"} @@ -48,6 +49,7 @@ def __init__(self, username: str, password: str): self.classes_api = ClassesApi(self) self.studios_api = StudiosApi(self) self.dna_api = DnaApi(self) + self.telemetry_api = TelemtryApi(self) self.performance_api = PerformanceApi(self) @classmethod @@ -122,9 +124,9 @@ async def _default_request(self, method: str, url: str, params: dict[str, Any] | """Perform an API request to the default API.""" return await self._do(method, API_BASE_URL, url, params) - async def _dna_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any: - """Perform an API request to the DNA API.""" - return await self._do(method, API_DNA_BASE_URL, url, params) + async def _telemetry_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any: + """Perform an API request to the Telemetry API.""" + return await self._do(method, API_TELEMETRY_BASE_URL, url, params) async def _performance_summary_request( self, method: str, url: str, headers: dict[str, str], params: dict[str, Any] | None = None diff --git a/src/otf_api/models/__init__.py b/src/otf_api/models/__init__.py index 9770ebd..4bc040f 100644 --- a/src/otf_api/models/__init__.py +++ b/src/otf_api/models/__init__.py @@ -8,9 +8,6 @@ ChallengeTrackerContent, ChallengeTrackerDetailList, ChallengeType, - DnaHrHistory, - DnaMaxHr, - DnaTelemetry, EquipmentType, FavoriteStudioList, HistoryClassStatus, @@ -26,6 +23,9 @@ StudioDetailList, StudioServiceList, StudioStatus, + TelemetryHrHistory, + TelemetryItem, + TelemetryMaxHr, TotalClasses, WorkoutList, ) @@ -50,9 +50,9 @@ "WorkoutList", "FavoriteStudioList", "OtfClassList", - "DnaHrHistory", - "DnaTelemetry", - "DnaMaxHr", + "TelemetryHrHistory", + "TelemetryItem", + "TelemetryMaxHr", "StudioDetail", "StudioDetailList", "ALL_CLASS_STATUS", diff --git a/src/otf_api/models/responses/__init__.py b/src/otf_api/models/responses/__init__.py index a0a7734..083afaf 100644 --- a/src/otf_api/models/responses/__init__.py +++ b/src/otf_api/models/responses/__init__.py @@ -2,9 +2,6 @@ from .challenge_tracker_content import ChallengeTrackerContent from .challenge_tracker_detail import ChallengeTrackerDetailList from .classes import OtfClassList -from .dna_hr_history import DnaHrHistory -from .dna_max_hr import DnaMaxHr -from .dna_telemetry import DnaTelemetry from .enums import ( ALL_CLASS_STATUS, ALL_HISTORY_CLASS_STATUS, @@ -25,6 +22,9 @@ from .performance_summary_list import PerformanceSummaryList from .studio_detail import StudioDetail, StudioDetailList from .studio_services import StudioServiceList +from .telemetry_hr_history import TelemetryHrHistory +from .telemetry_item import TelemetryItem +from .telemetry_max_hr import TelemetryMaxHr from .total_classes import TotalClasses from .workouts import WorkoutList @@ -47,9 +47,9 @@ "StudioStatus", "FavoriteStudioList", "OtfClassList", - "DnaHrHistory", - "DnaTelemetry", - "DnaMaxHr", + "TelemetryHrHistory", + "TelemetryItem", + "TelemetryMaxHr", "StudioDetail", "StudioDetailList", "ALL_CLASS_STATUS", diff --git a/src/otf_api/models/responses/dna_hr_history.py b/src/otf_api/models/responses/telemetry_hr_history.py similarity index 94% rename from src/otf_api/models/responses/dna_hr_history.py rename to src/otf_api/models/responses/telemetry_hr_history.py index df3424d..9a6b4ce 100644 --- a/src/otf_api/models/responses/dna_hr_history.py +++ b/src/otf_api/models/responses/telemetry_hr_history.py @@ -29,6 +29,6 @@ class HistoryItem(OtfBaseModel): assigned_at: str = Field(..., alias="assignedAt") -class DnaHrHistory(OtfBaseModel): +class TelemetryHrHistory(OtfBaseModel): member_uuid: str = Field(..., alias="memberUuid") history: list[HistoryItem] diff --git a/src/otf_api/models/responses/dna_telemetry.py b/src/otf_api/models/responses/telemetry_item.py similarity index 97% rename from src/otf_api/models/responses/dna_telemetry.py rename to src/otf_api/models/responses/telemetry_item.py index a812604..d071e4b 100644 --- a/src/otf_api/models/responses/dna_telemetry.py +++ b/src/otf_api/models/responses/telemetry_item.py @@ -38,7 +38,7 @@ class TelemetryItem(OtfBaseModel): tread_data: TreadData | None = Field(None, alias="treadData") -class DnaTelemetry(OtfBaseModel): +class TelemetryItem(OtfBaseModel): member_uuid: str = Field(..., alias="memberUuid") class_history_uuid: str = Field(..., alias="classHistoryUuid") class_start_time: datetime = Field(..., alias="classStartTime") diff --git a/src/otf_api/models/responses/dna_max_hr.py b/src/otf_api/models/responses/telemetry_max_hr.py similarity index 86% rename from src/otf_api/models/responses/dna_max_hr.py rename to src/otf_api/models/responses/telemetry_max_hr.py index 7c75353..a4acd6a 100644 --- a/src/otf_api/models/responses/dna_max_hr.py +++ b/src/otf_api/models/responses/telemetry_max_hr.py @@ -8,6 +8,6 @@ class MaxHr(OtfBaseModel): value: int -class DnaMaxHr(OtfBaseModel): +class TelemetryMaxHr(OtfBaseModel): member_uuid: str = Field(..., alias="memberUuid") max_hr: MaxHr = Field(..., alias="maxHr") diff --git a/src/otf_api/dna_api.py b/src/otf_api/telemetry_api.py similarity index 75% rename from src/otf_api/dna_api.py rename to src/otf_api/telemetry_api.py index c358848..86d1b78 100644 --- a/src/otf_api/dna_api.py +++ b/src/otf_api/telemetry_api.py @@ -1,15 +1,15 @@ import typing from math import ceil -from otf_api.models.responses.dna_hr_history import DnaHrHistory -from otf_api.models.responses.dna_max_hr import DnaMaxHr -from otf_api.models.responses.dna_telemetry import DnaTelemetry +from otf_api.models.responses.telemetry_hr_history import TelemetryHrHistory +from otf_api.models.responses.telemetry_item import TelemetryItem +from otf_api.models.responses.telemetry_max_hr import TelemetryMaxHr if typing.TYPE_CHECKING: from otf_api import Api -class DnaApi: +class TelemtryApi: def __init__(self, api: "Api"): self._api = api self.logger = api.logger @@ -18,38 +18,38 @@ def __init__(self, api: "Api"): self._member_id = self._api.user.member_id self._member_uuid = self._api.user.member_uuid - async def get_hr_history(self) -> DnaHrHistory: + async def get_hr_history(self) -> TelemetryHrHistory: """Get the heartrate history for the user. Returns a list of history items that contain the max heartrate, start/end bpm for each zone, the change from the previous, the change bucket, and the assigned at time. Returns: - DnaHrHistory: The heartrate history for the user. + TelemetryHrHistory: The heartrate history for the user. """ path = "/v1/physVars/maxHr/history" params = {"memberUuid": self._member_id} - res = await self._api._dna_request("GET", path, params=params) - return DnaHrHistory(**res) + res = await self._api._telemetry_request("GET", path, params=params) + return TelemetryHrHistory(**res) - async def get_max_hr(self) -> DnaMaxHr: + async def get_max_hr(self) -> TelemetryMaxHr: """Get the max heartrate for the user. Returns a simple object that has the member_uuid and the max_hr. Returns: - DnaMaxHr: The max heartrate for the user. + TelemetryMaxHr: The max heartrate for the user. """ path = "/v1/physVars/maxHr" params = {"memberUuid": self._member_id} - res = await self._api._dna_request("GET", path, params=params) - return DnaMaxHr(**res) + res = await self._api._telemetry_request("GET", path, params=params) + return TelemetryMaxHr(**res) - async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) -> DnaTelemetry: + async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) -> TelemetryItem: """Get the telemetry for a class history. This returns an object that contains the max heartrate, start/end bpm for each zone, @@ -61,7 +61,7 @@ async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) get the max data points from the workout. If the workout is not found, it will default to 120 data points. Returns: - DnaTelemetry: The telemetry for the class history. + TelemetryItem: The telemetry for the class history. """ path = "/v1/performance/summary" @@ -69,8 +69,8 @@ async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) max_data_points = max_data_points or await self._get_max_data_points(class_history_uuid) params = {"classHistoryUuid": class_history_uuid, "maxDataPoints": max_data_points} - res = await self._api._dna_request("GET", path, params=params) - return DnaTelemetry(**res) + res = await self._api._telemetry_request("GET", path, params=params) + return TelemetryItem(**res) async def _get_max_data_points(self, class_history_uuid: str) -> int: """Get the max data points to use for the telemetry.