MQTT KeyError in Custom Component

Hello all,

I’m developing a new integration for lights and need MQTT to receive ASYNC updates for LED brightness levels, especially when DALI scenes are activated.

Dev Environment: Set up development environment | Home Assistant Developer Docs
HA Core Dev Repo in VSCode devcontainer.

I verbatim copied this MQTT example code in separate folder under custom_component, and getting KeyError, MQTT may not be setup correctly.

Tutorial: example-custom-config/custom_components/mqtt_basic_async at 4405fb21498ed17dfdb35634021742383d940645 · home-assistant/example-custom-config · GitHub

However, when I copied my custom component folder code to a proper HaOS installation with MQTT Add-on installed and setup in Devices page, the error is gone.

Can someone guide me as to how to replicate this MQTT Add-on installation or equivalent in a HA Core Docker? Or I should setup a different Dev Environment to install Add-ons?

@patrick_jane made a similar comment in this thread: [SOLVED] MQTT not working in custom component