Skip to content

Commit

Permalink
Merge branch 'release/v1.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Sep 13, 2020
2 parents b5648c1 + 4c15312 commit faaedab
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 23 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/semantic_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: semantic_release

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
ref: master
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install python-semantic-release
- name: Setup Git
run: |
git config --global user.name "semantic-release"
git config --global user.email "semantic-release@GitHub"
- name: Publish with semantic-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DEBUG='*' semantic-release publish
# Pack the ha-average dir as a zip and upload to the release
- name: Zip average dir
run: |
cd /home/runner/work/ha-average/ha-average/custom_components/average
zip average.zip -r ./
- name: Set release variable
run: |
echo "::set-env name=release_version::`git describe --abbrev=0`"
- name: Sleep
# add delay so upload does not kill the release notes from semantic-release
run: |
sleep 5
- name: Upload zip to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: /home/runner/work/ha-average/ha-average/custom_components/average/average.zip
asset_name: average.zip
tag: ${{ env.release_version }}
overwrite: true
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ repos:
- id: no-commit-to-branch
args:
- --branch=master
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.23.0
hooks:
- id: yamllint
- repo: local
hooks:
# Run mypy through our wrapper script in order to get the possible
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ I also suggest you [visit the support topic][forum-support] on the community for
I put a lot of work into making this repo and component available and updated to inspire and help others! I will be glad to receive thanks from you — it will give me new strength and add enthusiasm:
<p align="center"><br>
<a href="https://www.patreon.com/join/limych?" target="_blank"><img src="http://khrolenok.ru/support_patreon.png" alt="Patreon" width="250" height="48"></a>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=UAGFL5L6M8RN2&item_name=[average]+Donation+for+a+big+barrel+of+coffee+:)&currency_code=EUR&source=url" target="_blank"><img src="http://khrolenok.ru/support_paypal.png" alt="PayPal" width="250" height="48"></a>
<br>or&nbsp;support via Bitcoin or Etherium:<br>
<a href="https://sochain.com/a/mjz640g" target="_blank"><img src="http://khrolenok.ru/support_bitcoin.png" alt="Bitcoin" width="150"><br>
16yfCfz9dZ8y8yuSwBFVfiAa3CNYdMh7Ts</a>
Expand All @@ -93,6 +92,9 @@ I put a lot of work into making this repo and component available and updated to
> **_Note_**:\
> You can use weather provider, climate and water heater entities as a data source. For that entities sensor use values of current temperature.
> **_Note_**:\
> You can use groups of entities as a data source. These groups will be automatically expanded to individual entities.
**name**:\
_(string) (Optional)_\
Name to use in the frontend.\
Expand Down Expand Up @@ -132,8 +134,11 @@ I put a lot of work into making this repo and component available and updated to
**end**:\
Timestamp of the end of the calculation period (if period was set).
**sources**:\
Total expanded list of source sensors.
**count_sources**:\
Total count of set source sensors.
Total count of source sensors.
**available_sources**:\
Count of available source sensors (for current calculation period).
Expand Down Expand Up @@ -184,6 +189,15 @@ The duration variable is used when the time period is fixed. Different syntaxes
minutes: 30
```

<p align="center">* * *</p>
I put a lot of work into making this repo and component available and updated to inspire and help others! I will be glad to receive thanks from you — it will give me new strength and add enthusiasm:
<p align="center"><br>
<a href="https://www.patreon.com/join/limych?" target="_blank"><img src="http://khrolenok.ru/support_patreon.png" alt="Patreon" width="250" height="48"></a>
<br>or&nbsp;support via Bitcoin or Etherium:<br>
<a href="https://sochain.com/a/mjz640g" target="_blank"><img src="http://khrolenok.ru/support_bitcoin.png" alt="Bitcoin" width="150"><br>
16yfCfz9dZ8y8yuSwBFVfiAa3CNYdMh7Ts</a>
</p>

### Examples

Here are some examples of periods you could work with, and what to write in your `configuration.yaml`:
Expand Down Expand Up @@ -274,3 +288,5 @@ See separate [license file](LICENSE.md) for full text.

[forum-support]: https://community.home-assistant.io/t/average-sensor/111674
[hacs]: https://github.com/custom-components/hacs
[limych]: https://github.com/Limych
[contributors]: https://github.com/Limych/ha-average/graphs/contributors
2 changes: 1 addition & 1 deletion custom_components/average/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"""

# Base component constants
VERSION = '1.5.0'
VERSION = '1.5.1'
ISSUE_URL = "https://github.com/Limych/ha-average/issues"
2 changes: 2 additions & 0 deletions custom_components/average/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

ATTR_START = "start"
ATTR_END = "end"
ATTR_SOURCES = "sources"
ATTR_COUNT_SOURCES = "count_sources"
ATTR_AVAILABLE_SOURCES = "available_sources"
ATTR_COUNT = "count"
Expand All @@ -26,6 +27,7 @@
ATTR_TO_PROPERTY = [
ATTR_START,
ATTR_END,
ATTR_SOURCES,
ATTR_COUNT_SOURCES,
ATTR_AVAILABLE_SOURCES,
ATTR_COUNT,
Expand Down
10 changes: 6 additions & 4 deletions custom_components/average/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import voluptuous as vol
from homeassistant.components import history
from homeassistant.components.climate import ClimateDevice
from homeassistant.components.group import expand_entity_ids
from homeassistant.components.water_heater import WaterHeaterDevice
from homeassistant.components.weather import WeatherEntity
from homeassistant.const import (
Expand Down Expand Up @@ -138,14 +139,15 @@ def __init__(
self._end_template = end
self._duration = duration
self._period = self.start = self.end = None
self._entity_ids = entity_ids
self._precision = precision
self._undef = undef
self._state = None
self._unit_of_measurement = None
self._icon = None
self._temperature_mode = None
self.count_sources = len(self._entity_ids)

self.sources = expand_entity_ids(hass, entity_ids)
self.count_sources = len(self.sources)
self.available_sources = 0
self.count = 0
self.min_value = self.max_value = None
Expand Down Expand Up @@ -218,7 +220,7 @@ def sensor_startup(event):
self.async_schedule_update_ha_state(True)
else:
async_track_state_change(
self._hass, self._entity_ids, sensor_state_listener
self._hass, self.sources, sensor_state_listener
)
sensor_state_listener(None, None, None)

Expand Down Expand Up @@ -419,7 +421,7 @@ def _update_state(self): # pylint: disable=r0914,r0912,r0915
self.min_value = self.max_value = None

# pylint: disable=too-many-nested-blocks
for entity_id in self._entity_ids:
for entity_id in self.sources:
_LOGGER.debug('Processing entity "%s"', entity_id)

entity = self._hass.states.get(entity_id)
Expand Down
27 changes: 15 additions & 12 deletions script/version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@

_LOGGER = logging.getLogger(__name__)

VERSION = "1.1.2"

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

sys.path.append(ROOT)


def fallback_version(localpath):
"""Return version from regex match."""
return_value = ""
if os.path.isfile(localpath):
with open(localpath) as local:
ret = re.compile(r"^\b(VERSION|__version__)\s*=\s*['\"](.*)['\"]")
for line in local.readlines():
matcher = ret.match(line)
if matcher:
return_value = str(matcher.group(2))
return return_value
for fname in ("__init__", "const"):
fpath = f"{localpath}/{fname}.py"
if os.path.isfile(fpath):
with open(fpath) as local:
ret = re.compile(r"^\b(VERSION|__version__)\s*=\s*['\"](.*)['\"]")
for line in local.readlines():
matcher = ret.match(line)
if matcher:
return str(matcher.group(2))
return ""


def get_package_version(localpath, package):
"""Return the local version if any."""
_LOGGER.debug("Started for %s (%s)", localpath, package)
return_value = ""
if os.path.isfile(localpath):
if os.path.isfile(f"{localpath}/__init__.py"):
try:
name = "__version__"
return_value = getattr(__import__(f"..{package}", fromlist=[name]), name)
Expand Down Expand Up @@ -178,7 +181,7 @@ def write_version(package_path, version, dry_run=False):
def main():
"""Execute script."""
parser = argparse.ArgumentParser(
description="Bump version of Home Assistant custom component"
description=f"Bump version of Python package. Version {VERSION}"
)
parser.add_argument(
"type",
Expand Down Expand Up @@ -222,7 +225,7 @@ def main():
package_dir = f"{ROOT}/custom_components/{package}"
package = f"custom_components.{package}"

current = Version(get_package_version(f"{package_dir}/__init__.py", package))
current = Version(get_package_version(package_dir, package))
bumped = bump_version(current, arguments.type)
assert bumped > current, "BUG! New version is not newer than old version"

Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ exclude =

[mypy]
ignore_missing_imports = True

[semantic_release]
version_variable=custom_components/average/__init__.py:VERSION
upload_to_pypi=false
upload_to_release=false

0 comments on commit faaedab

Please sign in to comment.