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

Only subscribe to MQTT topics if MQTT is enabled in Home Assistant #171

Open
nemec opened this issue Jun 3, 2022 · 2 comments
Open

Only subscribe to MQTT topics if MQTT is enabled in Home Assistant #171

nemec opened this issue Jun 3, 2022 · 2 comments

Comments

@nemec
Copy link
Contributor

nemec commented Jun 3, 2022

So I'm getting the following error every time I boot Home Assistant and it seems to stem from the binary sensor of this project calling the async_subscribe method of homeassistant.components.mqtt. I do not have MQTT installed/enabled. The error happens within Home Assistant code, but if you can detect that MQTT is not enabled (I'm not sure how to do this TBH), maybe this code can avoid trying to subscribe?

This is on Ubuntu 22.04 with a brand new Home Assistant install (via git/virtualenv). ha-blueiris is installed in custom_components folder with default settings (though I see the same in my main HA instance installed via HACS)
ETA: running Python 3.10

2022-06-02 20:14:52 ERROR (MainThread) [homeassistant.components.binary_sensor] Error adding entities for domain binary_sensor with platform blueiris
Traceback (most recent call last):
  File "/home/me/prg/src/home-assistant-core/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/home/me/prg/src/home-assistant-core/homeassistant/helpers/entity_platform.py", line 619, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/home/me/prg/src/home-assistant-core/homeassistant/helpers/entity.py", line 809, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/home/me/prg/src/home-assistant-core/config/custom_components/blueiris/models/base_entity.py", line 102, in async_added_to_hass
    await self.async_added_to_hass_local()
  File "/home/me/prg/src/home-assistant-core/config/custom_components/blueiris/binary_sensors/main.py", line 59, in async_added_to_hass_local
    self.remove_subscription = await async_subscribe(
  File "/home/me/prg/src/home-assistant-core/homeassistant/components/mqtt/client.py", line 198, in async_subscribe
    async_remove = await hass.data[DATA_MQTT].async_subscribe(
KeyError: 'mqtt'
@nemec
Copy link
Contributor Author

nemec commented Jun 3, 2022

Ok, so I did some testing on my main instance by commenting out the async_subscribe and it also solves my issue with #85. I don't know exactly what's happened, but it seems like the exception causes the internal EntityManager database to get out of sync with what's actually in Home Assistant, causing the BI plugin to try adding the entity a second time.

@kramttocs
Copy link
Collaborator

@nemec That is very promising!

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

No branches or pull requests

2 participants