Skip to content

Commit

Permalink
0.1.12 (#43)
Browse files Browse the repository at this point in the history
* [#33] Dockerhub 'latest' tag is currently published only if the release is created in the main branch. (#39)

* [#33] Dockerhub 'latest' tag is currently published only if the release is created in the main branch.

* [#33] Dockerhub 'latest' tag is currently published only if the release is created in the main branch.

* [#33] Dockerhub 'latest' tag is currently published only if the release is created in the main branch.

---------

Co-authored-by: Stéphane Senart <>

* [#36] Error if HA endpoint configuration is missing in configuration.yaml. (#40)

* [#36] Error if HA endpoint configuration is missing in configuration.yaml

* [#36] Error if HA endpoint configuration is missing in configuration.yaml

---------

Co-authored-by: Stéphane Senart <>

* [#38] Using the HA addon, the PCE identifier is transformed into another number. (#41)

* [#38] Using the HA addon, the PCE identifier is transformed into another number.

* [#38] Using the HA addon, the PCE identifier is transformed into another number.

---------

Co-authored-by: Stéphane Senart <>

* [#37] Error GrDF send missing data with type="Absence de Données". (#42)

Co-authored-by: Stéphane Senart <>
  • Loading branch information
ssenart authored Jan 15, 2025
1 parent 7071fb8 commit e693d0e
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 41 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
required: false
default: ""
type: string
is_final:
description: "It is a final release (not a pre-release)"
required: false
default: true
type: boolean

permissions:
contents: write # Allow to commit and push.
Expand Down Expand Up @@ -85,8 +90,8 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y gettext-base

#----------------------------------------------
# Replace version in pyproject.toml, config.yaml and build.yaml
- name: Replace version
# Bump version in pyproject.toml, config.yaml and build.yaml
- name: Bump version
run: |
envsubst < pyproject.template.toml > pyproject.toml
envsubst < addons/gazpar2haws/config.yaml.template > addons/gazpar2haws/config.yaml
Expand All @@ -100,7 +105,7 @@ jobs:
git config --global user.name github-actions
git config --global user.email github-actions@github.com
git add pyproject.toml addons/gazpar2haws/config.yaml addons/gazpar2haws/build.yaml
git commit --allow-empty -m "Upgrade version to ${PACKAGE_VERSION}"
git commit --allow-empty -m "Bump version to ${PACKAGE_VERSION}"
git push
#----------------------------------------------
Expand Down Expand Up @@ -210,5 +215,6 @@ jobs:
with:
image: ssenart/gazpar2haws
version: ${{ needs.prepare.outputs.package-version }}
is_latest : ${{ inputs.is_final }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
16 changes: 11 additions & 5 deletions .github/workflows/publish-to-dockerhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
required: false
default: ""
type: string
is_latest:
description: "Update the 'latest' tag"
required: false
default: true
type: boolean

permissions:
contents: read # Readonly permissions
Expand All @@ -17,9 +22,9 @@ env:

jobs:
#----------------------------------------------
# Collect information
information:
name: Collect information
# Prepare
prepare:
name: Prepare
outputs:
package-version: ${{ steps.select-package-version.outputs.package-version }}
default_python_version: ${{ env.DEFAULT_PYTHON_VERSION }}
Expand Down Expand Up @@ -66,7 +71,7 @@ jobs:
# Publish Docker image to DockerHub
publish-to-dockerhub:
name: Publish to DockerHub
needs: information
needs: prepare
runs-on: ubuntu-latest
permissions:
packages: write
Expand All @@ -85,6 +90,7 @@ jobs:
uses: ./.github/workflows/publish-to-dockerhub
with:
image: ssenart/gazpar2haws
version: ${{ needs.information.outputs.package-version }}
version: ${{ needs.prepare.outputs.package-version }}
is_latest: ${{ inputs.is_latest }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
6 changes: 5 additions & 1 deletion .github/workflows/publish-to-dockerhub/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
version:
description: "Version of the image"
required: true
is_latest:
description: "Whether the version is a final release"
required: false
default: false
username:
description: "DockerHub username"
required: true
Expand Down Expand Up @@ -39,7 +43,7 @@ runs:
images: ${{ inputs.image }}
tags: |
# Set latest tag for the default branch
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ inputs.is_latest }}
# Set the version tag for all branches
type=raw,value=${{ inputs.version }}
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.12] - 2025-01-15

### Fixed

[#37](https://github.com/ssenart/gazpar2haws/issues/37): Error GrDF send missing data with type="Absence de Données".

[#38](https://github.com/ssenart/gazpar2haws/issues/38): Using the HA addon, the PCE identifier is transformed into another number.

[#36](https://github.com/ssenart/gazpar2haws/issues/36): Error if HA endpoint configuration is missing in configuration.yaml.

### Added

[#33](https://github.com/ssenart/gazpar2haws/issues/33): Dockerhub 'latest' tag is currently published only if the release is created in the main branch.

## [0.1.11] - 2025-01-12

### Fixed
Expand Down
20 changes: 10 additions & 10 deletions addons/gazpar2haws/rootfs/app/config/configuration.template.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
logging:
file: log/gazpar2haws.log
console: true
console: true
level: debug
format: '%(asctime)s %(levelname)s [%(name)s] %(message)s'
format: "%(asctime)s %(levelname)s [%(name)s] %(message)s"

grdf:
scan_interval: ${GRDF_SCAN_INTERVAL} # Number of minutes between each data retrieval (0 means no scan: a single data retrieval at startup, then stops).
devices:
- name: gazpar2haws # Name of the device in home assistant. It will be used as the entity_id: sensor.${name}.
username: "!secret grdf.username"
password: "!secret grdf.password"
pce_identifier: "!secret grdf.pce_identifier"
timezone: ${GRDF_TIMEZONE} # Timezone of the data. It should be the same as the Home Assistant timezone.
last_days: ${GRDF_LAST_DAYS} # Number of days of data to retrieve
reset: false # If true, the data will be reset before the first data retrieval. If false, the data will be kept and new data will be added.
- name: gazpar2haws # Name of the device in home assistant. It will be used as the entity_id: sensor.${name}.
username: "!secret grdf.username"
password: "!secret grdf.password"
pce_identifier: "!secret grdf.pce_identifier"
timezone: "${GRDF_TIMEZONE}" # Timezone of the data. It should be the same as the Home Assistant timezone.
last_days: ${GRDF_LAST_DAYS} # Number of days of data to retrieve
reset: false # If true, the data will be reset before the first data retrieval. If false, the data will be kept and new data will be added.

homeassistant:
host: "!secret homeassistant.host"
port: "!secret homeassistant.port"
endpoint: ${HOMEASSISTANT_ENDPOINT}
endpoint: "${HOMEASSISTANT_ENDPOINT}" # The websocket endpoint to use. It should be /api/websocket by default.
token: "!secret homeassistant.token"
12 changes: 6 additions & 6 deletions addons/gazpar2haws/rootfs/app/config/secrets.template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
grdf.username: ${GRDF_USERNAME}
grdf.password: ${GRDF_PASSWORD}
grdf.pce_identifier: ${GRDF_PCE_IDENTIFIER}
grdf.username: "${GRDF_USERNAME}"
grdf.password: "${GRDF_PASSWORD}"
grdf.pce_identifier: "${GRDF_PCE_IDENTIFIER}"

homeassistant.host: ${HOMEASSISTANT_HOST}
homeassistant.port: ${HOMEASSISTANT_PORT}
homeassistant.token: ${HOMEASSISTANT_TOKEN}
homeassistant.host: "${HOMEASSISTANT_HOST}"
homeassistant.port: "${HOMEASSISTANT_PORT}"
homeassistant.token: "${HOMEASSISTANT_TOKEN}"
14 changes: 7 additions & 7 deletions config/secrets.template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
grdf.username: ${GRDF_USERNAME}
grdf.password: ${GRDF_PASSWORD}
grdf.pce_identifier: ${GRDF_PCE_IDENTIFIER}

homeassistant.host: ${HOMEASSISTANT_HOST}
homeassistant.port: ${HOMEASSISTANT_PORT}
homeassistant.token: ${HOMEASSISTANT_TOKEN}
grdf.username: "${GRDF_USERNAME}"
grdf.password: "${GRDF_PASSWORD}"
grdf.pce_identifier: "${GRDF_PCE_IDENTIFIER}"

homeassistant.host: "${HOMEASSISTANT_HOST}"
homeassistant.port: "${HOMEASSISTANT_PORT}"
homeassistant.token: "${HOMEASSISTANT_TOKEN}"
25 changes: 23 additions & 2 deletions gazpar2haws/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,40 @@ class Bridge:
def __init__(self, config: config_utils.ConfigLoader):

# GrDF scan interval (in seconds)
if config.get("grdf.scan_interval") is None:
raise ValueError("Configuration parameter 'grdf.scan_interval' is missing")
self._grdf_scan_interval = int(config.get("grdf.scan_interval"))

# Home Assistant configuration
# Home Assistant configuration: host
if config.get("homeassistant.host") is None:
raise ValueError("Configuration parameter 'homeassistant.host' is missing")
ha_host = config.get("homeassistant.host")

# Home Assistant configuration: port
if config.get("homeassistant.port") is None:
raise ValueError("Configuration parameter 'homeassistant.port' is missing")
ha_port = config.get("homeassistant.port")
ha_endpoint = config.get("homeassistant.endpoint")

# Home Assistant configuration: endpoint
ha_endpoint = (
config.get("homeassistant.endpoint")
if config.get("homeassistant.endpoint")
else "/api/websocket"
)

# Home Assistant configuration: token
if config.get("homeassistant.token") is None:
raise ValueError("Configuration parameter 'homeassistant.token' is missing")
ha_token = config.get("homeassistant.token")

# Initialize Home Assistant
self._homeassistant = HomeAssistantWS(ha_host, ha_port, ha_endpoint, ha_token)

# Initialize Gazpar
self._gazpar = []

if config.get("grdf.devices") is None:
raise ValueError("Configuration parameter 'grdf.devices' is missing")
for grdf_device_config in config.get("grdf.devices"):
self._gazpar.append(Gazpar(grdf_device_config, self._homeassistant))

Expand Down
58 changes: 54 additions & 4 deletions gazpar2haws/gazpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,59 @@ def __init__(self, config: dict[str, Any], homeassistant: HomeAssistantWS):

self._homeassistant = homeassistant

# GrDF configuration
# GrDF configuration: name
if config.get("name") is None:
raise ValueError("Configuration parameter 'grdf.devices[].name' is missing")
self._name = config.get("name")
self._data_source = config.get("data_source")

# GrDF configuration: data source
self._data_source = (
config.get("data_source") if config.get("data_source") else "json"
)

# GrDF configuration: username
if self._data_source != "test" and config.get("username") is None:
raise ValueError(
"Configuration parameter 'grdf.devices[].username' is missing"
)
self._username = config.get("username")

# GrDF configuration: password
if self._data_source != "test" and config.get("password") is None:
raise ValueError(
"Configuration parameter 'grdf.devices[].password' is missing"
)
self._password = config.get("password")

# GrDF configuration: pce_identifier
if self._data_source != "test" and config.get("pce_identifier") is None:
raise ValueError(
"Configuration parameter 'grdf.devices[].pce_identifier' is missing"
)
self._pce_identifier = str(config.get("pce_identifier"))
self._tmp_dir = config.get("tmp_dir")

# GrDF configuration: tmp_dir
self._tmp_dir = config.get("tmp_dir") if config.get("tmp_dir") else "/tmp"

# GrDF configuration: last_days
if config.get("last_days") is None:
raise ValueError(
"Configuration parameter 'grdf.devices[].last_days' is missing"
)
self._last_days = int(str(config.get("last_days")))

# GrDF configuration: timezone
if config.get("timezone") is None:
raise ValueError(
"Configuration parameter 'grdf.devices[].timezone' is missing"
)
self._timezone = str(config.get("timezone"))

# GrDF configuration: reset
if config.get("reset") is None:
raise ValueError(
"Configuration parameter 'grdf.devices[].reset' is missing"
)
self._reset = bool(config.get("reset"))

# As of date: YYYY-MM-DD
Expand Down Expand Up @@ -129,7 +173,13 @@ async def _publish_entity(
continue

# Compute the total volume and energy
total += reading[property_name]
if reading[property_name] is not None:
total += reading[property_name]
else:
Logger.warning(
f"Missing property {property_name} for date {date}. Skipping..."
)
continue

statistics.append({"start": date.isoformat(), "state": total, "sum": total})

Expand Down
1 change: 0 additions & 1 deletion tests/config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ grdf:
homeassistant:
host: "!secret homeassistant.host"
port: "!secret homeassistant.port"
endpoint: "/api/websocket"
token: "!secret homeassistant.token"
6 changes: 5 additions & 1 deletion tests/test_gazpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def setup_method(self): # pylint: disable=R0801

ha_host = self._config.get("homeassistant.host")
ha_port = self._config.get("homeassistant.port")
ha_endpoint = self._config.get("homeassistant.endpoint")
ha_endpoint = (
self._config.get("homeassistant.endpoint")
if self._config.get("homeassistant.endpoint")
else "/api/websocket"
)
ha_token = self._config.get("homeassistant.token")

self._haws = HomeAssistantWS( # pylint: disable=W0201
Expand Down
6 changes: 5 additions & 1 deletion tests/test_haws.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def setup_method(self):

ha_host = self._config.get("homeassistant.host")
ha_port = self._config.get("homeassistant.port")
ha_endpoint = self._config.get("homeassistant.endpoint")
ha_endpoint = (
self._config.get("homeassistant.endpoint")
if self._config.get("homeassistant.endpoint")
else "/api/websocket"
)
ha_token = self._config.get("homeassistant.token")

self._haws = HomeAssistantWS( # pylint: disable=W0201
Expand Down

0 comments on commit e693d0e

Please # to comment.