gazpar2haws 0.2.0a20__tar.gz → 0.2.1__tar.gz
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.
- gazpar2haws-0.2.1/CHANGELOG.md +126 -0
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/PKG-INFO +39 -34
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/README.md +38 -33
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/gazpar2haws/__main__.py +104 -91
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/gazpar2haws/bridge.py +32 -6
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/gazpar2haws/config_utils.py +61 -56
- gazpar2haws-0.2.1/gazpar2haws/gazpar.py +280 -0
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/gazpar2haws/haws.py +85 -32
- gazpar2haws-0.2.1/gazpar2haws/version.py +3 -0
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/pyproject.toml +1 -1
- gazpar2haws-0.2.0a20/CHANGELOG.md +0 -60
- gazpar2haws-0.2.0a20/gazpar2haws/gazpar.py +0 -139
- gazpar2haws-0.2.0a20/gazpar2haws/version.py +0 -3
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/LICENSE +0 -0
- {gazpar2haws-0.2.0a20 → gazpar2haws-0.2.1}/gazpar2haws/__init__.py +0 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [0.2.1] - 2025-01-24
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
[#57](https://github.com/ssenart/gazpar2haws/issues/57): The addon configuration is the wrong format (still the old one).
|
13
|
+
|
14
|
+
## [0.2.0] - 2025-01-23
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
[#55](https://github.com/ssenart/gazpar2haws/issues/55): Change HA addon configuration format to match gazpar2haws file configuration format.
|
19
|
+
|
20
|
+
## [0.1.14] - 2025-01-17
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
[#50](https://github.com/ssenart/gazpar2haws/issues/50): In dockerhub, version displayed in log file is wrong and always N-1.
|
25
|
+
|
26
|
+
## [0.1.13] - 2025-01-16
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
|
30
|
+
[#47](https://github.com/ssenart/gazpar2haws/issues/47): 'reset' configuration parameter is ignored in the addon configuration panel.
|
31
|
+
|
32
|
+
## [0.1.12] - 2025-01-15
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
[#37](https://github.com/ssenart/gazpar2haws/issues/37): Error GrDF send missing data with type="Absence de Données".
|
37
|
+
|
38
|
+
[#38](https://github.com/ssenart/gazpar2haws/issues/38): Using the HA addon, the PCE identifier is transformed into another number.
|
39
|
+
|
40
|
+
[#36](https://github.com/ssenart/gazpar2haws/issues/36): Error if HA endpoint configuration is missing in configuration.yaml.
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
44
|
+
[#33](https://github.com/ssenart/gazpar2haws/issues/33): Dockerhub 'latest' tag is currently published only if the release is created in the main branch.
|
45
|
+
|
46
|
+
## [0.1.11] - 2025-01-12
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
|
50
|
+
[#32](https://github.com/ssenart/gazpar2haws/issues/32): Fix fatal happening after introducing as_of_date for tests.
|
51
|
+
|
52
|
+
## [0.1.10] - 2025-01-11
|
53
|
+
|
54
|
+
### Fixed
|
55
|
+
|
56
|
+
[#28](https://github.com/ssenart/gazpar2haws/issues/28): Fix the code lint warning messages.
|
57
|
+
|
58
|
+
### Added
|
59
|
+
|
60
|
+
[#27](https://github.com/ssenart/gazpar2haws/issues/27): In a Github workflow, run unit tests against a HA container.
|
61
|
+
|
62
|
+
## [0.1.9] - 2025-01-10
|
63
|
+
|
64
|
+
### Fixed
|
65
|
+
|
66
|
+
[#26](https://github.com/ssenart/gazpar2haws/issues/26): Fix broken HA addons update.
|
67
|
+
|
68
|
+
## [0.1.8] - 2025-01-10
|
69
|
+
|
70
|
+
### Added
|
71
|
+
|
72
|
+
[#20](https://github.com/ssenart/gazpar2haws/issues/20): Automate build, package, publish with Github Actions.
|
73
|
+
|
74
|
+
## [0.1.7] - 2025-01-05
|
75
|
+
|
76
|
+
### Fixed
|
77
|
+
|
78
|
+
[#18](https://github.com/ssenart/gazpar2haws/issues/18): Regression on DockerHub deployment.
|
79
|
+
|
80
|
+
## [0.1.6] - 2025-01-05
|
81
|
+
|
82
|
+
### Added
|
83
|
+
|
84
|
+
[#4](https://github.com/ssenart/gazpar2haws/issues/4): Deploy gazpar2haws as an HA add-on.
|
85
|
+
|
86
|
+
## [0.1.5] - 2025-01-04
|
87
|
+
|
88
|
+
### Added
|
89
|
+
|
90
|
+
[#15](https://github.com/ssenart/gazpar2haws/issues/15): Using HassIO, websocket endpoint is /core/websocket.
|
91
|
+
|
92
|
+
## [0.1.4] - 2025-01-04
|
93
|
+
|
94
|
+
### Fixed
|
95
|
+
|
96
|
+
[#13](https://github.com/ssenart/gazpar2haws/issues/13): Using HassIO, connection to the supervisor requires Authorization header.
|
97
|
+
|
98
|
+
## [0.1.3] - 2025-01-03
|
99
|
+
|
100
|
+
### Changed
|
101
|
+
|
102
|
+
[#11](https://github.com/ssenart/gazpar2haws/issues/11): Upgrade PyGazpar version to 1.2.6.
|
103
|
+
|
104
|
+
## [0.1.2] - 2024-12-30
|
105
|
+
|
106
|
+
### Added
|
107
|
+
|
108
|
+
[#2](https://github.com/ssenart/gazpar2haws/issues/2): DockerHub deployment.
|
109
|
+
|
110
|
+
### Fixed
|
111
|
+
|
112
|
+
[#9](https://github.com/ssenart/gazpar2haws/issues/9): Incorrect timezone info creates duplicate import.
|
113
|
+
|
114
|
+
[#6](https://github.com/ssenart/gazpar2haws/issues/6): The last meter value may be imported multiple times and cause the today value being wrong.
|
115
|
+
|
116
|
+
[#3](https://github.com/ssenart/gazpar2haws/issues/3): reset=false makes the meter import to restart from zero.
|
117
|
+
|
118
|
+
## [0.1.1] - 2024-12-22
|
119
|
+
|
120
|
+
### Added
|
121
|
+
|
122
|
+
[#1](https://github.com/ssenart/gazpar2haws/issues/1): Publish energy indicator in kWh.
|
123
|
+
|
124
|
+
## [0.1.0] - 2024-12-21
|
125
|
+
|
126
|
+
First version of the project.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: gazpar2haws
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.1
|
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 License
|
6
6
|
|
@@ -52,7 +52,7 @@ Gazpar2HAWS can be installed in many ways.
|
|
52
52
|
|
53
53
|
### 1. Home Assistant Add-on
|
54
54
|
|
55
|
-
In the **Add-on store**, click **⋮ → Repositories**, fill in **`https://github.com/ssenart/gazpar2haws`** and click **Add → Close** or click the **Add repository** button below, click **Add → Close** (You might need to enter the **internal IP address** of your Home Assistant instance first).
|
55
|
+
In the **Add-on store**, click **⋮ → Repositories**, fill in **`https://github.com/ssenart/gazpar2haws`** and click **Add → Close** or click the **Add repository** button below, click **Add → Close** (You might need to enter the **internal IP address** of your Home Assistant instance first).
|
56
56
|
|
57
57
|
[](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fssenart%2Fgazpar2haws)
|
58
58
|
|
@@ -67,11 +67,11 @@ The following steps permits to run a container from an existing image available
|
|
67
67
|
```yaml
|
68
68
|
services:
|
69
69
|
gazpar2haws:
|
70
|
-
image: ssenart/gazpar2haws:latest
|
70
|
+
image: ssenart/gazpar2haws:latest
|
71
71
|
container_name: gazpar2haws
|
72
72
|
restart: unless-stopped
|
73
73
|
network_mode: bridge
|
74
|
-
user: "1000:1000"
|
74
|
+
user: "1000:1000"
|
75
75
|
volumes:
|
76
76
|
- ./gazpar2haws/config:/app/config
|
77
77
|
- ./gazpar2haws/log:/app/log
|
@@ -86,6 +86,7 @@ services:
|
|
86
86
|
Edit the environment variable section according to your setup.
|
87
87
|
|
88
88
|
2. Run the container:
|
89
|
+
|
89
90
|
```sh
|
90
91
|
$ docker compose up -d
|
91
92
|
```
|
@@ -112,27 +113,33 @@ $ pip install gazpar2haws
|
|
112
113
|
The following steps permit to build the Docker image based on the local source files.
|
113
114
|
|
114
115
|
1. Clone the repo locally:
|
116
|
+
|
115
117
|
```sh
|
116
118
|
$ cd /path/to/my_install_folder/
|
117
119
|
|
118
120
|
$ git clone https://github.com/ssenart/gazpar2haws.git
|
119
121
|
```
|
122
|
+
|
120
123
|
2. Edit the docker-compose.yaml file by setting the environment variables corresponding to your GrDF account and Home Assistant setup:
|
121
124
|
|
122
125
|
```yaml
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
126
|
+
environment:
|
127
|
+
- GRDF_USERNAME=<GrDF account username>
|
128
|
+
- GRDF_PASSWORD=<GrDF account password>
|
129
|
+
- GRDF_PCE_IDENTIFIER=<GrDF PCE meter identifier>
|
130
|
+
- HOMEASSISTANT_HOST=<Home Assistant instance host name>
|
131
|
+
- HOMEASSISTANT_PORT=<Home Assistant instance port number>
|
132
|
+
- HOMEASSISTANT_TOKEN=<Home Assistant access token>
|
130
133
|
```
|
134
|
+
|
131
135
|
3. Build the image:
|
136
|
+
|
132
137
|
```sh
|
133
138
|
$ docker compose -f docker/docker-compose.yaml build
|
134
139
|
```
|
140
|
+
|
135
141
|
4. Run the container:
|
142
|
+
|
136
143
|
```sh
|
137
144
|
$ docker compose -f docker/docker-compose.yaml up -d
|
138
145
|
```
|
@@ -171,18 +178,18 @@ logging:
|
|
171
178
|
file: log/gazpar2haws.log
|
172
179
|
console: true
|
173
180
|
level: debug
|
174
|
-
format:
|
181
|
+
format: "%(asctime)s %(levelname)s [%(name)s] %(message)s"
|
175
182
|
|
176
183
|
grdf:
|
177
184
|
scan_interval: 0 # Number of minutes between each data retrieval (0 means no scan: a single data retrieval at startup, then stops).
|
178
185
|
devices:
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
+
- name: gazpar2haws # Name of the device in home assistant. It will be used as the entity_ids: sensor.${name}_volume and sensor.${name}_energy.
|
187
|
+
username: "!secret grdf.username"
|
188
|
+
password: "!secret grdf.password"
|
189
|
+
pce_identifier: "!secret grdf.pce_identifier"
|
190
|
+
timezone: Europe/Paris
|
191
|
+
last_days: 365 # Number of days of data to retrieve
|
192
|
+
reset: false # If true, the data will be reset before the first data retrieval
|
186
193
|
|
187
194
|
homeassistant:
|
188
195
|
host: "!secret homeassistant.host"
|
@@ -203,8 +210,9 @@ homeassistant.token: ${HA_TOKEN}
|
|
203
210
|
```
|
204
211
|
|
205
212
|
The history is uploaded on the entities with names:
|
206
|
-
|
207
|
-
- sensor.${name}
|
213
|
+
|
214
|
+
- sensor.${name}\_volume: Volume history in m³.
|
215
|
+
- sensor.${name}\_energy: Energy history in kWh.
|
208
216
|
|
209
217
|
`${name}` is 'gazpar2haws' defined in the above configuration file. It can be replaced by any other name.
|
210
218
|
|
@@ -212,16 +220,16 @@ The history is uploaded on the entities with names:
|
|
212
220
|
|
213
221
|
In a Docker environment, the configurations files are instantiated by replacing the environment variables below in the template files:
|
214
222
|
|
215
|
-
| Environment variable | Description
|
216
|
-
|
217
|
-
| GRDF_USERNAME
|
218
|
-
| GRDF_PASSWORD
|
219
|
-
| GRDF_PCE_IDENTIFIER | GrDF meter PCE identifier
|
220
|
-
| GRDF_SCAN_INTERVAL
|
221
|
-
| GRDF_LAST_DAYS
|
222
|
-
| HOMEASSISTANT_HOST
|
223
|
-
| HOMEASSISTANT_PORT
|
224
|
-
| HOMEASSISTANT_TOKEN | Home Assistant access token
|
223
|
+
| Environment variable | Description | Required | Default value |
|
224
|
+
| -------------------- | ----------------------------------------------------------------------------- | -------- | -------------- |
|
225
|
+
| GRDF_USERNAME | GrDF account user name | Yes | - |
|
226
|
+
| GRDF_PASSWORD | GrDF account password (avoid using special characters) | Yes | - |
|
227
|
+
| GRDF_PCE_IDENTIFIER | GrDF meter PCE identifier | Yes | - |
|
228
|
+
| GRDF_SCAN_INTERVAL | Period in minutes to refresh meter data (0 means one single refresh and stop) | No | 480 (8 hours) |
|
229
|
+
| GRDF_LAST_DAYS | Number of days of history data to retrieve | No | 1095 (3 years) |
|
230
|
+
| HOMEASSISTANT_HOST | Home Assistant instance host name | Yes | - |
|
231
|
+
| HOMEASSISTANT_PORT | Home Assistant instance port number | No | 8123 |
|
232
|
+
| HOMEASSISTANT_TOKEN | Home Assistant access token | Yes | - |
|
225
233
|
|
226
234
|
You can setup them directly in a docker-compose.yaml file (environment section) or from a Docker command line (-e option).
|
227
235
|
|
@@ -273,6 +281,3 @@ Please make sure to update tests as appropriate.
|
|
273
281
|
|
274
282
|
Gazpar2HAWS has been initiated for integration with [Home Assistant](https://www.home-assistant.io/) energy dashboard.
|
275
283
|
|
276
|
-
|
277
|
-
|
278
|
-
|
@@ -16,7 +16,7 @@ Gazpar2HAWS can be installed in many ways.
|
|
16
16
|
|
17
17
|
### 1. Home Assistant Add-on
|
18
18
|
|
19
|
-
In the **Add-on store**, click **⋮ → Repositories**, fill in **`https://github.com/ssenart/gazpar2haws`** and click **Add → Close** or click the **Add repository** button below, click **Add → Close** (You might need to enter the **internal IP address** of your Home Assistant instance first).
|
19
|
+
In the **Add-on store**, click **⋮ → Repositories**, fill in **`https://github.com/ssenart/gazpar2haws`** and click **Add → Close** or click the **Add repository** button below, click **Add → Close** (You might need to enter the **internal IP address** of your Home Assistant instance first).
|
20
20
|
|
21
21
|
[](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fssenart%2Fgazpar2haws)
|
22
22
|
|
@@ -31,11 +31,11 @@ The following steps permits to run a container from an existing image available
|
|
31
31
|
```yaml
|
32
32
|
services:
|
33
33
|
gazpar2haws:
|
34
|
-
image: ssenart/gazpar2haws:latest
|
34
|
+
image: ssenart/gazpar2haws:latest
|
35
35
|
container_name: gazpar2haws
|
36
36
|
restart: unless-stopped
|
37
37
|
network_mode: bridge
|
38
|
-
user: "1000:1000"
|
38
|
+
user: "1000:1000"
|
39
39
|
volumes:
|
40
40
|
- ./gazpar2haws/config:/app/config
|
41
41
|
- ./gazpar2haws/log:/app/log
|
@@ -50,6 +50,7 @@ services:
|
|
50
50
|
Edit the environment variable section according to your setup.
|
51
51
|
|
52
52
|
2. Run the container:
|
53
|
+
|
53
54
|
```sh
|
54
55
|
$ docker compose up -d
|
55
56
|
```
|
@@ -76,27 +77,33 @@ $ pip install gazpar2haws
|
|
76
77
|
The following steps permit to build the Docker image based on the local source files.
|
77
78
|
|
78
79
|
1. Clone the repo locally:
|
80
|
+
|
79
81
|
```sh
|
80
82
|
$ cd /path/to/my_install_folder/
|
81
83
|
|
82
84
|
$ git clone https://github.com/ssenart/gazpar2haws.git
|
83
85
|
```
|
86
|
+
|
84
87
|
2. Edit the docker-compose.yaml file by setting the environment variables corresponding to your GrDF account and Home Assistant setup:
|
85
88
|
|
86
89
|
```yaml
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
environment:
|
91
|
+
- GRDF_USERNAME=<GrDF account username>
|
92
|
+
- GRDF_PASSWORD=<GrDF account password>
|
93
|
+
- GRDF_PCE_IDENTIFIER=<GrDF PCE meter identifier>
|
94
|
+
- HOMEASSISTANT_HOST=<Home Assistant instance host name>
|
95
|
+
- HOMEASSISTANT_PORT=<Home Assistant instance port number>
|
96
|
+
- HOMEASSISTANT_TOKEN=<Home Assistant access token>
|
94
97
|
```
|
98
|
+
|
95
99
|
3. Build the image:
|
100
|
+
|
96
101
|
```sh
|
97
102
|
$ docker compose -f docker/docker-compose.yaml build
|
98
103
|
```
|
104
|
+
|
99
105
|
4. Run the container:
|
106
|
+
|
100
107
|
```sh
|
101
108
|
$ docker compose -f docker/docker-compose.yaml up -d
|
102
109
|
```
|
@@ -135,18 +142,18 @@ logging:
|
|
135
142
|
file: log/gazpar2haws.log
|
136
143
|
console: true
|
137
144
|
level: debug
|
138
|
-
format:
|
145
|
+
format: "%(asctime)s %(levelname)s [%(name)s] %(message)s"
|
139
146
|
|
140
147
|
grdf:
|
141
148
|
scan_interval: 0 # Number of minutes between each data retrieval (0 means no scan: a single data retrieval at startup, then stops).
|
142
149
|
devices:
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
+
- name: gazpar2haws # Name of the device in home assistant. It will be used as the entity_ids: sensor.${name}_volume and sensor.${name}_energy.
|
151
|
+
username: "!secret grdf.username"
|
152
|
+
password: "!secret grdf.password"
|
153
|
+
pce_identifier: "!secret grdf.pce_identifier"
|
154
|
+
timezone: Europe/Paris
|
155
|
+
last_days: 365 # Number of days of data to retrieve
|
156
|
+
reset: false # If true, the data will be reset before the first data retrieval
|
150
157
|
|
151
158
|
homeassistant:
|
152
159
|
host: "!secret homeassistant.host"
|
@@ -167,8 +174,9 @@ homeassistant.token: ${HA_TOKEN}
|
|
167
174
|
```
|
168
175
|
|
169
176
|
The history is uploaded on the entities with names:
|
170
|
-
|
171
|
-
- sensor.${name}
|
177
|
+
|
178
|
+
- sensor.${name}\_volume: Volume history in m³.
|
179
|
+
- sensor.${name}\_energy: Energy history in kWh.
|
172
180
|
|
173
181
|
`${name}` is 'gazpar2haws' defined in the above configuration file. It can be replaced by any other name.
|
174
182
|
|
@@ -176,16 +184,16 @@ The history is uploaded on the entities with names:
|
|
176
184
|
|
177
185
|
In a Docker environment, the configurations files are instantiated by replacing the environment variables below in the template files:
|
178
186
|
|
179
|
-
| Environment variable | Description
|
180
|
-
|
181
|
-
| GRDF_USERNAME
|
182
|
-
| GRDF_PASSWORD
|
183
|
-
| GRDF_PCE_IDENTIFIER | GrDF meter PCE identifier
|
184
|
-
| GRDF_SCAN_INTERVAL
|
185
|
-
| GRDF_LAST_DAYS
|
186
|
-
| HOMEASSISTANT_HOST
|
187
|
-
| HOMEASSISTANT_PORT
|
188
|
-
| HOMEASSISTANT_TOKEN | Home Assistant access token
|
187
|
+
| Environment variable | Description | Required | Default value |
|
188
|
+
| -------------------- | ----------------------------------------------------------------------------- | -------- | -------------- |
|
189
|
+
| GRDF_USERNAME | GrDF account user name | Yes | - |
|
190
|
+
| GRDF_PASSWORD | GrDF account password (avoid using special characters) | Yes | - |
|
191
|
+
| GRDF_PCE_IDENTIFIER | GrDF meter PCE identifier | Yes | - |
|
192
|
+
| GRDF_SCAN_INTERVAL | Period in minutes to refresh meter data (0 means one single refresh and stop) | No | 480 (8 hours) |
|
193
|
+
| GRDF_LAST_DAYS | Number of days of history data to retrieve | No | 1095 (3 years) |
|
194
|
+
| HOMEASSISTANT_HOST | Home Assistant instance host name | Yes | - |
|
195
|
+
| HOMEASSISTANT_PORT | Home Assistant instance port number | No | 8123 |
|
196
|
+
| HOMEASSISTANT_TOKEN | Home Assistant access token | Yes | - |
|
189
197
|
|
190
198
|
You can setup them directly in a docker-compose.yaml file (environment section) or from a Docker command line (-e option).
|
191
199
|
|
@@ -236,6 +244,3 @@ Please make sure to update tests as appropriate.
|
|
236
244
|
## Project status
|
237
245
|
|
238
246
|
Gazpar2HAWS has been initiated for integration with [Home Assistant](https://www.home-assistant.io/) energy dashboard.
|
239
|
-
|
240
|
-
|
241
|
-
|
@@ -1,91 +1,104 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import logging
|
4
|
-
import traceback
|
5
|
-
|
6
|
-
from gazpar2haws import __version__
|
7
|
-
from gazpar2haws.bridge import Bridge
|
8
|
-
|
9
|
-
Logger = logging.getLogger(__name__)
|
10
|
-
|
11
|
-
|
12
|
-
# ----------------------------------
|
13
|
-
async def main():
|
14
|
-
"""Main function"""
|
15
|
-
parser = argparse.ArgumentParser(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
parser.add_argument(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
config.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
1
|
+
import argparse
|
2
|
+
import asyncio
|
3
|
+
import logging
|
4
|
+
import traceback
|
5
|
+
|
6
|
+
from gazpar2haws import __version__, config_utils
|
7
|
+
from gazpar2haws.bridge import Bridge
|
8
|
+
|
9
|
+
Logger = logging.getLogger(__name__)
|
10
|
+
|
11
|
+
|
12
|
+
# ----------------------------------
|
13
|
+
async def main():
|
14
|
+
"""Main function"""
|
15
|
+
parser = argparse.ArgumentParser(
|
16
|
+
prog="gazpar2haws",
|
17
|
+
description="Gateway that reads data history from the GrDF (French gas provider) meter and send it to Home Assistant using WebSocket interface.",
|
18
|
+
)
|
19
|
+
parser.add_argument(
|
20
|
+
"-v", "--version", action="version", version="Gazpar2HAWS version"
|
21
|
+
)
|
22
|
+
parser.add_argument(
|
23
|
+
"-c",
|
24
|
+
"--config",
|
25
|
+
required=False,
|
26
|
+
default="config/configuration.yaml",
|
27
|
+
help="Path to the configuration file",
|
28
|
+
)
|
29
|
+
parser.add_argument(
|
30
|
+
"-s",
|
31
|
+
"--secrets",
|
32
|
+
required=False,
|
33
|
+
default="config/secrets.yaml",
|
34
|
+
help="Path to the secret file",
|
35
|
+
)
|
36
|
+
|
37
|
+
args = parser.parse_args()
|
38
|
+
|
39
|
+
try:
|
40
|
+
# Load configuration files
|
41
|
+
config = config_utils.ConfigLoader(args.config, args.secrets)
|
42
|
+
config.load_secrets()
|
43
|
+
config.load_config()
|
44
|
+
|
45
|
+
print(f"Gazpar2HAWS version: {__version__}")
|
46
|
+
|
47
|
+
# Set up logging
|
48
|
+
logging_file = config.get("logging.file")
|
49
|
+
logging_console = bool(config.get("logging.console"))
|
50
|
+
logging_level = config.get("logging.level")
|
51
|
+
logging_format = config.get("logging.format")
|
52
|
+
|
53
|
+
# Convert logging level to integer
|
54
|
+
if logging_level.upper() == "DEBUG":
|
55
|
+
level = logging.DEBUG
|
56
|
+
elif logging_level.upper() == "INFO":
|
57
|
+
level = logging.INFO
|
58
|
+
elif logging_level.upper() == "WARNING":
|
59
|
+
level = logging.WARNING
|
60
|
+
elif logging_level.upper() == "ERROR":
|
61
|
+
level = logging.ERROR
|
62
|
+
elif logging_level.upper() == "CRITICAL":
|
63
|
+
level = logging.CRITICAL
|
64
|
+
else:
|
65
|
+
level = logging.INFO
|
66
|
+
|
67
|
+
logging.basicConfig(filename=logging_file, level=level, format=logging_format)
|
68
|
+
|
69
|
+
if logging_console:
|
70
|
+
# Add a console handler manually
|
71
|
+
console_handler = logging.StreamHandler()
|
72
|
+
console_handler.setLevel(level) # Set logging level for the console
|
73
|
+
console_handler.setFormatter(
|
74
|
+
logging.Formatter(logging_format)
|
75
|
+
) # Customize console format
|
76
|
+
|
77
|
+
# Get the root logger and add the console handler
|
78
|
+
logging.getLogger().addHandler(console_handler)
|
79
|
+
|
80
|
+
Logger.info(f"Starting Gazpar2HAWS version {__version__}")
|
81
|
+
|
82
|
+
# Log configuration
|
83
|
+
Logger.info(f"Configuration:\n{config.dumps()}")
|
84
|
+
|
85
|
+
# Start the bridge
|
86
|
+
bridge = Bridge(config)
|
87
|
+
await bridge.run()
|
88
|
+
|
89
|
+
Logger.info("Gazpar2HAWS stopped.")
|
90
|
+
|
91
|
+
return 0
|
92
|
+
|
93
|
+
except Exception: # pylint: disable=broad-except
|
94
|
+
errorMessage = (
|
95
|
+
f"An error occured while running Gazpar2HAWS: {traceback.format_exc()}"
|
96
|
+
)
|
97
|
+
Logger.error(errorMessage)
|
98
|
+
print(errorMessage)
|
99
|
+
return 1
|
100
|
+
|
101
|
+
|
102
|
+
# ----------------------------------
|
103
|
+
if __name__ == "__main__":
|
104
|
+
asyncio.run(main())
|