mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add command-line toggle to run in demo mode
This commit is contained in:
parent
ed05ff6fd9
commit
5f0f06b22d
@ -33,19 +33,18 @@ If you run into issues while using Home Assistant or during development of a com
|
|||||||
|
|
||||||
## Installation instructions / Quick-start guide
|
## Installation instructions / Quick-start guide
|
||||||
|
|
||||||
Running Home Assistant requires that python3 and the package requests are installed.
|
Running Home Assistant requires that python3 and the package requests are installed. Run the following code to install and start Home Assistant:
|
||||||
|
|
||||||
Run the following code to get up and running with the minimum setup:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
git clone --recursive https://github.com/balloob/home-assistant.git
|
git clone --recursive https://github.com/balloob/home-assistant.git
|
||||||
cd home-assistant
|
cd home-assistant
|
||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
python3 -m homeassistant --open-ui
|
python3 -m homeassistant --open-ui
|
||||||
```
|
```
|
||||||
|
|
||||||
This will start the Home Assistant server and launch its webinterface. By default Home Assistant looks for the configuration file `config/home-assistant.conf`. A standard configuration file will be written if none exists.
|
The last command will start the Home Assistant server and launch its webinterface. By default Home Assistant looks for the configuration file `config/home-assistant.conf`. A standard configuration file will be written if none exists.
|
||||||
|
|
||||||
|
If you are still exploring if you want to use Home Assistant in the first place, you can enable the demo mode by adding the `--demo-mode` argument to the last command.
|
||||||
|
|
||||||
If you're using Docker, you can use
|
If you're using Docker, you can use
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ except ImportError:
|
|||||||
from homeassistant import bootstrap
|
from homeassistant import bootstrap
|
||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||||
|
from homeassistant.components import http, demo
|
||||||
|
|
||||||
|
|
||||||
def validate_dependencies():
|
def validate_dependencies():
|
||||||
@ -55,7 +56,7 @@ def ensure_config_path(config_dir):
|
|||||||
try:
|
try:
|
||||||
with open(config_path, 'w') as conf:
|
with open(config_path, 'w') as conf:
|
||||||
conf.write("[http]\n\n")
|
conf.write("[http]\n\n")
|
||||||
conf.write("[demo]\n\n")
|
conf.write("[discovery]\n\n")
|
||||||
except IOError:
|
except IOError:
|
||||||
print(('Fatal Error: No configuration file found and unable '
|
print(('Fatal Error: No configuration file found and unable '
|
||||||
'to write a default one to {}').format(config_path))
|
'to write a default one to {}').format(config_path))
|
||||||
@ -73,6 +74,10 @@ def main():
|
|||||||
metavar='path_to_config_dir',
|
metavar='path_to_config_dir',
|
||||||
default="config",
|
default="config",
|
||||||
help="Directory that contains the Home Assistant configuration")
|
help="Directory that contains the Home Assistant configuration")
|
||||||
|
parser.add_argument(
|
||||||
|
'--demo-mode',
|
||||||
|
action='store_true',
|
||||||
|
help='Start Home Assistant in demo mode')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--open-ui',
|
'--open-ui',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -86,7 +91,14 @@ def main():
|
|||||||
|
|
||||||
config_path = ensure_config_path(config_dir)
|
config_path = ensure_config_path(config_dir)
|
||||||
|
|
||||||
hass = bootstrap.from_config_file(config_path)
|
if args.demo_mode:
|
||||||
|
# Demo mode only requires http and demo components.
|
||||||
|
hass = bootstrap.from_config_dict({
|
||||||
|
http.DOMAIN: {},
|
||||||
|
demo.DOMAIN: {}
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
hass = bootstrap.from_config_file(config_path)
|
||||||
|
|
||||||
if args.open_ui:
|
if args.open_ui:
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
@ -61,6 +61,8 @@ def from_config_dict(config, hass=None):
|
|||||||
if hass is None:
|
if hass is None:
|
||||||
hass = homeassistant.HomeAssistant()
|
hass = homeassistant.HomeAssistant()
|
||||||
|
|
||||||
|
enable_logging(hass)
|
||||||
|
|
||||||
loader.prepare(hass)
|
loader.prepare(hass)
|
||||||
|
|
||||||
# Make a copy because we are mutating it.
|
# Make a copy because we are mutating it.
|
||||||
@ -86,7 +88,7 @@ def from_config_dict(config, hass=None):
|
|||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
|
||||||
def from_config_file(config_path, hass=None, enable_logging=True):
|
def from_config_file(config_path, hass=None):
|
||||||
"""
|
"""
|
||||||
Reads the configuration file and tries to start all the required
|
Reads the configuration file and tries to start all the required
|
||||||
functionality. Will add functionality to 'hass' parameter if given,
|
functionality. Will add functionality to 'hass' parameter if given,
|
||||||
@ -98,32 +100,6 @@ def from_config_file(config_path, hass=None, enable_logging=True):
|
|||||||
# Set config dir to directory holding config file
|
# Set config dir to directory holding config file
|
||||||
hass.config_dir = os.path.abspath(os.path.dirname(config_path))
|
hass.config_dir = os.path.abspath(os.path.dirname(config_path))
|
||||||
|
|
||||||
if enable_logging:
|
|
||||||
# Setup the logging for home assistant.
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
# Log errors to a file if we have write access to file or config dir
|
|
||||||
err_log_path = hass.get_config_path("home-assistant.log")
|
|
||||||
err_path_exists = os.path.isfile(err_log_path)
|
|
||||||
|
|
||||||
# Check if we can write to the error log if it exists or that
|
|
||||||
# we can create files in the containgin directory if not.
|
|
||||||
if (err_path_exists and os.access(err_log_path, os.W_OK)) or \
|
|
||||||
(not err_path_exists and os.access(hass.config_dir, os.W_OK)):
|
|
||||||
|
|
||||||
err_handler = logging.FileHandler(
|
|
||||||
err_log_path, mode='w', delay=True)
|
|
||||||
|
|
||||||
err_handler.setLevel(logging.WARNING)
|
|
||||||
err_handler.setFormatter(
|
|
||||||
logging.Formatter('%(asctime)s %(name)s: %(message)s',
|
|
||||||
datefmt='%H:%M %d-%m-%y'))
|
|
||||||
logging.getLogger('').addHandler(err_handler)
|
|
||||||
|
|
||||||
else:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Unable to setup error log %s (access denied)", err_log_path)
|
|
||||||
|
|
||||||
# Read config
|
# Read config
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_path)
|
config.read(config_path)
|
||||||
@ -137,3 +113,30 @@ def from_config_file(config_path, hass=None, enable_logging=True):
|
|||||||
config_dict[section][key] = val
|
config_dict[section][key] = val
|
||||||
|
|
||||||
return from_config_dict(config_dict, hass)
|
return from_config_dict(config_dict, hass)
|
||||||
|
|
||||||
|
|
||||||
|
def enable_logging(hass):
|
||||||
|
""" Setup the logging for home assistant. """
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
# Log errors to a file if we have write access to file or config dir
|
||||||
|
err_log_path = hass.get_config_path("home-assistant.log")
|
||||||
|
err_path_exists = os.path.isfile(err_log_path)
|
||||||
|
|
||||||
|
# Check if we can write to the error log if it exists or that
|
||||||
|
# we can create files in the containing directory if not.
|
||||||
|
if (err_path_exists and os.access(err_log_path, os.W_OK)) or \
|
||||||
|
(not err_path_exists and os.access(hass.config_dir, os.W_OK)):
|
||||||
|
|
||||||
|
err_handler = logging.FileHandler(
|
||||||
|
err_log_path, mode='w', delay=True)
|
||||||
|
|
||||||
|
err_handler.setLevel(logging.WARNING)
|
||||||
|
err_handler.setFormatter(
|
||||||
|
logging.Formatter('%(asctime)s %(name)s: %(message)s',
|
||||||
|
datefmt='%H:%M %d-%m-%y'))
|
||||||
|
logging.getLogger('').addHandler(err_handler)
|
||||||
|
|
||||||
|
else:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Unable to setup error log %s (access denied)", err_log_path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user