refactor: combine signal retrieval and token rewards operations.#264
refactor: combine signal retrieval and token rewards operations.#264
Conversation
|
There was a problem hiding this comment.
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_rewardsfrom async method to sync_process_token_rewardsthat processes already-fetched data - Minor code quality improvements in
dimo_client.pyto 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}): | |||
There was a problem hiding this comment.
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.
| 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}}}}, | |
| ], | |
| ): |




No description provided.