Skip to content

refactor: combine signal retrieval and token rewards operations.#264

Open
ardevd wants to merge 1 commit intomainfrom
token-rewards-in-parallel
Open

refactor: combine signal retrieval and token rewards operations.#264
ardevd wants to merge 1 commit intomainfrom
token-rewards-in-parallel

Conversation

@ardevd
Copy link
Owner

@ardevd ardevd commented Feb 25, 2026

No description provided.

@ardevd ardevd self-assigned this Feb 25, 2026
Copilot AI review requested due to automatic review settings February 25, 2026 22:44
@ardevd ardevd added the enhancement New feature or request label Feb 25, 2026
@redbird-sonarqube
Copy link

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the signal retrieval and token rewards operations to execute concurrently using asyncio.gather, improving performance by fetching both datasets in parallel. The _update_token_rewards async method is converted to a synchronous _process_token_rewards method that processes pre-fetched data rather than fetching it itself.

Changes:

  • Combined signal and token rewards API calls to execute concurrently using asyncio.gather
  • Refactored _update_token_rewards from async method to sync _process_token_rewards that processes already-fetched data
  • Minor code quality improvements in dimo_client.py to avoid redundant dictionary access

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
custom_components/dimo/init.py Refactored to fetch signals and rewards concurrently; converted _update_token_rewards to sync _process_token_rewards method
custom_components/dimo/dimoapi/dimo_client.py Minor refactoring to eliminate redundant dictionary access and improve code readability
tests/test_init.py Updated test to reflect sync nature of _process_token_rewards; removed async decorator and updated mocking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -393,22 +393,21 @@ async def test_get_signals_data_for_vehicle(hass, entry):
coordinator.vehicle_data = {"v1": VehicleData(definition={}, available_signals=["speed"])}

with patch.object(coordinator, "get_api_data", return_value={"data": {"signalsLatest": {"speed": 100}}, "errors": None}):
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test mocks get_api_data with a single return value, but the refactored code calls it twice (once for signals, once for rewards). This should be updated to use side_effect with a list of return values to properly test the concurrent API calls. Currently, both API calls receive the signals data structure, which is not realistic and could hide bugs if the _process_token_rewards mock is removed.

Suggested change
with patch.object(coordinator, "get_api_data", return_value={"data": {"signalsLatest": {"speed": 100}}, "errors": None}):
with patch.object(
coordinator,
"get_api_data",
side_effect=[
{"data": {"signalsLatest": {"speed": 100}}, "errors": None},
{"data": {"vehicle": {"earnings": {"totalTokens": 50}}}},
],
):

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants