Invalid config for selfmade custom component

I wrote a custom component in my Home Assistant 0.40 Branch, and the configuration of that component gives back a rather cryptic Error:

ERROR:homeassistant.config:Invalid config for [lablink_ha]: [homeassistant] is an invalid option for [lablink_ha]. Check: lablink_ha->homeassistant. (See ?, line ?). Please check the docs at https://home-assistant.io/components/lablink_ha/
ERROR:homeassistant.setup:Setup failed for lablink_ha: Invalid config.

My configuration.yaml:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 48.2333
[...]
lablink_ha:

and my code from homeassistant/components/lablink_ha/init.py:

import logging

import jpype
import lablink
import lablink.lablink_connection as llcon
import voluptuous as vol
from homeassistant.helpers import config_validation as cv
from homeassistant.const import (
    EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)

_LOGGER = logging.getLogger(__name__)

DOMAIN = "lablink_ha"

REQUIREMENTS = ["lablink==0.1.3"]

CONF_BROKER = "broker"
CONF_PORT = "port"
CONF_PROTOCOL = "protocol"
CONF_ENABLE_RE = "reconnect"

CONF_DOMAIN = "domain"
CONF_APP = "app"
CONF_GROUP = "group"
CONF_NAME = "name"

DEFAULT_BROKER = "localhost"
DEFAULT_PORT = 1883

DEFAULT_DOMAIN = ""
DEFAULT_APP = "HA"
DEFAULT_GROUP = "Group1"
DEFAULT_NAME = "HomeAssistant"

CONFIG_SCHEMA = vol.Schema({
    DOMAIN: vol.Schema({
        vol.Optional(CONF_DOMAIN, default=DEFAULT_DOMAIN): cv.string,
        vol.Optional(CONF_APP, default=DEFAULT_APP): cv.string,
        vol.Optional(CONF_GROUP, default=DEFAULT_GROUP): cv.string,
        vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
        vol.Optional(CONF_BROKER, default=DEFAULT_BROKER): cv.string,
        vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.positive_int,
        vol.Optional(CONF_PROTOCOL): cv.string,
        vol.Optional(CONF_ENABLE_RE): cv.boolean,
}, extra=vol.ALLOW_EXTRA)})

lablink_con = None


def setup(hass, config):
     """Lablink setup"""
     config = config.get(DOMAIN, {})

   lablink.start_jvm()
    _LOGGER.debug("JVM started")

    global lablink_con
    lablink_con = LablinkConnection(
        platform_domain=config[CONF_DOMAIN],
        platform_app=config[CONF_APP],
        platform_group=config[CONF_GROUP],
        platform_name=config[CONF_NAME],
        connect_broker=config[CONF_BROKER],
        connect_port=config[CONF_PORT])

    def stop_lablink():
        """Stop the Lablink Service"""
        lablink_con.shutdown_connection()

    def start_lablink():
        """Start the Lablink Service"""
        lablink_con.start_connection()
        hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_lablink)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_lablink)

    return True


class LablinkConnection():

    def __init__(self, platform_domain, platform_app, platform_group,
                 platform_name, connect_broker, connect_port,
                 connect_protocol=None, connect_enable_re=None):

        self.platform_domain = platform_domain
        self.platform_app = platform_app
        self.platform_group = platform_group
        self.platform_name = platform_name

        self.connect_broker = connect_broker
        self.connect_port = connect_port
        self.connect_protocol = connect_protocol or "tcp"
        self.connect_enable_re = connect_enable_re or True

        BaseConfiguration = jpype.JClass(
            "org.apache.commons.configuration.BaseConfiguration")
        config = BaseConfiguration()
        config.addProperty("lowLevelComm.brokerAddress", self.connect_broker)
        config.addProperty("lowLevelComm.brokerPort", self.connect_port)
        if not self.connect_enable_re:
            config.addProperty("lowLevelComm.enableReconnection",
                               self.connect_enable_re)
        if self.connect_protocol != "tcp":
            config.addProperty("lowLevelComm.connectionProtocol",
                               self.connect_protocol)

        self.ll_connection = llcon.LabLinkConnection(self.platform_domain,
                                                     self.platform_app,
                                                     self.platform_group,
                                                     self.platform_name,)

    def start_connection(self):
        lablink.start_jvm()
        self.ll_connection.connect()
        _LOGGER.debug("lablink_ha connection has been established")

    def shutdown_connection(self):

        self.ll_connection.disconnect()
        self.ll_connection.shutdown()
        _LOGGER.debug("lablink_ha connection has been shut down")

        lablink.shutdown_jvm()
        _LOGGER.debug("lablink_ha core has been shut down")
        return False

I’m not quite sure what to make of this Error, as it keeps popping up no matter what i change.
Do I have to register my component with Home Assistant somehow?

I have tried several different configurations, like adding all the optional arguments and moving my component to the custom_components folder in the CONFIG directory, but i keep getting the same Error.
What does it mean that [homeassistant] is an invalid option for [lablink_ha]?

I would appreciate it if someone could show me in the right direction here :slight_smile:,
I’m really out of ideas!
thanks!

1 Like

The minimal example works for me with your structure (components/lablink_ha/__init__.py instead of components/lablink_ha.py)

Thank you! i was able to reconstruct a working example from the minimal example… the Error was with the location of the extra=vol.ALLOW_EXTRA inside the brackets (it’s supposed to be in the outer brackets) in the CONFIG_SCHEMA…
Hope this can help someone avoid a similar mistake!

The stupidest errors are often the hardest to find :smile: