Basically dot means the current package. So in this case, for the original climate.py, in its original location, . means homeassistant.components.mqtt (or homeassistant/components/mqtt/__init__.py.) And .discovery means homeassistant.components.mqtt.discovery (or homeassistant/components/mqtt/discovery.py.)
What I’ve done in the past, rather than change the import statements, or copying all the files, I simply created indirect references. E.g., in this case I would create /config/custom_components/whatever/__init__.py which would contain:
from homeassistant.components.mqtt import *
and /config/custom_components/whatever/const.py that would contain:
from homeassistant.components.mqtt.const import *
etc.
Or, although I haven’t tried this, you might be able to just make symlinks:
cd /config/custom_components/whatever
ln -s /usr/src/app/homeassistant/components/mqtt/__init__.py __init__.py
...
Either of these last two options allows you to copy and modify only what you want, while effectively including the other files as-is. When you update HA you automatically get any new versions – which can be a good thing, or a bad thing.
Thanks for the link. What I should’ve said was what is the purpose of these commands: import sys sys.path.insert(0, '/config')
I found this link explaining sys and my guess is the two commands are being used to configure python’s environment?
I like the suggestions you’ve made for incorporating the from statements into __init__.py.
I finished creating a customized version of 0.94’s MQTT climate.py. It took longer than expected because the code changed since 0.89 (for the better, but it created more work for me). The few tests I’ve done confirm it’s working as desired. FWIW, I have no __init__.py in the directory (just climate.py and manifest.json) and Home Assistant seems to have no problem with that arrangement.
I’m hoping this is the last time I will need to create a customized version of MQTT’s climate component. pvizeli is redesigning the entire climate component (for all platforms). I know at least one of the things it will do (that one of my modifications does now) is to make a distinction between an HVAC system’s operating mode (auto, heat, cool, off) and its operating state (heating, cooling, drying, idle).
Yeah, basically the import mechanism will use sys.path to search for modules & packages. You’ll notice that when I had you run that site package it output what sys.path would be (although I had you do it originally from the wrong directory. Should have been in /usr/src/apps/homeassisant, which I figured out later.) You can add paths to sys.path (which is just a Python list of path strings) to make it look in additional places. In fact, that’s what HA’s loader does:
I just suggested you do the same thing “manually.”