vinteo / hass-opensprinkler

OpenSprinkler Integration for Home Assistant
MIT License
204 stars 40 forks source link

fix: allow run_seconds to use int or str as keys #288

Closed EdLeckert closed 3 months ago

EdLeckert commented 3 months ago

This resolves Issue #284, which pointed out that one of the formats for creating template switches used in the examples no longer works.

Consider this snippet:

  run_seconds:
    0: 60
    1: 60
    2: 60
    3: 60
    4: 60
    5: 60

If this is called as part of opensprinkler.run from Developer tools > Services, the keys are converted to strings, which is what the code expects. However, if it is part of a template switch, they arrive as integers, which dict.get() interprets as a lookup failure and returns None. Ultimately, the run durations are set to 0.

This PR attempts to find both int and str keys. If you know of a better way to cover both cases than to use the default parameter of dict.get(), please speak up.

sonarcloud[bot] commented 3 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

EdLeckert commented 3 months ago

@vinteo: I see you have approved this PR. Do you want me to merge it?