Skip to content

Commit 162a085

Browse files
committed
Fixes
1 parent fcc493b commit 162a085

File tree

6 files changed

+50
-24
lines changed

6 files changed

+50
-24
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ dmypy.json
144144
.pyre/
145145

146146
# Ignore folder for local testing
147-
ignore/
147+
ignore/

.pre-commit-config.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,31 @@ repos:
1818
- tomli
1919
exclude: 'cassettes/'
2020

21+
- repo: https://github.com/psf/black
22+
rev: 24.8.0
23+
hooks:
24+
- id: black
25+
additional_dependencies: ['.[jupyter]']
26+
language_version: python3
27+
28+
- repo: https://github.com/astral-sh/ruff-pre-commit
29+
rev: v0.6.4
30+
hooks:
31+
- id: ruff
32+
args: [--fix]
33+
- id: ruff-format
34+
2135
- repo: local
2236
hooks:
37+
- id: format
38+
name: format
39+
entry: .venv/bin/pdm run format
40+
types: [python]
41+
language: system
42+
pass_filenames: false
2343
- id: lint
2444
name: lint
25-
entry: pdm run lint
45+
entry: .venv/bin/pdm run lint
2646
types: [python]
2747
language: system
2848
pass_filenames: false

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
],
55
"python.testing.unittestEnabled": false,
66
"python.testing.pytestEnabled": true
7-
}
7+
}

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ ./example.py
99
Select a category:
1010

1111
[1] 👤 User & Profile
12-
[2] 📊 Daily Health & Activity
12+
[2] 📊 Daily Health & Activity
1313
[3] 🔬 Advanced Health Metrics
1414
[4] 📈 Historical Data & Trends
1515
[5] 🏃 Activities & Workouts
@@ -22,7 +22,7 @@ Select a category:
2222

2323
[q] Exit program
2424

25-
Make your selection:
25+
Make your selection:
2626
```
2727

2828
### API Coverage Statistics
@@ -59,7 +59,7 @@ A comprehensive Python 3 API wrapper for Garmin Connect, providing access to hea
5959
This library enables developers to programmatically access Garmin Connect data including:
6060

6161
- **Health Metrics**: Heart rate, sleep, stress, body composition, SpO2, HRV
62-
- **Activity Data**: Workouts, exercises, training status, performance metrics
62+
- **Activity Data**: Workouts, exercises, training status, performance metrics
6363
- **Device Information**: Connected devices, settings, alarms, solar data
6464
- **Goals & Achievements**: Personal records, badges, challenges, race predictions
6565
- **Historical Data**: Trends, progress tracking, date range queries
@@ -146,7 +146,7 @@ pdm run --list # Display all available PDM scripts
146146
# Before making changes
147147
pdm run lint # Check current code quality
148148

149-
# After making changes
149+
# After making changes
150150
pdm run format # Auto-format your code
151151
pdm run lint # Verify code quality
152152
pdm run codespell # Check spelling
@@ -161,7 +161,7 @@ The library uses the same OAuth authentication as the official Garmin Connect ap
161161

162162
**Key Features:**
163163
- Login credentials valid for one year (no repeated logins)
164-
- Secure OAuth token storage
164+
- Secure OAuth token storage
165165
- Same authentication flow as official app
166166

167167
**Advanced Configuration:**
@@ -195,7 +195,7 @@ pdm run testcov # Run tests with coverage report
195195

196196
**Note:** Tests automatically use `~/.garminconnect` as the default token file location. You can override this by setting the `GARMINTOKENS` environment variable. Run `example.py` first to generate authentication tokens for testing.
197197

198-
**For Developers:** Tests use VCR cassettes to record/replay HTTP interactions. If tests fail with authentication errors, ensure valid tokens exist in `~/.garminconnect`
198+
**For Developers:** Tests use VCR cassettes to record/replay HTTP interactions. If tests fail with authentication errors, ensure valid tokens exist in `~/.garminconnect`
199199

200200
## 📦 Publishing
201201

@@ -232,13 +232,13 @@ pdm publish # Publish pre-built package
232232
We welcome contributions! Here's how you can help:
233233

234234
- **Report Issues**: Bug reports and feature requests via GitHub issues
235-
- **Submit PRs**: Code improvements, new features, documentation updates
235+
- **Submit PRs**: Code improvements, new features, documentation updates
236236
- **Testing**: Help test new features and report compatibility issues
237237
- **Documentation**: Improve examples, add use cases, fix typos
238238

239239
**Before Contributing:**
240240
1. Set up development environment (`pdm install --group :all`)
241-
2. Execute code quality checks (`pdm run format && pdm run lint`)
241+
2. Execute code quality checks (`pdm run format && pdm run lint`)
242242
3. Test your changes (`pdm run test`)
243243
4. Follow existing code style and patterns
244244

@@ -255,7 +255,7 @@ pdm install --group :all
255255

256256
# 3. Quality checks
257257
pdm run format # Auto-format code
258-
pdm run lint # Check code quality
258+
pdm run lint # Check code quality
259259
pdm run test # Run tests
260260

261261
# 4. Submit PR
@@ -293,7 +293,7 @@ print(f"Resting HR: {hr_data['restingHeartRate']}")
293293
Special thanks to all contributors who have helped improve this project:
294294

295295
- **Community Contributors**: Bug reports, feature requests, and code improvements
296-
- **Issue Reporters**: Helping identify and resolve compatibility issues
296+
- **Issue Reporters**: Helping identify and resolve compatibility issues
297297
- **Feature Developers**: Adding new API endpoints and functionality
298298
- **Documentation Authors**: Improving examples and user guides
299299

@@ -307,7 +307,7 @@ If you find this library useful for your projects, please consider supporting it
307307

308308
- **⭐ Star this repository** - Help others discover the project
309309
- **💰 Financial Support** - Contribute to development and hosting costs
310-
- **🐛 Report Issues** - Help improve stability and compatibility
310+
- **🐛 Report Issues** - Help improve stability and compatibility
311311
- **📖 Spread the Word** - Share with other developers
312312

313313
### 💳 Financial Support Options

garminconnect/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,13 @@ def get_body_composition(
537537
"""
538538

539539
startdate = _validate_date_format(startdate, "startdate")
540-
enddate = startdate if enddate is None else _validate_date_format(enddate, "enddate")
541-
if datetime.strptime(startdate, DATE_FORMAT_STR).date() > datetime.strptime(enddate, DATE_FORMAT_STR).date():
540+
enddate = (
541+
startdate if enddate is None else _validate_date_format(enddate, "enddate")
542+
)
543+
if (
544+
datetime.strptime(startdate, DATE_FORMAT_STR).date()
545+
> datetime.strptime(enddate, DATE_FORMAT_STR).date()
546+
):
542547
raise ValueError("Startdate cannot be after enddate")
543548
url = f"{self.garmin_connect_weight_url}/weight/dateRange"
544549
params = {"startDate": str(startdate), "endDate": str(enddate)}
@@ -838,7 +843,6 @@ def get_lactate_threshold(
838843
"""
839844

840845
if latest:
841-
842846
speed_and_heart_rate_url = (
843847
f"{self.garmin_connect_biometric_url}/latestLactateThreshold"
844848
)
@@ -1862,7 +1866,6 @@ def get_activity_details(
18621866
def get_activity_exercise_sets(self, activity_id: str) -> dict[str, Any]:
18631867
"""Return activity exercise sets."""
18641868

1865-
activity_id = _validate_positive_integer(activity_id, "activity_id")
18661869
url = f"{self.garmin_connect_activity}/{activity_id}/exerciseSets"
18671870
logger.debug("Requesting exercise sets for activity id %s", activity_id)
18681871

@@ -1871,7 +1874,6 @@ def get_activity_exercise_sets(self, activity_id: str) -> dict[str, Any]:
18711874
def get_activity_gear(self, activity_id: str) -> dict[str, Any]:
18721875
"""Return gears used for activity id."""
18731876

1874-
activity_id = _validate_positive_integer(activity_id, "activity_id")
18751877
params = {
18761878
"activityId": str(activity_id),
18771879
}
@@ -1934,14 +1936,12 @@ def get_workouts(self, start: int = 0, limit: int = 100) -> dict[str, Any]:
19341936
def get_workout_by_id(self, workout_id: str) -> dict[str, Any]:
19351937
"""Return workout by id."""
19361938

1937-
workout_id = _validate_positive_integer(workout_id, "workout_id")
19381939
url = f"{self.garmin_workouts}/workout/{workout_id}"
19391940
return self.connectapi(url)
19401941

19411942
def download_workout(self, workout_id: str) -> bytes:
19421943
"""Download workout by id."""
19431944

1944-
workout_id = _validate_positive_integer(workout_id, "workout_id")
19451945
url = f"{self.garmin_workouts}/workout/FIT/{workout_id}"
19461946
logger.debug("Downloading workout from %s", url)
19471947

pyproject.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ line-length = 88
9292
target-version = "py310"
9393
exclude = [
9494
".git",
95-
".venv",
95+
".venv",
9696
"__pycache__",
9797
".pytest_cache",
9898
"build",
@@ -151,6 +151,12 @@ testcov = {composite = ["test", "pdm run coverage html", "pdm run coverage xml -
151151
codespell = "pre-commit run codespell --all-files"
152152
clean = "python -c \"import shutil, pathlib; [shutil.rmtree(p, ignore_errors=True) for p in pathlib.Path('.').rglob('__pycache__')]; [p.unlink(missing_ok=True) for p in pathlib.Path('.').rglob('*.py[co]')]\""
153153

154+
# Pre-commit hooks
155+
pre-commit-install = "pre-commit install"
156+
pre-commit-run = "pre-commit run --all-files"
157+
pre-commit-run-staged = "pre-commit run"
158+
pre-commit-update = "pre-commit autoupdate"
159+
154160
# Publishing
155161
build = "pdm build"
156162
publish = {composite = ["build", "pdm publish"]}
@@ -160,8 +166,8 @@ record-vcr = {env = {GARMINTOKENS = "~/.garminconnect"}, cmd = "pdm run pytest t
160166
clean-vcr = "rm -f tests/cassettes/*.yaml"
161167
reset-vcr = {composite = ["clean-vcr", "record-vcr"]}
162168

163-
# Quality checks
164-
all = {composite = ["lint", "codespell", "test"]}
169+
# Quality checks
170+
all = {composite = ["lint", "codespell", "pre-commit-run", "test"]}
165171

166172
[tool.pdm.dev-dependencies]
167173
dev = [

0 commit comments

Comments
 (0)