Skip to content

Commit

Permalink
Merge remote-tracking branch 'template/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	custom_components/integration_blueprint/__init__.py
#	custom_components/integration_blueprint/binary_sensor.py
#	custom_components/integration_blueprint/sensor.py
#	custom_components/integration_blueprint/switch.py
#	tests/test_api.py
#	tests/test_config_flow.py
#	tests/test_init.py
#	tests/test_switch.py
  • Loading branch information
Limych committed Mar 17, 2021
2 parents de7bf49 + b4e2695 commit 913f762
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ tab_width = 4

[*.{yml,yaml}]
indent_size = 2

[*.json]
indent_size = 2
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
.gitattributes export-ignore
.gitignore export-ignore

.* export-ignore
/bin export-ignore
/docs export-ignore
/tests export-ignore
README.md export-ignore
setup.cfg export-ignore
pylintrc export-ignore
7 changes: 0 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ jobs:
git config --global user.name "release"
git config --global user.email "release@GitHub"
- name: "Set version number"
if: env.release_version != '' && success()
working-directory: ./custom_components/${{ env.package }}
run: |
sed -i '/VERSION = /c\VERSION = "${{ env.release_version }}"' __init__.py
sed -i '/VERSION = /c\VERSION = "${{ env.release_version }}"' const.py
- name: "Zip component dir"
if: env.release_version != '' && success()
working-directory: ./custom_components/${{ env.package }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ venv.bak/

/custom_components/__init__.py
/test*.py
secrets.yaml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
[![License][license-shield]](LICENSE.md)
[![License][license-shield]][license]

[![hacs][hacs-shield]][hacs]
[![Project Maintenance][maintenance-shield]][user_profile]
Expand Down
43 changes: 26 additions & 17 deletions bin/devcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cd "${ROOT}"
# Load common functions
source ./bin/_common

dk=$(which docker) || die "ERROR: Docker not found."
docker=$(which docker) || die "ERROR: Docker not found."

workspace=${PWD##*/}
workdir="/workspaces/${workspace}"
Expand All @@ -21,15 +21,26 @@ 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}"
docker_start() {
tmp=$(echo "${port}" | cut -d":" -f-2)
tmp=$(${docker} ps | grep "${tmp}" | awk "{print \$NF}")
if [ -n "${tmp}" ] ; then
log.info "Stop container ${tmp}..."
${docker} stop "${tmp}"
fi

log.info "Start container..."
${dk} start "${container}"
${docker} start "${container}"
}

if ! ${docker} ps -a | grep -wq ${container} && [[ "${cmd}" != "down" ]]; then
log.info "Create container..."
${docker} create -it --name "${container}" -p "${port}" -v "${volume}" "${image}"

docker_start

log.info "Initialize container..."
${dk} exec -it -w "${workdir}" "${container}" container install
${docker} exec -it -w "${workdir}" "${container}" container install
fi

if [[ "${cmd}" == "menu" ]]; then
Expand Down Expand Up @@ -63,30 +74,28 @@ fi
case "${cmd}" in
"stop" )
log.info "Stop container..."
${dk} stop "${container}"
${docker} stop "${container}"
;;
"down" )
log.info "Destroy container..."
${dk} stop -t 10 "${container}" >/dev/null
${dk} rm "${container}"
${docker} stop -t 10 "${container}" >/dev/null
${docker} rm "${container}"
;;
"bash" )
if ! ${dk} ps | grep -wq ${container}; then
log.info "Start container..."
${dk} start "${container}"
if ! ${docker} ps | grep -wq ${container}; then
docker_start
fi
log.info "Interactive mode..."
${dk} exec -it "${container}" bash
${docker} exec -it "${container}" bash
;;
* )
if ! ${dk} ps | grep -wq ${container}; then
log.info "Start container..."
${dk} start "${container}"
if ! ${docker} ps | grep -wq ${container}; then
docker_start
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}"
${docker} exec -it -w "${workdir}" "${container}" container "${cmd}"
;;
esac
2 changes: 1 addition & 1 deletion bin/gen_releasenotes
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_period(repo: Repository, release: str = None) -> List[datetime]:
timestamp = datetime.strptime(commit.last_modified, dateformat)
_LOGGER.debug("Process tag %s => timestamp %s", tag.name, timestamp)
data.append(timestamp)
if found and (not Version(tag.name).is_prerelease or not is_prerelease):
if found and (not Version(tag.name).is_prerelease or is_prerelease):
break
if release is not None and release == tag.name:
found = last = True
Expand Down
8 changes: 6 additions & 2 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ new=$(echo "${1}" | sed -E "s/\+.*//")
log.info "Patch files to version '${new}'..."
sed -i -E "s/(^VERSION = \")[^\"]*/\\1${new}/" ${const_path}
./bin/update_manifest
git commit -a --no-verify -m "Bump version"
git commit -a --no-verify -m "Bump version to ${new}"
git tag -a "$new" -m "v$new"
log.info "Commit tagged as v$new"

dev="$(echo "${new}" | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.).dev0"
if echo "${new}" | grep -Eq "[0-9](a|b|rc)"; then
dev="$(echo "${version}" | sed "s/dev//" | awk -F. '/[0-9]+\./{$NF="dev"($NF+1);print}' OFS=.)"
else
dev="$(echo "${new}" | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.).dev0"
fi

log.info "Patch files to version '${dev}'..."
sed -i -E "s/(^VERSION = \")[^\"]*/\\1${dev}/" ${const_path}
Expand Down
11 changes: 7 additions & 4 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ set -e
ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )"
cd "${ROOT}"

python=$(which python3)
pip="${python} -m pip"

# Load common functions
source ./bin/_common

if [ ! -d "venv" ]; then
log.info "Initializing the virtual environment..."
/usr/bin/python3 -m venv venv
${python} -m venv venv
source ./venv/bin/activate
fi

log.info "Updating PIP..."
/usr/bin/python3 -m pip install --upgrade pip
${pip} install --upgrade pip

log.info "Installing development dependencies..."
pip3 install colorlog pre-commit $(grep mypy requirements-dev.txt)
${pip} install colorlog pre-commit $(grep mypy requirements-dev.txt)

pre-commit install
pip3 install -r requirements-dev.txt
${pip} install -r requirements-dev.txt

echo '"""Custom components module."""' >custom_components/__init__.py
8 changes: 6 additions & 2 deletions bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ set -e
ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )"
cd "${ROOT}"

git pull
git submodule update
if git branch -r | grep -q "template/" ; then
git fetch template
fi

git fetch
git submodule update --remote
17 changes: 10 additions & 7 deletions bin/update_requirements
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
"""Helper script to update requirements."""
import json
import os
import sys

import requests

ROOT = os.path.dirname(os.path.abspath(f"{__file__}/.."))

PKG_PATH = PACKAGE = None
for current_path, dirs, _ in os.walk(f"{ROOT}/custom_components"):
if current_path.find("__pycache__") != -1:
continue
for dname in dirs:
if dname != "__pycache__":
PACKAGE = dname
PKG_PATH = f"{ROOT}/custom_components/{PACKAGE}"
for fname in os.listdir(f"{ROOT}/custom_components"):
if fname != "__pycache__" and os.path.isdir(f"{ROOT}/custom_components/{fname}"):
PACKAGE = fname
PKG_PATH = f"{ROOT}/custom_components/{PACKAGE}"
break

if not PACKAGE:
print("Package not found.")
sys.exit(1)


def get_package(requre: str) -> str:
Expand Down
8 changes: 4 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements-test.txt
black==20.08b1
packaging==20.9
pre-commit==2.10.1
PyGithub==1.54.1
pyupgrade==2.10.0
yamllint==1.26.0
pre-commit~=2.11
PyGithub~=1.54
pyupgrade~=2.10
yamllint~=1.26
14 changes: 7 additions & 7 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-r requirements.txt
pytest==6.2.2
pytest-cov==2.10.1
pytest-homeassistant-custom-component==0.2.1
flake8==3.8.4
pylint==2.7.2
pylint-strict-informational==0.1
asynctest==0.13.0
asynctest~=0.13
flake8~=3.9
mypy==0.812
pylint~=2.7
pylint-strict-informational==0.1
pytest~=6.2
pytest-cov~=2.10
pytest-homeassistant-custom-component~=0.2
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=protected-access,redefined-outer-name
"""Global fixtures for integration."""
# Fixtures allow you to replace functions with a Mock object. You can perform
# many options via the Mock to reflect a particular behavior from the original
Expand Down

0 comments on commit 913f762

Please sign in to comment.