Skip to content

fix: convert run_seconds float values to int before API calls#352

Merged
vinteo merged 3 commits intovinteo:masterfrom
JoshDev:fix/issue-294-run-seconds-float
Jan 5, 2026
Merged

fix: convert run_seconds float values to int before API calls#352
vinteo merged 3 commits intovinteo:masterfrom
JoshDev:fix/issue-294-run-seconds-float

Conversation

@JoshDev
Copy link
Contributor

@JoshDev JoshDev commented Jan 5, 2026

Summary

Converts float values in run_seconds to integers before sending to the OpenSprinkler API.

Problem

OpenSprinkler interprets decimal points as zone separators, so values like [0, 480.0, 540.0] fail while [0, 480, 540] works correctly. This commonly occurs when users calculate run times using templates that produce float results.

Solution

Added int() conversion in all code paths that pass run_seconds to the API:

  1. Dict-based run_seconds - Convert values when building the list
  2. Config objects list - Convert values when building the list
  3. Direct list - Convert with list comprehension [int(s) for s in run_seconds]
  4. Individual station run - Accept float type and convert to int (previously raised exception)

Testing

Added pytest test suite with 8 tests covering:

  • Float list conversion (main issue case)
  • Dict value conversion
  • Mixed int/float conversion
  • Backwards compatibility with int values
  • Single station float handling
  • None and invalid type handling

All tests pass locally.

Fixes #294

OpenSprinkler interprets decimal points as zone separators, causing
run_seconds values like [0, 480.0, 540.0] to fail. This converts all
numeric values to integers before passing them to the API.

Also adds pytest test suite covering the fix.

Fixes vinteo#294
@vinteo
Copy link
Owner

vinteo commented Jan 5, 2026

Thanks for adding tests, would it be difficult to add a github action to run the tests?

- Add tests.yml workflow that runs pytest on push/PR
- Tests against Python 3.12 and 3.13
- Clean up unused imports in test file
@JoshDev
Copy link
Contributor Author

JoshDev commented Jan 5, 2026

Added a GitHub Actions workflow to run the tests! It runs pytest against Python 3.12 and 3.13 on every push and PR.

Also cleaned up unused imports in the test file.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2026

@vinteo
Copy link
Owner

vinteo commented Jan 5, 2026

Thank you very much

@vinteo vinteo merged commit 9362920 into vinteo:master Jan 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenSprinkler bug. run_seconds can not be float in opensprinkler.run service

2 participants