gazpar2haws 0.2.0b1__py3-none-any.whl → 0.2.1__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.
gazpar2haws/bridge.py CHANGED
@@ -16,12 +16,30 @@ class Bridge:
16
16
  def __init__(self, config: config_utils.ConfigLoader):
17
17
 
18
18
  # GrDF scan interval (in seconds)
19
+ if config.get("grdf.scan_interval") is None:
20
+ raise ValueError("Configuration parameter 'grdf.scan_interval' is missing")
19
21
  self._grdf_scan_interval = int(config.get("grdf.scan_interval"))
20
22
 
21
- # Home Assistant configuration
23
+ # Home Assistant configuration: host
24
+ if config.get("homeassistant.host") is None:
25
+ raise ValueError("Configuration parameter 'homeassistant.host' is missing")
22
26
  ha_host = config.get("homeassistant.host")
27
+
28
+ # Home Assistant configuration: port
29
+ if config.get("homeassistant.port") is None:
30
+ raise ValueError("Configuration parameter 'homeassistant.port' is missing")
23
31
  ha_port = config.get("homeassistant.port")
24
- ha_endpoint = config.get("homeassistant.endpoint")
32
+
33
+ # Home Assistant configuration: endpoint
34
+ ha_endpoint = (
35
+ config.get("homeassistant.endpoint")
36
+ if config.get("homeassistant.endpoint")
37
+ else "/api/websocket"
38
+ )
39
+
40
+ # Home Assistant configuration: token
41
+ if config.get("homeassistant.token") is None:
42
+ raise ValueError("Configuration parameter 'homeassistant.token' is missing")
25
43
  ha_token = config.get("homeassistant.token")
26
44
 
27
45
  # Initialize Home Assistant
@@ -29,6 +47,9 @@ class Bridge:
29
47
 
30
48
  # Initialize Gazpar
31
49
  self._gazpar = []
50
+
51
+ if config.get("grdf.devices") is None:
52
+ raise ValueError("Configuration parameter 'grdf.devices' is missing")
32
53
  for grdf_device_config in config.get("grdf.devices"):
33
54
  self._gazpar.append(Gazpar(grdf_device_config, self._homeassistant))
34
55
 
@@ -1,18 +1,21 @@
1
1
  import os
2
+ from typing import Any
2
3
 
3
4
  import yaml
4
5
 
5
6
 
6
7
  class ConfigLoader:
7
- def __init__(self, config_file="config.yaml", secrets_file="secrets.yaml"):
8
+ def __init__(self, config_file: str, secrets_file: str):
8
9
  self.config_file = config_file
9
10
  self.secrets_file = secrets_file
10
- self.config = {}
11
- self.secrets = {}
11
+ self.config = dict[str, Any]()
12
+ self.secrets = dict[str, Any]()
12
13
  self.raw_config = None
13
14
 
14
15
  def load_secrets(self):
15
16
  """Load the secrets file."""
17
+ if self.secrets_file is None:
18
+ return
16
19
  if os.path.exists(self.secrets_file):
17
20
  with open(self.secrets_file, "r", encoding="utf-8") as file:
18
21
  self.secrets = yaml.safe_load(file)
gazpar2haws/gazpar.py CHANGED
@@ -19,15 +19,59 @@ class Gazpar:
19
19
 
20
20
  self._homeassistant = homeassistant
21
21
 
22
- # GrDF configuration
22
+ # GrDF configuration: name
23
+ if config.get("name") is None:
24
+ raise ValueError("Configuration parameter 'grdf.devices[].name' is missing")
23
25
  self._name = config.get("name")
24
- self._data_source = config.get("data_source")
26
+
27
+ # GrDF configuration: data source
28
+ self._data_source = (
29
+ config.get("data_source") if config.get("data_source") else "json"
30
+ )
31
+
32
+ # GrDF configuration: username
33
+ if self._data_source != "test" and config.get("username") is None:
34
+ raise ValueError(
35
+ "Configuration parameter 'grdf.devices[].username' is missing"
36
+ )
25
37
  self._username = config.get("username")
38
+
39
+ # GrDF configuration: password
40
+ if self._data_source != "test" and config.get("password") is None:
41
+ raise ValueError(
42
+ "Configuration parameter 'grdf.devices[].password' is missing"
43
+ )
26
44
  self._password = config.get("password")
45
+
46
+ # GrDF configuration: pce_identifier
47
+ if self._data_source != "test" and config.get("pce_identifier") is None:
48
+ raise ValueError(
49
+ "Configuration parameter 'grdf.devices[].pce_identifier' is missing"
50
+ )
27
51
  self._pce_identifier = str(config.get("pce_identifier"))
28
- self._tmp_dir = config.get("tmp_dir")
52
+
53
+ # GrDF configuration: tmp_dir
54
+ self._tmp_dir = config.get("tmp_dir") if config.get("tmp_dir") else "/tmp"
55
+
56
+ # GrDF configuration: last_days
57
+ if config.get("last_days") is None:
58
+ raise ValueError(
59
+ "Configuration parameter 'grdf.devices[].last_days' is missing"
60
+ )
29
61
  self._last_days = int(str(config.get("last_days")))
62
+
63
+ # GrDF configuration: timezone
64
+ if config.get("timezone") is None:
65
+ raise ValueError(
66
+ "Configuration parameter 'grdf.devices[].timezone' is missing"
67
+ )
30
68
  self._timezone = str(config.get("timezone"))
69
+
70
+ # GrDF configuration: reset
71
+ if config.get("reset") is None:
72
+ raise ValueError(
73
+ "Configuration parameter 'grdf.devices[].reset' is missing"
74
+ )
31
75
  self._reset = bool(config.get("reset"))
32
76
 
33
77
  # As of date: YYYY-MM-DD
@@ -43,7 +87,8 @@ class Gazpar:
43
87
 
44
88
  # Set the timezone
45
89
  timezone = pytz.timezone(self._timezone)
46
- self._as_of_date = timezone.localize(self._as_of_date)
90
+ if self._as_of_date.tzinfo is None:
91
+ self._as_of_date = timezone.localize(self._as_of_date)
47
92
 
48
93
  # ----------------------------------
49
94
  def name(self):
@@ -128,7 +173,13 @@ class Gazpar:
128
173
  continue
129
174
 
130
175
  # Compute the total volume and energy
131
- total += reading[property_name]
176
+ if reading[property_name] is not None:
177
+ total += reading[property_name]
178
+ else:
179
+ Logger.warning(
180
+ f"Missing property {property_name} for date {date}. Skipping..."
181
+ )
182
+ continue
132
183
 
133
184
  statistics.append({"start": date.isoformat(), "state": total, "sum": total})
134
185
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: gazpar2haws
3
- Version: 0.2.0b1
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
  [![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](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
- environment:
124
- - GRDF_USERNAME=<GrDF account username>
125
- - GRDF_PASSWORD=<GrDF account password>
126
- - GRDF_PCE_IDENTIFIER=<GrDF PCE meter identifier>
127
- - HOMEASSISTANT_HOST=<Home Assistant instance host name>
128
- - HOMEASSISTANT_PORT=<Home Assistant instance port number>
129
- - HOMEASSISTANT_TOKEN=<Home Assistant access token>
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: '%(asctime)s %(levelname)s [%(name)s] %(message)s'
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
- - name: gazpar2haws # Name of the device in home assistant. It will be used as the entity_ids: sensor.${name}_volume and sensor.${name}_energy.
180
- username: "!secret grdf.username"
181
- password: "!secret grdf.password"
182
- pce_identifier: "!secret grdf.pce_identifier"
183
- timezone: Europe/Paris
184
- last_days: 365 # Number of days of data to retrieve
185
- reset: false # If true, the data will be reset before the first data retrieval
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
- - sensor.${name}_volume: Volume history in m³.
207
- - sensor.${name}_energy: Energy history in kWh.
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 | Required | Default value |
216
- |---|---|---|---|
217
- | GRDF_USERNAME | GrDF account user name | Yes | - |
218
- | GRDF_PASSWORD | GrDF account password (avoid using special characters) | Yes | - |
219
- | GRDF_PCE_IDENTIFIER | GrDF meter PCE identifier | Yes | - |
220
- | GRDF_SCAN_INTERVAL | Period in minutes to refresh meter data (0 means one single refresh and stop) | No | 480 (8 hours) |
221
- | GRDF_LAST_DAYS | Number of days of history data to retrieve | No | 1095 (3 years) |
222
- | HOMEASSISTANT_HOST | Home Assistant instance host name | Yes | - |
223
- | HOMEASSISTANT_PORT | Home Assistant instance port number | No | 8123 |
224
- | HOMEASSISTANT_TOKEN | Home Assistant access token | Yes | - |
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
-
@@ -0,0 +1,11 @@
1
+ gazpar2haws/__init__.py,sha256=3MCDQdGGmT3FQMKaAB3mBJq7L75T_bJSdpDRjE-pado,58
2
+ gazpar2haws/__main__.py,sha256=KdhkowqJP6L8WTF9FNpTy4ZzDf1OPARm6mVtMclxGFk,3265
3
+ gazpar2haws/bridge.py,sha256=IDunENo7bQ9NDov76IEefAkMOen-6Wc_2NZcHGyk_XI,4601
4
+ gazpar2haws/config_utils.py,sha256=r8BvrA1r8huF-qjvQb0P1JYDLqzDleirLjOcj0xOyyU,2253
5
+ gazpar2haws/gazpar.py,sha256=29RfLxBaBCpoopOBpCX3xh681Ksm5pjZlLu9l3PqTAI,10321
6
+ gazpar2haws/haws.py,sha256=H--UWGECYq9JYlbU6IHLO2btaRXInwoVRZnHIXSA1ts,8169
7
+ gazpar2haws/version.py,sha256=9Iq5Jm63Ev7QquCjhDqa9_KAgHdKl9FJHynq8M6JNrY,83
8
+ gazpar2haws-0.2.1.dist-info/LICENSE,sha256=ajApZPyhVx8AU9wN7DXeRGhoWFqY2ylBZUa5GRhTmok,1073
9
+ gazpar2haws-0.2.1.dist-info/METADATA,sha256=Fbf6evtMKByRJCEWcE179YQHhmtsa4COSYluCIcGaKo,10050
10
+ gazpar2haws-0.2.1.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
11
+ gazpar2haws-0.2.1.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- gazpar2haws/__init__.py,sha256=3MCDQdGGmT3FQMKaAB3mBJq7L75T_bJSdpDRjE-pado,58
2
- gazpar2haws/__main__.py,sha256=KdhkowqJP6L8WTF9FNpTy4ZzDf1OPARm6mVtMclxGFk,3265
3
- gazpar2haws/bridge.py,sha256=s8ENqugNhxTJMAOJzRwVt1YidwxzbPfwdWKx7TLQN7w,3625
4
- gazpar2haws/config_utils.py,sha256=89ClKudFGxiT_EnzqRhfEvYVm9SeWq6U2xhNjvm3hhs,2161
5
- gazpar2haws/gazpar.py,sha256=6FyKUKtvn9zlpHbyaUvEYs6uUK7Bnx8LDGB9Nbs_E58,8327
6
- gazpar2haws/haws.py,sha256=H--UWGECYq9JYlbU6IHLO2btaRXInwoVRZnHIXSA1ts,8169
7
- gazpar2haws/version.py,sha256=9Iq5Jm63Ev7QquCjhDqa9_KAgHdKl9FJHynq8M6JNrY,83
8
- gazpar2haws-0.2.0b1.dist-info/LICENSE,sha256=ajApZPyhVx8AU9wN7DXeRGhoWFqY2ylBZUa5GRhTmok,1073
9
- gazpar2haws-0.2.0b1.dist-info/METADATA,sha256=-TB33G3v3eu9r1Uv33ffcP-zBRMpBQBIY3nezSwYFV4,9452
10
- gazpar2haws-0.2.0b1.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
11
- gazpar2haws-0.2.0b1.dist-info/RECORD,,