Onkyo: volume control fixes#14053
Onkyo: volume control fixes#14053rsmeral wants to merge 2 commits intohome-assistant:devfrom rsmeral:onkyo-volume-control-fixes
Conversation
There was a problem hiding this comment.
line too long (88 > 79 characters)
There was a problem hiding this comment.
line too long (97 > 79 characters)
|
|
||
| def __init__(self, receiver, sources, name=None): | ||
| """Initialize the Onkyo Receiver.""" | ||
| from concurrent.futures import ThreadPoolExecutor |
There was a problem hiding this comment.
Oh no. This is waaay too heavy of a solution. If you would want 1 thread, you should start just a thread, not introduce a whole pool. However, even a thread is not allowed to be added. Imagine all our integrations include a thread, we would swamp the CPU.
So instead, you should use asyncio and locks (Home Assistant core is based on asyncio). Asyncio tasks waiting for a lock don't take up any resources. It means that you need to convert all commands to their async variant and include the lock. Once lock has been acquired asynchronously, use the built-in worker pool to run a threaded command: await hass.async_add_job(self.execute_command, command).
There was a problem hiding this comment.
Thanks for review. Good point, I'll try to rework.
If the other commit (SUPPORT_VOLUME_STEP) looks OK, I'll make it a separate PR.
|
@rsmeral Any updates on this PR? |
|
@andrey-git One part got merged (#14299), but the second part (command serialization) I didn't find the time for yet – I agree with the approach proposed by @balloob, but it's non-trivial for me to implement given my limited experience with Python. |
|
This PR seems to have gone stale. Closing it. You can reopen it when you're ready to finish it. |
Description:
Two fixes for Onkyo media player:
media_playerbehaviour of stepping by 10% which seems too coarse for most receiversvolume_up(or any other) service was called repeatedly in a very fast succession (e.g. when pressing a button on a remote), I'd frequently get aResetting connection...errorDisclaimer: I'm not much of a pythonista. Tried running tests, got:
But also:
Checklist:
tox. Your PR cannot be merged unless tests pass