diff --git a/Dockerfile b/Dockerfile index 5c4cfc78704..3ff2a3f1dfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,4 @@ VOLUME /config EXPOSE 8123 -CMD [ "python", "./start.py", "--docker" ] +CMD [ "python", "-m", "homeassistant", "--docker" ] diff --git a/README.md b/README.md index 33cd4d862ea..0881780a39f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ git clone --recursive https://github.com/balloob/home-assistant.git cd home-assistant pip3 install -r requirements.txt -python3 start.py +python3 -m homeassistant ``` This will start the Home Assistant server and create an initial configuration file in `config/home-assistant.conf` that is setup for demo mode. It will launch its web interface on [http://127.0.0.1:8123](http://127.0.0.1:8123). The default password is 'password'. diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py new file mode 100644 index 00000000000..42b70c87454 --- /dev/null +++ b/homeassistant/__main__.py @@ -0,0 +1,52 @@ +""" Starts home assistant. """ + +import sys +import os + +try: + from homeassistant import bootstrap + +except ImportError: + # This is to add support to load Home Assistant using + # `python3 homeassistant` instead of `python3 -m homeassistant` + + # Insert the parent directory of this file into the module search path + sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) + + from homeassistant import bootstrap + + +ARG_RUN_TESTS = "--run-tests" +ARG_DOCKER = '--docker' + + +def main(): + """ Starts Home Assistant. Will create demo config if no config found. """ + + # Do we want to run the tests? + if ARG_RUN_TESTS in sys.argv: + sys.argv.remove(ARG_RUN_TESTS) + + import unittest + + unittest.main(module='homeassistant.test') + + # Within Docker we load the config from a different path + if ARG_DOCKER in sys.argv: + config_path = '/config/home-assistant.conf' + else: + config_path = 'config/home-assistant.conf' + + # Ensure a config file exists to make first time usage easier + if not os.path.isfile(config_path): + with open(config_path, 'w') as conf: + conf.write("[http]\n") + conf.write("api_password=password\n\n") + conf.write("[demo]\n") + + hass = bootstrap.from_config_file(config_path) + hass.start() + hass.block_till_stopped() + +if __name__ == "__main__": + main() diff --git a/run_tests b/run_tests deleted file mode 100755 index fcf5f06cf0d..00000000000 --- a/run_tests +++ /dev/null @@ -1 +0,0 @@ -python3 -B -m unittest homeassistant.test diff --git a/start.py b/start.py deleted file mode 100644 index 9ac8cce457d..00000000000 --- a/start.py +++ /dev/null @@ -1,24 +0,0 @@ -""" Starts home assistant. """ - -import sys -import os - -import homeassistant -import homeassistant.bootstrap - -# Within Docker we load the config from a different path -if '--docker' in sys.argv: - config_path = '/config/home-assistant.conf' -else: - config_path = 'config/home-assistant.conf' - -# Ensure a config file exists to make first time usage easier -if not os.path.isfile(config_path): - with open(config_path, 'w') as conf: - conf.write("[http]\n") - conf.write("api_password=password\n\n") - conf.write("[demo]\n") - -hass = homeassistant.bootstrap.from_config_file(config_path) -hass.start() -hass.block_till_stopped()