Skip to content

Track API tokens per device instead of globally #43

@simons-plugins

Description

@simons-plugins

Problem

The plugin tracks a single _token_remaining counter in NetroAPIClient that gets overwritten by every API response's meta.token_remaining. Since Netro confirmed that each device has its own independent 2000/day token limit, the last device polled determines the displayed count.

This causes the proactive pause threshold (100 tokens) to trigger based on one device's count, pausing ALL polling — including devices with plenty of tokens remaining.

Context from Netro support

The 2000 limit applies per API key as well as per device. The API key is generated based on the serial number, so the two limits are equivalent.
Each device — Spark, Whisper, and Pixie — is independent and has its own 2000 limit.
All devices perform a poll every 5 minutes, which should theoretically be sufficient: 60 × 24 / 5 = 288 times per day.

Expected token usage per device

  • Sprinkler controller: ~4 calls/poll × 288 polls/day = 1,152/day (within 2000)
  • Whisperer sensor: ~1 call/poll × 288 polls/day = 288/day (within 2000)

No single device should approach the 2000 limit at normal polling intervals.

Proposed solution

  • Track token_remaining and token_reset per device serial number in NetroAPIClient
  • Apply pause/warning thresholds per device, not globally
  • Update the token_remaining device state per device
  • Consider whether proactive pause is still needed given the maths above

Files involved

  • api_client.py_update_token_budget(), should_pause_polling, _token_remaining
  • plugin.pyrunConcurrentThread() pause check, device state updates

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions