(Pressed wrong category, Should have put this in development)
I did find this https://developers.home-assistant.io/docs/en/creating_component_generic_discovery.html that used the “load_platform”
def load_platform(hass, component, platform, discovered=None, hass_config=None)
So I have a platform in the custom directory. Then a directory called switch off of that.
I was using the arduino as my pattern.
There is the component called arduino.py in the components directory.
https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/arduino.py
Then there is the switch platform in the switch directory.
https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/switch/arduino.py
So in my custom directory I have the almond_plus.py “almond_plus.py component code”
Then I have a switch directory off of it for my platform switch “almond_plus.py platform switch code”
In the component code is the class “AlmondPlus”. It is the wrapper for the API.
hass.data[DATA_ALMONDPLUS] = AlmondPlus(connect_url)
hass.data[DATA_ALMONDPLUS].start()
_LOGGER.debug("Test Almond+ setup: "+str(hass.data[DATA_ALMONDPLUS].get_device_list()))
This logs the device list as expected.
Then I load the platform with the “load_platform”
_LOGGER.debug("Loading switch platform")
load_platform(hass, 'switch', DOMAIN, discovered=None, hass_config=None)
return_status = True
....
_LOGGER.debug("Setup ended with "+str(return_status))
return return_status
The component loads with out error and logs both device list and a “True” return_status.
The platform does not. The “setup.py” throws something about no attributes error. It was line 146 so I added a debug log showing str(component). It is showing null, so I must not be setting the call up right.
More detail is below, but looking at the log output …
2018-07-17 07:35:11 DEBUG (MainThread) [homeassistant.setup] this is starting <module 'custom_components.switch' (namespace)>
Compare the the component
2018-07-17 07:35:11 DEBUG (MainThread) [homeassistant.setup] this is starting <module 'custom_components.almond_plus' from 'C:\\Users\\paul\\PycharmProjects\\home-assistant\\config\\custom_components\\almond_plus.py'>
I am guessing I am not loading the path or something is not right in my call.
Does anyone see the mistake off the top of their head?
Here is the config.yaml, code snippent for the setup.py and part of the hass log. Line 146 was the else part.
config.yaml
almond_plus:
url: 'ws://192.168.1.2:7681/root/password'
setup.py code
try:
_LOGGER.debug("this is starting "+str(component))
if hasattr(component, 'async_setup'):
result = await component.async_setup( # type: ignore
hass, processed_config)
else:
result = await hass.async_add_job(
component.setup, hass, processed_config) # type: ignore
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Error during setup of component %s", domain)
async_notify_setup_error(hass, domain, True)
return False
finally:
end = timer()
if warn_task:
warn_task.cancel()
_LOGGER.info("Setup of domain %s took %.1f seconds.", domain, end - start)
hass log (of course the error is now line 147 after adding the debug )
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.setup] Setting up almond_plus
2018-07-17 07:35:11 DEBUG (MainThread) [homeassistant.setup] this is starting <module 'custom_components.almond_plus' from 'C:\\Users\\paul\\PycharmProjects\\home-assistant\\config\\custom_components\\almond_plus.py'>
2018-07-17 07:35:11 DEBUG (SyncWorker_3) [custom_components.almond_plus] Setup stated
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.entity_registry>
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.config_entries>
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.setup] Setup of domain config took 0.1 seconds.
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config>
2018-07-17 07:35:11 DEBUG (SyncWorker_3) [custom_components.almond_plus] Test Almond+ setup: {"00020001":"AlmondPlusEntity:"{"id":"2","device_id":"1","name":"Under Cabinet MultiSwitch","friendly_device_type":"BinarySwitch","location":"Under Cabinet","last_active_epoch":"1531825145","model":"Unknown: type=2017,","value_name":"SWITCH_BINARY1","value_value":"false","value_type":"1"}"}
2018-07-17 07:35:11 DEBUG (SyncWorker_3) [custom_components.almond_plus] Loading switch platform
2018-07-17 07:35:11 DEBUG (SyncWorker_3) [custom_components.almond_plus] Setup ended with True
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.loader] Loaded switch from custom_components.switch
2018-07-17 07:35:11 WARNING (MainThread) [homeassistant.loader] You are using a custom component for switch which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.setup] Setting up switch
2018-07-17 07:35:11 DEBUG (MainThread) [homeassistant.setup] this is starting <module 'custom_components.switch' (namespace)>
2018-07-17 07:35:11 ERROR (MainThread) [homeassistant.setup] Error during setup of component switch
Traceback (most recent call last):
File "C:\Users\paul\PycharmProjects\home-assistant\venv\lib\site-packages\homeassistant-0.73.1-py3.7.egg\homeassistant\setup.py", line 147, in _async_setup_component
component.setup, hass, processed_config) # type: ignore
AttributeError: module 'custom_components.switch' has no attribute 'setup'
2018-07-17 07:35:11 INFO (MainThread) [homeassistant.setup] Setup of domain almond_plus took 0.5 seconds.