Custom mqtt component not working after 0.69 update

Hi there,

I’ve got two custom components that import mqtt in this way: “loader.get_component(‘mqtt’)” where loader is “homeassistant.loader”.

It worked fine for a few releases, but now with 0.69 and 0.69.1 I get can error while starting HASS: TypeError: get_component() missing 1 required positional argument: ‘comp_or_platform’

Any idea what’s wrong? I obviously miss an argument, but is there any more information about it? Is that all, or is the whole usage of mqtt different for example? Some API docs would be great…

1 Like

There was a PR that got Reverted a few days later.
Maybe you can get some infos there.

Thanks, that fixed that error. I now use mqtt like this: “mqtt = hass.components.mqtt”

But now I get a new error that never was there before: “raise HomeAssistantError(“topic needs to be a string!”)”.

I even tried to put a str function around the topic, but doesn’t fix it.

Here’s my call: “mqtt.subscribe(hass, topic0, message_received_0)”

Anyone? Tried to use subscribe async but that doesn’t do anything.

I’m 100% sure that my topic is a string because when I print the type via Python I get “type:<class ‘str’>”. So there must be something broken.

Even when I do ‘mqtt.subscribe(hass, “lala”, message_received_0)’ it gives the error. Did someone break this in an update?

You’re not alone and I’m getting exactly what’s happening to you. I’m digging for a solution but if anybody else more knowledgeable can chime in with a solution that would be nice.

@Gerben321 you helped me out figuring out that you need to use mqtt like this: mqtt = hass.components.mqtt and from this I think I might have figured this out:

In my custom component I was doing this:

mqtt.subscribe(hass, topic, message_received)
mqtt.publish(hass, topic, call.data.get('new_state'))

What needs to happen is this:

mqtt.subscribe(topic, message_received)
mqtt.publish(topic, call.data.get('new_state'))

Since the component was already created for you, you no longer have to pass hass in the subscribe or publish calls.

I haven’t tested this out but it looks like this would do it.

2 Likes

@ccuono Wow that would make a lot of sense. I was getting some other errors which this might also explain! I’ll give it a shot tonight. Let me know if it works for you! Cheers.

@Gerben321 I can confirm it worked, this is the solution to the problem.

Thanks again. Upgraded my system to 0.70.0 with your fix and no more errors. Not home atm so I can’t test, but it seems good.