gazpar2haws 0.1.1__py3-none-any.whl → 0.1.2__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 CHANGED
@@ -4,10 +4,21 @@ 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.1] - 2024-12-22
7
+ ## [0.1.2] - 2024-12-30
8
8
 
9
9
  ### Added
10
+ [#2](https://github.com/ssenart/gazpar2haws/issues/2): DockerHub deployment.
11
+
12
+ ### Fixed
13
+ [#9](https://github.com/ssenart/gazpar2haws/issues/9): Incorrect timezone info creates duplicate import.
14
+
15
+ [#6](https://github.com/ssenart/gazpar2haws/issues/6): The last meter value may be imported multiple times and cause the today value being wrong.
16
+
17
+ [#3](https://github.com/ssenart/gazpar2haws/issues/3): reset=false makes the meter import to restart from zero.
10
18
 
19
+ ## [0.1.1] - 2024-12-22
20
+
21
+ ### Added
11
22
  [#1](https://github.com/ssenart/gazpar2haws/issues/1): Publish energy indicator in kWh.
12
23
 
13
24
  ## [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 statistics from GrDF
67
+ # Get the last statistic from Home Assistant
68
68
  try:
69
- last_statistics = await self._homeassistant.get_last_statistic(entity_id)
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(last_statistics.get("end") / 1000)
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 = 0
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.1
3
+ Version: 0.1.2
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
@@ -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=2Xv5NYFt0BQy7NAAQPDHKb4OTsPaz5qF_2UDK5VP4a8,447
1
+ CHANGELOG.md,sha256=ViL-BtLOsttdVoe_XUsE8CPmI1Unpb9d-YRFsUMJaYo,946
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=mC2yDvb22sGjA4c3Gj0sPXEyLKnSNi6WGbVG2HOkD-A,5285
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.1.dist-info/LICENSE,sha256=G6JttcnlwcRHYzIcDflSGOVrHTtaP3BEegM2lH00xHw,1094
10
- gazpar2haws-0.1.1.dist-info/METADATA,sha256=QcSwzAfhXOngs180kR2n4FAoA6RcvCIETBR2uDRUXVY,3965
11
- gazpar2haws-0.1.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
- gazpar2haws-0.1.1.dist-info/RECORD,,
9
+ gazpar2haws-0.1.2.dist-info/LICENSE,sha256=G6JttcnlwcRHYzIcDflSGOVrHTtaP3BEegM2lH00xHw,1094
10
+ gazpar2haws-0.1.2.dist-info/METADATA,sha256=1duww4kuumkMKGB1XufxPyjClZmmkSA8QnrbheRoB7M,7359
11
+ gazpar2haws-0.1.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
+ gazpar2haws-0.1.2.dist-info/RECORD,,