Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocking HA process using asyncio #9

Merged
merged 6 commits into from
Mar 16, 2024
Merged

Conversation

dbuezas
Copy link
Contributor

@dbuezas dbuezas commented Mar 16, 2024

Also stop/play media on volume change so it is applied

Fixes #8

Also stop/play media on volume change so it is applied
Timeout on connection
@definitio
Copy link
Owner

Thanks for contributing! There is unhandled exception when device is unavailable:

2024-03-16 17:06:37.084 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.vacuum fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 945, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1262, in async_device_update
await self.async_update()
File "/config/custom_components/sox/media_player.py", line 218, in async_update
await self._async_send("") # For compatibility with old sound server
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/sox/media_player.py", line 195, in _async_send
if writer:
^^^^^^
UnboundLocalError: cannot access local variable 'writer' where it is not associated with a value

@dbuezas
Copy link
Contributor Author

dbuezas commented Mar 16, 2024

Ups missed that :)

@definitio
Copy link
Owner

Integration doesn't try to connect to device if it was offline during HA start. However after successful start reconnecting works. Any ideas?

@dbuezas
Copy link
Contributor Author

dbuezas commented Mar 16, 2024

I'm suspecting of self._is_connected is None in:

async def async_update(self):
        """Get the latest data and update the state."""
        if self._is_connected is None or self._volume is not None:
            await self._async_send("")  # For compatibility with old sound server

Although it should connect as soon as a command is sent. I'm testing that.

BTW, I'm curious, did you also notice your home assistant working better with this PR?
I only discovered this when my vacuum broke (fixed now), that it was working awfully. I wonder if you also had bad performance for months because of this

@dbuezas
Copy link
Contributor Author

dbuezas commented Mar 16, 2024

Ok, If it is not connected, HA won't send the play command. I guess it used to work because the send command would error.

fix reconnection
@dbuezas
Copy link
Contributor Author

dbuezas commented Mar 16, 2024

Do you know why the update function has an or self._volume is not None ?
I don't understand that part

@dbuezas
Copy link
Contributor Author

dbuezas commented Mar 16, 2024

Should be fixed now

@definitio
Copy link
Owner

definitio commented Mar 16, 2024

BTW, I'm curious, did you also notice your home assistant working better with this PR?

It's definitely better now.

Do you know why the update function has an or self._volume is not None ?

The first version of sound server doesn't support volume control and state reporting. I used self._volume to detect version of server. There was some compatibility problems between old and new versions. It was 3 years ago, I don't remember how exactly that works. Probably nobody uses old version now and this hack can be removed.

@definitio definitio merged commit f650adc into definitio:master Mar 16, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blocks the all processes for 3 seconds every 10 if the vacuum is offline
2 participants