gazpar2haws 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CHANGELOG.md +17 -1
- gazpar2haws/gazpar.py +19 -10
- {gazpar2haws-0.1.1.dist-info → gazpar2haws-0.1.3.dist-info}/METADATA +115 -2
- {gazpar2haws-0.1.1.dist-info → gazpar2haws-0.1.3.dist-info}/RECORD +6 -6
- {gazpar2haws-0.1.1.dist-info → gazpar2haws-0.1.3.dist-info}/LICENSE +0 -0
- {gazpar2haws-0.1.1.dist-info → gazpar2haws-0.1.3.dist-info}/WHEEL +0 -0
CHANGELOG.md
CHANGED
@@ -4,10 +4,26 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [0.1.
|
7
|
+
## [0.1.3] - 2025-01-03
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
[#11](https://github.com/ssenart/gazpar2haws/issues/11): Upgrade PyGazpar version to 1.2.6.
|
11
|
+
|
12
|
+
## [0.1.2] - 2024-12-30
|
8
13
|
|
9
14
|
### Added
|
15
|
+
[#2](https://github.com/ssenart/gazpar2haws/issues/2): DockerHub deployment.
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
[#9](https://github.com/ssenart/gazpar2haws/issues/9): Incorrect timezone info creates duplicate import.
|
19
|
+
|
20
|
+
[#6](https://github.com/ssenart/gazpar2haws/issues/6): The last meter value may be imported multiple times and cause the today value being wrong.
|
10
21
|
|
22
|
+
[#3](https://github.com/ssenart/gazpar2haws/issues/3): reset=false makes the meter import to restart from zero.
|
23
|
+
|
24
|
+
## [0.1.1] - 2024-12-22
|
25
|
+
|
26
|
+
### Added
|
11
27
|
[#1](https://github.com/ssenart/gazpar2haws/issues/1): Publish energy indicator in kWh.
|
12
28
|
|
13
29
|
## [0.1.0] - 2024-12-21
|
gazpar2haws/gazpar.py
CHANGED
@@ -64,25 +64,33 @@ class Gazpar:
|
|
64
64
|
raise Exception(errorMessage)
|
65
65
|
|
66
66
|
if exists_statistic_id:
|
67
|
-
# Get last
|
67
|
+
# Get the last statistic from Home Assistant
|
68
68
|
try:
|
69
|
-
|
69
|
+
last_statistic = await self._homeassistant.get_last_statistic(entity_id)
|
70
70
|
except Exception:
|
71
71
|
errorMessage = f"Error while fetching last statistics from Home Assistant: {traceback.format_exc()}"
|
72
72
|
Logger.warning(errorMessage)
|
73
73
|
raise Exception(errorMessage)
|
74
74
|
|
75
75
|
# Extract the end date of the last statistics from the unix timestamp
|
76
|
-
last_date = datetime.fromtimestamp(
|
76
|
+
last_date = datetime.fromtimestamp(last_statistic.get("start") / 1000, tz=pytz.timezone(self._timezone))
|
77
77
|
|
78
78
|
# Compute the number of days since the last statistics
|
79
|
-
last_days = (datetime.now() - last_date).days
|
79
|
+
last_days = (datetime.now(tz=pytz.timezone(self._timezone)) - last_date).days
|
80
|
+
|
81
|
+
# Get the last meter value
|
82
|
+
last_value = last_statistic.get("sum")
|
80
83
|
else:
|
81
84
|
# If the sensor does not exist in Home Assistant, fetch the last days defined in the configuration
|
82
85
|
last_days = self._last_days
|
83
86
|
|
84
87
|
# Compute the corresponding last_date
|
85
|
-
last_date = datetime.now() - timedelta(days=last_days)
|
88
|
+
last_date = datetime.now(tz=pytz.timezone(self._timezone)) - timedelta(days=last_days)
|
89
|
+
|
90
|
+
# If no statistic, the last value is initialized to zero
|
91
|
+
last_value = 0
|
92
|
+
|
93
|
+
Logger.debug(f"Last date: {last_date}, last days: {last_days}, last value: {last_value}")
|
86
94
|
|
87
95
|
# Initialize PyGazpar client
|
88
96
|
client = pygazpar.Client(pygazpar.JsonWebDataSource(username=self._username, password=self._password))
|
@@ -100,18 +108,19 @@ class Gazpar:
|
|
100
108
|
# Compute and fill statistics.
|
101
109
|
daily = data.get(pygazpar.Frequency.DAILY.value)
|
102
110
|
statistics = []
|
103
|
-
total =
|
111
|
+
total = last_value
|
104
112
|
for reading in daily:
|
105
113
|
# Parse date format DD/MM/YYYY into datetime.
|
106
114
|
date = datetime.strptime(reading[pygazpar.PropertyName.TIME_PERIOD.value], "%d/%m/%Y")
|
107
115
|
|
108
|
-
# Skip all readings before the last statistic date.
|
109
|
-
if date.date() < last_date.date():
|
110
|
-
continue
|
111
|
-
|
112
116
|
# Set the timezone
|
113
117
|
date = timezone.localize(date)
|
114
118
|
|
119
|
+
# Skip all readings before the last statistic date.
|
120
|
+
if date <= last_date:
|
121
|
+
Logger.debug(f"Skip date: {date} <= {last_date}")
|
122
|
+
continue
|
123
|
+
|
115
124
|
# Compute the total volume and energy
|
116
125
|
total += reading[property_name]
|
117
126
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: gazpar2haws
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: Gazpar2HAWS is a gateway that reads data history from the GrDF (French gas provider) meter and send it to Home Assistant using WebSocket interface
|
5
5
|
License: MIT
|
6
6
|
Author: Stéphane Senart
|
@@ -9,7 +9,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
10
10
|
Classifier: Programming Language :: Python :: 3.12
|
11
11
|
Classifier: Programming Language :: Python :: 3.13
|
12
|
-
Requires-Dist: pygazpar (
|
12
|
+
Requires-Dist: pygazpar (>=1.2.6,<2.0.0)
|
13
13
|
Requires-Dist: pytest-asyncio (>=0.25.0,<0.26.0)
|
14
14
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
15
15
|
Requires-Dist: websockets (>=14.1,<15.0)
|
@@ -58,6 +58,68 @@ $ pip install gazpar2haws
|
|
58
58
|
|
59
59
|
```
|
60
60
|
|
61
|
+
### 3. Using Dockerfile
|
62
|
+
|
63
|
+
The following steps permit to build the Docker image based on the local source files.
|
64
|
+
|
65
|
+
1. Clone the repo locally:
|
66
|
+
```sh
|
67
|
+
$ cd /path/to/my_install_folder/
|
68
|
+
|
69
|
+
$ git clone https://github.com/ssenart/gazpar2haws.git
|
70
|
+
```
|
71
|
+
2. Edit the docker-compose.yaml file by setting the environment variables corresponding to your GrDF account and Home Assistant setup:
|
72
|
+
|
73
|
+
```yaml
|
74
|
+
environment:
|
75
|
+
- GRDF_USERNAME=<GrDF account username>
|
76
|
+
- GRDF_PASSWORD=<GrDF account password>
|
77
|
+
- GRDF_PCE_IDENTIFIER=<GrDF PCE meter identifier>
|
78
|
+
- HOMEASSISTANT_HOST=<Home Assistant instance host name>
|
79
|
+
- HOMEASSISTANT_PORT=<Home Assistant instance port number>
|
80
|
+
- HOMEASSISTANT_TOKEN=<Home Assistant access token>
|
81
|
+
```
|
82
|
+
3. Build the image:
|
83
|
+
```sh
|
84
|
+
$ docker compose -f docker/docker-compose.yaml build
|
85
|
+
```
|
86
|
+
4. Run the container:
|
87
|
+
```sh
|
88
|
+
$ docker compose -f docker/docker-compose.yaml up -d
|
89
|
+
```
|
90
|
+
|
91
|
+
### 4. Using Docker Hub
|
92
|
+
|
93
|
+
The following steps permits to run a container from an existing image available in the Docker Hub repository.
|
94
|
+
|
95
|
+
1. Copy and save the following docker-compose.yaml file:
|
96
|
+
|
97
|
+
```yaml
|
98
|
+
services:
|
99
|
+
gazpar2haws:
|
100
|
+
image: ssenart/gazpar2haws:latest
|
101
|
+
container_name: gazpar2haws
|
102
|
+
restart: unless-stopped
|
103
|
+
network_mode: bridge
|
104
|
+
user: "1000:1000"
|
105
|
+
volumes:
|
106
|
+
- ./gazpar2haws/config:/app/config
|
107
|
+
- ./gazpar2haws/log:/app/log
|
108
|
+
environment:
|
109
|
+
- GRDF_USERNAME=<GrDF account username>
|
110
|
+
- GRDF_PASSWORD=<GrDF account password>
|
111
|
+
- GRDF_PCE_IDENTIFIER=<GrDF PCE meter identifier>
|
112
|
+
- HOMEASSISTANT_HOST=<Home Assistant instance host name>
|
113
|
+
- HOMEASSISTANT_TOKEN=<Home Assistant access token>
|
114
|
+
```
|
115
|
+
|
116
|
+
Edit the environment variable section according to your setup.
|
117
|
+
|
118
|
+
2. Run the container:
|
119
|
+
```sh
|
120
|
+
$ docker compose up -d
|
121
|
+
```
|
122
|
+
|
61
123
|
## Usage
|
62
124
|
|
63
125
|
### Command line
|
@@ -136,6 +198,57 @@ They may be created using the following templates:
|
|
136
198
|
|
137
199
|
```
|
138
200
|
|
201
|
+
### Environment variable for Docker
|
202
|
+
|
203
|
+
In a Docker environment, the configurations files are instantiated by replacing the environment variables below in the template files:
|
204
|
+
|
205
|
+
| Environment variable | Description | Required | Default value |
|
206
|
+
|---|---|---|---|
|
207
|
+
| GRDF_USERNAME | GrDF account user name | Yes | - |
|
208
|
+
| GRDF_PASSWORD | GrDF account password (avoid using special characters) | Yes | - |
|
209
|
+
| GRDF_PCE_IDENTIFIER | GrDF meter PCE identifier | Yes | - |
|
210
|
+
| GRDF_SCAN_INTERVAL | Period in minutes to refresh meter data (0 means one single refresh and stop) | No | 480 (8 hours) |
|
211
|
+
| GRDF_LAST_DAYS | Number of days of history data to retrieve | No | 1095 (3 years) |
|
212
|
+
| HOMEASSISTANT_HOST | Home Assistant instance host name | Yes | - |
|
213
|
+
| HOMEASSISTANT_PORT | Home Assistant instance port number | No | 8123 |
|
214
|
+
| HOMEASSISTANT_TOKEN | Home Assistant access token | Yes | - |
|
215
|
+
|
216
|
+
You can setup them directly in a docker-compose.yaml file (environment section) or from a Docker command line (-e option).
|
217
|
+
|
218
|
+
## Publish a new image on Docker Hub
|
219
|
+
|
220
|
+
1. List all local images
|
221
|
+
|
222
|
+
```sh
|
223
|
+
$ docker image ls
|
224
|
+
```
|
225
|
+
|
226
|
+
2. Build a new local image
|
227
|
+
|
228
|
+
```sh
|
229
|
+
$ docker compose -f docker/docker-compose.yaml build
|
230
|
+
```
|
231
|
+
|
232
|
+
3. Tag the new built image with the version number
|
233
|
+
|
234
|
+
```sh
|
235
|
+
$ docker image tag ssenart/gazpar2haws:latest ssenart/gazpar2haws:0.1.2
|
236
|
+
```
|
237
|
+
|
238
|
+
4. Login in Docker Hub
|
239
|
+
|
240
|
+
```sh
|
241
|
+
$ docker login
|
242
|
+
```
|
243
|
+
|
244
|
+
5. Push all the tagged local images to Docker Hub
|
245
|
+
|
246
|
+
```sh
|
247
|
+
$ docker push --all-tags ssenart/gazpar2haws
|
248
|
+
```
|
249
|
+
|
250
|
+
All the gazpar2haws images are available [here](https://hub.docker.com/repository/docker/ssenart/gazpar2haws/general).
|
251
|
+
|
139
252
|
## Contributing
|
140
253
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
141
254
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
CHANGELOG.md,sha256=
|
1
|
+
CHANGELOG.md,sha256=mVzDLcrktC232keeqp1qwQTqQ7jYuC3xGZ4vTCbd-L0,1081
|
2
2
|
gazpar2haws/__init__.py,sha256=yzol8uZSBI7pIRGUmYJ6-vRBwkM4MI3IGf5cQpNsaFw,57
|
3
3
|
gazpar2haws/__main__.py,sha256=g8xk0x_kprBHKHLzgf9y9EY2_gKC9V3k4z0n-EDTd-I,3253
|
4
4
|
gazpar2haws/bridge.py,sha256=TiPmvRBxzgwOKKmWNXMOaP0pLg-Wls_SmiwHczNEM_4,3466
|
5
5
|
gazpar2haws/config_utils.py,sha256=D0lu-3KY-vLEyD2vDN05UABkMnpMJjqw1RuDJVrkGFs,2123
|
6
|
-
gazpar2haws/gazpar.py,sha256=
|
6
|
+
gazpar2haws/gazpar.py,sha256=8yrMzs9HfMSgq3HPeJs64SHWb5RWm7ZL3tgfzhlwHFQ,5754
|
7
7
|
gazpar2haws/haws.py,sha256=SiVM5QTANMmUq66IAsFn68jwej-Rdpqg6dIqTeTadmw,6765
|
8
8
|
gazpar2haws/version.py,sha256=ebdTNl4h0hNKmN3Gbs592VJsYbMmrkB47WyZMJevaQo,86
|
9
|
-
gazpar2haws-0.1.
|
10
|
-
gazpar2haws-0.1.
|
11
|
-
gazpar2haws-0.1.
|
12
|
-
gazpar2haws-0.1.
|
9
|
+
gazpar2haws-0.1.3.dist-info/LICENSE,sha256=G6JttcnlwcRHYzIcDflSGOVrHTtaP3BEegM2lH00xHw,1094
|
10
|
+
gazpar2haws-0.1.3.dist-info/METADATA,sha256=nehgHbI4QeWEpAMQ383dUerc8u1l5ufj9tEoBTg1t7o,7366
|
11
|
+
gazpar2haws-0.1.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
12
|
+
gazpar2haws-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|