diff --git a/.gitignore b/.gitignore index 1aee3b5..6fe0770 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,5 @@ venv.bak/ -/dev-config /custom_components/__init__.py /test*.py diff --git a/bin/dev-deploy b/bin/dev-deploy deleted file mode 100755 index 1f155fb..0000000 --- a/bin/dev-deploy +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -# Stop on errors -set -e - -ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )" -cd "${ROOT}" - -# Load common functions -source ./bin/_common - -HASSIO_CONFIG="${ROOT}/dev-config" - -component=$(ls -q "${ROOT}/custom_components/" | grep -v __) - -[[ -d "${HASSIO_CONFIG}/custom_components" ]] || die "ERROR: Home Assistant development configs are not configured." - -pytest || die - -if [[ -d "${HASSIO_CONFIG}/custom_components" ]]; then - log.info "Removing old version of component '${component}'..." - cd "${HASSIO_CONFIG}/custom_components" - rm -Rf "${component}" -fi - -log.info "Copy new version of component '${component}'..." -install -d "${HASSIO_CONFIG}/custom_components" -cp -R "${ROOT}/custom_components/${component}" "${HASSIO_CONFIG}/custom_components" diff --git a/bin/devcontainer b/bin/devcontainer new file mode 100755 index 0000000..bae131e --- /dev/null +++ b/bin/devcontainer @@ -0,0 +1,86 @@ +#!/usr/bin/env bash + +# Stop on errors +set -e + +ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )" +cd "${ROOT}" + +# Load common functions +source ./bin/_common + +dk=$(which docker) || die "ERROR: Docker not found." + +workspace=${PWD##*/} +workdir="/workspaces/${workspace}" + +container="dev-${workspace}" +port="127.0.0.1:9123:8123" +image="ludeeus/container:integration-debian" +volume="${ROOT}:${workdir}" + +cmd="${1:-menu}" + +if ! ${dk} ps -a | grep -wq ${container} && [[ "${cmd}" != "down" ]]; then + log.info "Create container..." + ${dk} create -it --name "${container}" -p "${port}" -v "${volume}" "${image}" +fi + +if [[ "${cmd}" == "menu" ]]; then + PS3='Please enter your choice: ' + options=(\ + "Run Home Assistant on port 9123" + "Run Home Assistant configuration against /config" + "Upgrade Home Assistant to latest dev" + "Install a specific version of Home Assistant" + ) + echo + select opt in "${options[@]}" + do + case $REPLY in + 1 ) + cmd="start" + ;; + 2 ) + cmd="check" + ;; + 3 ) + cmd="upgrade" + ;; + 4 ) + cmd="set-version" + ;; + esac + break + done +fi +case "${cmd}" in + "stop" ) + log.info "Stop container..." + ${dk} stop "${container}" + ;; + "down" ) + log.info "Destroy container..." + ${dk} stop -t 10 "${container}" >/dev/null + ${dk} rm "${container}" + ;; + "bash" ) + if ! ${dk} ps | grep -wq ${container}; then + log.info "Start container..." + ${dk} start "${container}" + fi + log.info "Interactive mode..." + ${dk} exec -it "${container}" bash + ;; + * ) + if ! ${dk} ps | grep -wq ${container}; then + log.info "Start container..." + ${dk} start "${container}" + fi + log.info "Send command '${cmd}' to container..." + if [[ "${cmd}" == "start" ]]; then + log.info "After Home Assistant initialization you can access to system on http://localhost:9123/" + fi + ${dk} exec -it -w "${workdir}" "${container}" container "${cmd}" + ;; +esac diff --git a/bin/setup b/bin/setup index b485bc5..bd64924 100755 --- a/bin/setup +++ b/bin/setup @@ -26,8 +26,3 @@ pre-commit install pip3 install -r requirements-dev.txt touch custom_components/__init__.py - -CONFIG=/run/user/$(id -u)/gvfs/smb-share:server=hassio,share=config/ -if [ -d "$CONFIG" ] && [ ! -e dev-config ]; then - ln -s "$CONFIG" dev-config -fi diff --git a/setup.cfg b/setup.cfg index 294da4b..e0298b3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,7 +15,6 @@ show_missing = true testpaths = tests norecursedirs = .git - dev-config addopts = --strict-markers --cov=custom_components @@ -23,7 +22,7 @@ filterwarnings = ignore::DeprecationWarning:asynctest.*: [flake8] -exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build,__pycache__,dev-config +exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build,__pycache__ doctests = True # To work with Black # https://github.com/ambv/black#line-length