0.89 Custom component change guidance

Hi,

I’ve made a custom_component based on the inbuilt sharp aquos media_player component and modified it to test out a heap of changes I want to make. Prior to 0.89, I put a copy of the stock component into custom_components, and made my changes, and away it went. Now though, it appears I need to at least also copy over init.py too which I’ve done too. But I’ve hit this error,

2019-03-07 23:18:29 ERROR (SyncWorker_10) [homeassistant.loader] Error loading custom_components.sharp_aquos. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/loader.py", line 166, in _load_file
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/custom_components/sharp_aquos/__init__.py", line 39, in <module>
    from .const import (
ImportError: cannot import name 'ATTR_APP_ID' from 'custom_components.sharp_aquos.const' (/home/homeassistant/.homeassistant/custom_components/sharp_aquos/const.py)

I’ve tried copying over the whole media_player component folder into the custom_components folder including const.py too, but this message still repeats.

Can anyone advise what I need to do to get this working again?

Have you followed the error and looked in or around line 39 in the copied init.py ? It appears to be referencing something called ATTR_APP_ID that is not available there.

The 0.89 Release notes point here for further clues:

Yeah so that is in the const.py which I’ve put in the folder.

I’ll be honest, I’m not a python person so I’ve struggle through just changing the stock component. I’m not sure what

Example of a relative import is from . import DATA_BRIDGE

means.

This is the part in init.py it doesnt like:

from .const import (
    ATTR_APP_ID,
    ATTR_APP_NAME,
    ATTR_INPUT_SOURCE,
    ATTR_INPUT_SOURCE_LIST,
    ATTR_MEDIA_ALBUM_ARTIST,
    ATTR_MEDIA_ALBUM_NAME,
    ATTR_MEDIA_ARTIST,
    ATTR_MEDIA_CHANNEL,
    ATTR_MEDIA_CONTENT_ID,
    ATTR_MEDIA_CONTENT_TYPE,
    ATTR_MEDIA_DURATION,
    ATTR_MEDIA_ENQUEUE,
    ATTR_MEDIA_EPISODE,
    ATTR_MEDIA_PLAYLIST,
    ATTR_MEDIA_POSITION,
    ATTR_MEDIA_POSITION_UPDATED_AT,
    ATTR_MEDIA_SEASON,
    ATTR_MEDIA_SEEK_POSITION,
    ATTR_MEDIA_SERIES_TITLE,
    ATTR_MEDIA_SHUFFLE,
    ATTR_MEDIA_TITLE,
    ATTR_MEDIA_TRACK,
    ATTR_MEDIA_VOLUME_LEVEL,
    ATTR_MEDIA_VOLUME_MUTED,
    ATTR_SOUND_MODE,
    ATTR_SOUND_MODE_LIST,
    DOMAIN,
    SERVICE_CLEAR_PLAYLIST,
    SERVICE_PLAY_MEDIA,
    SERVICE_SELECT_SOUND_MODE,
    SERVICE_SELECT_SOURCE,
    SUPPORT_PAUSE,
    SUPPORT_SEEK,
    SUPPORT_VOLUME_SET,
    SUPPORT_VOLUME_MUTE,
    SUPPORT_PREVIOUS_TRACK,
    SUPPORT_NEXT_TRACK,
    SUPPORT_PLAY_MEDIA,
    SUPPORT_SELECT_SOURCE,
    SUPPORT_STOP,
    SUPPORT_CLEAR_PLAYLIST,
    SUPPORT_PLAY,
    SUPPORT_SHUFFLE_SET,
    SUPPORT_SELECT_SOUND_MODE,
)

Apparently it expects a file names const (or .const?) in the same directory. If a filename begins with a ‘.’ it is sometimes hidden.

I assume based on what I see in the stock component, ‘.’ could mean current directory. If I rename it to have the dot at the start, the error changes to

ModuleNotFoundError: No module named 'custom_components.sharp_aquos.const'

So it seems to recognize that the file was at least there when it was named const.py.

Well… weird…, by renaming it, and then renaming it back, it now recognises it and the component loads.

i also have a question about new custom component, i am still using the harmony as a custom component

so i have a new file structure : custom_components\harmony

in here;

  • remote.py
  • init.py

but i receve 2 warnings?

2019-03-07 15:17:17 WARNING (MainThread) [homeassistant.loader] You are using a custom component for harmony 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.
2019-03-07 15:17:17 WARNING (MainThread) [homeassistant.loader] You are using a custom component for harmony.remote 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.

why do i have 2 warnings instead of 1 ?

I dont think there is a problem, I have that for every custom component too now.

2019-03-08 07:13:21 WARNING (MainThread) [homeassistant.loader] You are using a custom component for smartir 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.
2019-03-08 07:13:21 WARNING (MainThread) [homeassistant.loader] You are using a custom component for custom_updater 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.
2019-03-08 07:13:29 WARNING (MainThread) [homeassistant.loader] You are using a custom component for bom_radar 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.
2019-03-08 07:13:29 WARNING (MainThread) [homeassistant.loader] You are using a custom component for bom_radar.camera 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.
2019-03-08 07:13:29 WARNING (MainThread) [homeassistant.loader] You are using a custom component for smartir.climate 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.
2019-03-08 07:13:30 WARNING (MainThread) [homeassistant.loader] You are using a custom component for fcm-android 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.
2019-03-08 07:13:30 WARNING (MainThread) [homeassistant.loader] You are using a custom component for fcm-android.notify 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.
2019-03-08 07:13:30 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sharp_aquos 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.
2019-03-08 07:13:30 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sharp_aquos.media_player 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.
2019-03-08 07:13:30 WARNING (MainThread) [homeassistant.loader] You are using a custom component for composite 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.
2019-03-08 07:13:30 WARNING (MainThread) [homeassistant.loader] You are using a custom component for composite.device_tracker 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.