diff --git a/.devcontainer/bootstrap.sh b/.devcontainer/bootstrap.sh new file mode 100755 index 0000000..0589bba --- /dev/null +++ b/.devcontainer/bootstrap.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )" + +GITHUB_TOKEN=$(grep github_token ${ROOT}/secrets.yaml | cut -d' ' -f2) +FILES=$(grep "{GITHUB_TOKEN}" ${ROOT}/requirements.txt | sed "s/{GITHUB_TOKEN}/${GITHUB_TOKEN}/g") + +python3 -m pip install --upgrade "${FILES}" diff --git a/bin/devcontainer b/bin/devcontainer index 54b0cfd..b071dc3 100755 --- a/bin/devcontainer +++ b/bin/devcontainer @@ -19,12 +19,18 @@ port="127.0.0.1:9123:8123" image="ludeeus/container:integration-debian" volume="${ROOT}:${workdir}" +if [[ "${1}" == "--public" ]]; then + shift + log.info "Attention! The container is creating externally accessible." + port=$(echo "${port}" | sed "s/127.0.0.1/0.0.0.0/") +fi + cmd="${1:-menu}" docker_start() { tmp=$(echo "${port}" | cut -d":" -f-2) tmp=$(${docker} ps | grep "${tmp}" | awk "{print \$NF}") - if [ -n "${tmp}" ] ; then + if test -n "${tmp}" ; then log.info "Stop container ${tmp}..." ${docker} stop "${tmp}" fi @@ -33,6 +39,13 @@ docker_start() { ${docker} start "${container}" } +bootstrap() { + if test -f "${ROOT}/.devcontainer/bootstrap.sh"; then + log.info "Execute bootstrap.sh..." + ${docker} exec -it -w "${workdir}" "${container}" .devcontainer/bootstrap.sh "$1" + fi +} + if ! ${docker} ps -a | grep -wq ${container} && [[ "${cmd}" != "down" ]]; then log.info "Create container..." ${docker} create -it --name "${container}" -p "${port}" -v "${volume}" "${image}" @@ -41,6 +54,7 @@ if ! ${docker} ps -a | grep -wq ${container} && [[ "${cmd}" != "down" ]]; then log.info "Initialize container..." ${docker} exec -it -w "${workdir}" "${container}" container install + bootstrap "install" fi if [[ "${cmd}" == "menu" ]]; then @@ -88,6 +102,9 @@ case "${cmd}" in log.info "Interactive mode..." ${docker} exec -it "${container}" bash ;; + "bootstrap" ) + bootstrap "${cmd}" + ;; * ) if ! ${docker} ps | grep -wq ${container}; then docker_start @@ -97,5 +114,9 @@ case "${cmd}" in log.info "After Home Assistant initialization you can access to system on http://localhost:9123/" fi ${docker} exec -it -w "${workdir}" "${container}" container "${cmd}" + + if [[ "${cmd}" == "upgrade" ]]; then + bootstrap "${cmd}" + fi ;; esac diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index a369430..e1f5090 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -85,7 +85,7 @@ async def test_failed_config_flow(hass: HomeAssistant, error_on_get_data): # Our config flow also has an options flow, so we must test it as well. -async def test_options_flow(hass): +async def test_options_flow(hass: HomeAssistant): """Test an options flow.""" # Create a new MockConfigEntry and add to HASS (we're bypassing config # flow entirely) diff --git a/tests/test_switch.py b/tests/test_switch.py index 7ea4906..477b531 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -5,6 +5,7 @@ from homeassistant.components.switch import SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.const import ATTR_ENTITY_ID +from homeassistant.core import HomeAssistant from pytest_homeassistant_custom_component.common import MockConfigEntry from custom_components.integration_blueprint import async_setup_entry @@ -13,7 +14,7 @@ from .const import MOCK_CONFIG -async def test_switch_services(hass): +async def test_switch_services(hass: HomeAssistant): """Test switch services.""" # Create a mock entry so we don't have to go through config flow config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")