diff --git a/bin/release b/bin/release index 1ae88c2..35d65a6 100755 --- a/bin/release +++ b/bin/release @@ -39,6 +39,8 @@ git commit -a --no-verify -m "Bump version" git tag -a "$new" -m "v$new" log.info "Commit tagged as v$new" -log.info "Patch files to version '${new}.dev0'..." -sed -i -E "s/(^VERSION = \")[^\"]*/\\1${new}.dev0/" ${const_path} +dev="$(echo "${new}" | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.).dev0" + +log.info "Patch files to version '${dev}'..." +sed -i -E "s/(^VERSION = \")[^\"]*/\\1${dev}/" ${const_path} ./bin/update_manifest diff --git a/bin/update_requirements b/bin/update_requirements index 67f3b81..974f661 100755 --- a/bin/update_requirements +++ b/bin/update_requirements @@ -54,6 +54,6 @@ for req in manifest["requirements"]: pkg = get_package(req) if pkg in harequire: print(f"{pkg} in HA requirements, no need here.") -print(json.dumps(manifest["requirements"], indent=4, sort_keys=True)) +print(json.dumps(manifest["requirements"], indent=4)) with open(f"{PKG_PATH}/manifest.json", "w") as manifestfile: - manifestfile.write(json.dumps(manifest, indent=4, sort_keys=True)) + manifestfile.write(json.dumps(manifest, indent=4)) diff --git a/custom_components/__init__.py b/custom_components/__init__.py deleted file mode 100644 index f55f54d..0000000 --- a/custom_components/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Custom components module.""" diff --git a/custom_components/average/const.py b/custom_components/average/const.py index 05a9051..cf1a170 100644 --- a/custom_components/average/const.py +++ b/custom_components/average/const.py @@ -12,7 +12,15 @@ VERSION = "1.6.8+dev" ISSUE_URL = "https://github.com/Limych/ha-average/issues" -UPDATE_MIN_TIME = timedelta(seconds=20) +STARTUP_MESSAGE = f""" +------------------------------------------------------------------- +{NAME} +Version: {VERSION} +This is a custom integration! +If you have ANY issues with this you need to open an issue here: +{ISSUE_URL} +------------------------------------------------------------------- +""" # Configuration and options CONF_START = "start" @@ -26,8 +34,6 @@ DEFAULT_NAME = "Average" DEFAULT_PRECISION = 2 -# Defaults - # Attributes ATTR_START = "start" ATTR_END = "end" @@ -37,8 +43,7 @@ ATTR_COUNT = "count" ATTR_MIN_VALUE = "min_value" ATTR_MAX_VALUE = "max_value" - - +# ATTR_TO_PROPERTY = [ ATTR_START, ATTR_END, @@ -51,12 +56,4 @@ ] -STARTUP_MESSAGE = f""" -------------------------------------------------------------------- -{NAME} -Version: {VERSION} -This is a custom integration! -If you have ANY issues with this you need to open an issue here: -{ISSUE_URL} -------------------------------------------------------------------- -""" +UPDATE_MIN_TIME = timedelta(seconds=20) diff --git a/custom_components/average/sensor.py b/custom_components/average/sensor.py index 9e31e63..c524cb8 100644 --- a/custom_components/average/sensor.py +++ b/custom_components/average/sensor.py @@ -16,6 +16,7 @@ import homeassistant.util.dt as dt_util import voluptuous as vol +from _sha1 import sha1 from homeassistant.components import history from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN from homeassistant.components.group import expand_entity_ids @@ -148,6 +149,17 @@ def __init__( self.count = 0 self.min_value = self.max_value = None + self._unique_id = sha1( + ";".join( + [str(start), str(duration), str(end), ",".join(self.sources)] + ).encode("utf-8") + ) + + @property + def unique_id(self): + """Return a unique ID to use for this entity.""" + return self._unique_id + @property def _has_period(self) -> bool: """Return True if sensor has any period setting.""" diff --git a/requirements-test.txt b/requirements-test.txt index eac053f..9e24b41 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,7 +1,7 @@ -r requirements.txt pytest==6.2.2 pytest-cov==2.10.1 -pytest-homeassistant-custom-component==0.2.0 +pytest-homeassistant-custom-component==0.2.1 flake8==3.8.4 pylint==2.7.2 pylint-strict-informational==0.1