thebradleysanders / Monoprice-6-Zone-Audio-Controller

An Integration for the Monoprice 6 Zone Home Audio Controller, with added sensors, sound mode, balance, treble & bass support.
12 stars 2 forks source link

Merged config_flow HA changes #15

Open CoreyJ87 opened 5 months ago

CoreyJ87 commented 5 months ago

Sorry to reopen this. I thought the code I had in the original PR did not work. I was testing wrong. It appears it does work. Anyways like I said in the other PR

In https://github.com/thebradleysanders/Monoprice-6-Zone-Audio-Controller/pull/10 this pull request Gabriel mentioned that the config text was broken. I believe this is the missing code that should fix that. As this is part of the rework they did in the official HA integration around the config flow. Also removed the extra "CONF_NAME".

CoreyJ87 commented 5 months ago

Okay, so after some more testing now that I finally have the device. This doesn't quite fix it. I've narrowed it down a bit. It seems to be related to the fact that when it tries to make these calls in each file. It times out and errors. https://github.com/thebradleysanders/Monoprice-6-Zone-Audio-Controller/blob/dev/custom_components/monoprice_custom/media_player.py#L212.

When you don't have the extra zones. Like in my case. I just have a single 6 zone. It blows up trying to make this call state = self._monoprice.zone_status(self._zone_id) to each zone you don't have. It times out and causes everything to throw warnings and errors. Bombing out the configuration even though in the background everything still loads correctly.

I was able to fix the config flow bombing out by adding in this if. This effectively skips doing that call for any zones I personally do not have. Fixing the flow.

        """Retrieve latest state."""
        if self._zone_id > 20:
            self._update_success = False
            return
        try:
            state = self._monoprice.zone_status(self._zone_id)

This obviously isn't a fix. As people need this if they have more than 6 zones. I just don't know enough of what I'm doing here to say what that fix is. Just figured I'd post what I have so far in hopes it will save you guys some time.

I'll keep digging when I have time but here is an example of the error I get from the config flow when I don't have that if statement in there.

Error setting up entry socket://ip:port for monoprice
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 504, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/monoprice/__init__.py", line 51, in async_setup_entry
    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1741, in async_forward_entry_setups
    await asyncio.gather(
asyncio.exceptions.CancelledError