gazpar2haws 0.1.0__py3-none-any.whl → 0.1.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.
- CHANGELOG.md +7 -1
- gazpar2haws/gazpar.py +23 -7
- gazpar2haws/haws.py +1 -1
- {gazpar2haws-0.1.0.dist-info → gazpar2haws-0.1.1.dist-info}/METADATA +32 -2
- gazpar2haws-0.1.1.dist-info/RECORD +12 -0
- gazpar2haws-0.1.0.dist-info/RECORD +0 -12
- {gazpar2haws-0.1.0.dist-info → gazpar2haws-0.1.1.dist-info}/LICENSE +0 -0
- {gazpar2haws-0.1.0.dist-info → gazpar2haws-0.1.1.dist-info}/WHEEL +0 -0
CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ 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.1] - 2024-12-22
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
[#1](https://github.com/ssenart/gazpar2haws/issues/1): Publish energy indicator in kWh.
|
12
|
+
|
13
|
+
## [0.1.0] - 2024-12-21
|
8
14
|
|
9
15
|
First version of the project.
|
gazpar2haws/gazpar.py
CHANGED
@@ -34,18 +34,30 @@ class Gazpar:
|
|
34
34
|
# Publish Gaspar data to Home Assistant WS
|
35
35
|
async def publish(self):
|
36
36
|
|
37
|
+
# Volume and energy sensor names.
|
38
|
+
volume_sensor_name = f"sensor.{self._name}_volume"
|
39
|
+
energy_sensor_name = f"sensor.{self._name}_energy"
|
40
|
+
|
37
41
|
# Eventually reset the sensor in Home Assistant
|
38
42
|
if self._reset:
|
39
43
|
try:
|
40
|
-
await self._homeassistant.clear_statistics([
|
44
|
+
await self._homeassistant.clear_statistics([volume_sensor_name, energy_sensor_name])
|
41
45
|
except Exception:
|
42
46
|
errorMessage = f"Error while resetting the sensor in Home Assistant: {traceback.format_exc()}"
|
43
47
|
Logger.warning(errorMessage)
|
44
48
|
raise Exception(errorMessage)
|
45
49
|
|
50
|
+
# Publish volume sensor
|
51
|
+
await self._publish_entity(volume_sensor_name, pygazpar.PropertyName.VOLUME.value, "m³")
|
52
|
+
await self._publish_entity(energy_sensor_name, pygazpar.PropertyName.ENERGY.value, "kWh")
|
53
|
+
|
54
|
+
# ----------------------------------
|
55
|
+
# Publish a sensor to Home Assistant
|
56
|
+
async def _publish_entity(self, entity_id: str, property_name: str, unit_of_measurement: str):
|
57
|
+
|
46
58
|
# Check the existence of the sensor in Home Assistant
|
47
59
|
try:
|
48
|
-
exists_statistic_id = await self._homeassistant.exists_statistic_id(
|
60
|
+
exists_statistic_id = await self._homeassistant.exists_statistic_id(entity_id, "sum")
|
49
61
|
except Exception:
|
50
62
|
errorMessage = f"Error while checking the existence of the sensor in Home Assistant: {traceback.format_exc()}"
|
51
63
|
Logger.warning(errorMessage)
|
@@ -54,7 +66,7 @@ class Gazpar:
|
|
54
66
|
if exists_statistic_id:
|
55
67
|
# Get last statistics from GrDF
|
56
68
|
try:
|
57
|
-
last_statistics = await self._homeassistant.get_last_statistic(
|
69
|
+
last_statistics = await self._homeassistant.get_last_statistic(entity_id)
|
58
70
|
except Exception:
|
59
71
|
errorMessage = f"Error while fetching last statistics from Home Assistant: {traceback.format_exc()}"
|
60
72
|
Logger.warning(errorMessage)
|
@@ -85,9 +97,10 @@ class Gazpar:
|
|
85
97
|
# Timezone
|
86
98
|
timezone = pytz.timezone(self._timezone)
|
87
99
|
|
88
|
-
#
|
100
|
+
# Compute and fill statistics.
|
89
101
|
daily = data.get(pygazpar.Frequency.DAILY.value)
|
90
102
|
statistics = []
|
103
|
+
total = 0
|
91
104
|
for reading in daily:
|
92
105
|
# Parse date format DD/MM/YYYY into datetime.
|
93
106
|
date = datetime.strptime(reading[pygazpar.PropertyName.TIME_PERIOD.value], "%d/%m/%Y")
|
@@ -99,15 +112,18 @@ class Gazpar:
|
|
99
112
|
# Set the timezone
|
100
113
|
date = timezone.localize(date)
|
101
114
|
|
115
|
+
# Compute the total volume and energy
|
116
|
+
total += reading[property_name]
|
117
|
+
|
102
118
|
statistics.append({
|
103
119
|
"start": date.isoformat(),
|
104
|
-
"state":
|
105
|
-
"sum":
|
120
|
+
"state": total,
|
121
|
+
"sum": total
|
106
122
|
})
|
107
123
|
|
108
124
|
# Publish statistics to Home Assistant
|
109
125
|
try:
|
110
|
-
await self._homeassistant.import_statistics(
|
126
|
+
await self._homeassistant.import_statistics(entity_id, "recorder", "gazpar2haws", unit_of_measurement, statistics)
|
111
127
|
except Exception:
|
112
128
|
errorMessage = f"Error while importing statistics to Home Assistant: {traceback.format_exc()}"
|
113
129
|
Logger.warning(errorMessage)
|
gazpar2haws/haws.py
CHANGED
@@ -73,7 +73,7 @@ class HomeAssistantWS:
|
|
73
73
|
|
74
74
|
response_data = json.loads(response)
|
75
75
|
|
76
|
-
Logger.debug(
|
76
|
+
Logger.debug("Received response")
|
77
77
|
|
78
78
|
if response_data.get("type") != "result":
|
79
79
|
raise Exception(f"Invalid response message: {response_data}")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: gazpar2haws
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.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
|
6
6
|
Author: Stéphane Senart
|
@@ -80,7 +80,7 @@ logging:
|
|
80
80
|
grdf:
|
81
81
|
scan_interval: 0 # Number of minutes between each data retrieval (0 means no scan: a single data retrieval at startup, then stops).
|
82
82
|
devices:
|
83
|
-
- name: gazpar2haws
|
83
|
+
- name: gazpar2haws # Name of the device in home assistant. It will be used as the entity_ids: sensor.${name}_volume and sensor.${name}_energy.
|
84
84
|
username: "!secret grdf.username"
|
85
85
|
password: "!secret grdf.password"
|
86
86
|
pce_identifier: "!secret grdf.pce_identifier"
|
@@ -106,6 +106,36 @@ homeassistant.port: ${HA_PORT}
|
|
106
106
|
homeassistant.token: ${HA_TOKEN}
|
107
107
|
```
|
108
108
|
|
109
|
+
The history is uploaded on the entities with names:
|
110
|
+
- sensor.${name}_volume: Volume history in m³.
|
111
|
+
- sensor.${name}_energy: Energy history in kWh.
|
112
|
+
|
113
|
+
${name} is 'gazpar2haws' defined in the above configuration file. It can be replaced by any other name.
|
114
|
+
|
115
|
+
Those two entities have to already exist in Home Assistant.
|
116
|
+
|
117
|
+
They may be created using the following templates:
|
118
|
+
|
119
|
+
```yaml
|
120
|
+
|
121
|
+
- name: gazpar2haws_volume
|
122
|
+
unit_of_measurement: 'm³'
|
123
|
+
availability: true
|
124
|
+
state: 0
|
125
|
+
icon: mdi:fire
|
126
|
+
device_class: gas
|
127
|
+
state_class: total_increasing
|
128
|
+
|
129
|
+
- name: gazpar2haws_energy
|
130
|
+
unit_of_measurement: 'kWh'
|
131
|
+
availability: true
|
132
|
+
state: 0
|
133
|
+
icon: mdi:fire
|
134
|
+
device_class: energy
|
135
|
+
state_class: total_increasing
|
136
|
+
|
137
|
+
```
|
138
|
+
|
109
139
|
## Contributing
|
110
140
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
111
141
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
CHANGELOG.md,sha256=2Xv5NYFt0BQy7NAAQPDHKb4OTsPaz5qF_2UDK5VP4a8,447
|
2
|
+
gazpar2haws/__init__.py,sha256=yzol8uZSBI7pIRGUmYJ6-vRBwkM4MI3IGf5cQpNsaFw,57
|
3
|
+
gazpar2haws/__main__.py,sha256=g8xk0x_kprBHKHLzgf9y9EY2_gKC9V3k4z0n-EDTd-I,3253
|
4
|
+
gazpar2haws/bridge.py,sha256=TiPmvRBxzgwOKKmWNXMOaP0pLg-Wls_SmiwHczNEM_4,3466
|
5
|
+
gazpar2haws/config_utils.py,sha256=D0lu-3KY-vLEyD2vDN05UABkMnpMJjqw1RuDJVrkGFs,2123
|
6
|
+
gazpar2haws/gazpar.py,sha256=mC2yDvb22sGjA4c3Gj0sPXEyLKnSNi6WGbVG2HOkD-A,5285
|
7
|
+
gazpar2haws/haws.py,sha256=SiVM5QTANMmUq66IAsFn68jwej-Rdpqg6dIqTeTadmw,6765
|
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,,
|
@@ -1,12 +0,0 @@
|
|
1
|
-
CHANGELOG.md,sha256=8JDG8V_DLBTwnVlZErwlK9PNI-xiwpU6vaqSKavYvKw,316
|
2
|
-
gazpar2haws/__init__.py,sha256=yzol8uZSBI7pIRGUmYJ6-vRBwkM4MI3IGf5cQpNsaFw,57
|
3
|
-
gazpar2haws/__main__.py,sha256=g8xk0x_kprBHKHLzgf9y9EY2_gKC9V3k4z0n-EDTd-I,3253
|
4
|
-
gazpar2haws/bridge.py,sha256=TiPmvRBxzgwOKKmWNXMOaP0pLg-Wls_SmiwHczNEM_4,3466
|
5
|
-
gazpar2haws/config_utils.py,sha256=D0lu-3KY-vLEyD2vDN05UABkMnpMJjqw1RuDJVrkGFs,2123
|
6
|
-
gazpar2haws/gazpar.py,sha256=4bEp0JDrLAFxbADSoRH76UD3OC8ls5GBhUcoBQ9WQxw,4663
|
7
|
-
gazpar2haws/haws.py,sha256=EXs5Tdla4u2BVtupCCLITyvdL_W288LrCxrTzskWSRY,6783
|
8
|
-
gazpar2haws/version.py,sha256=ebdTNl4h0hNKmN3Gbs592VJsYbMmrkB47WyZMJevaQo,86
|
9
|
-
gazpar2haws-0.1.0.dist-info/LICENSE,sha256=G6JttcnlwcRHYzIcDflSGOVrHTtaP3BEegM2lH00xHw,1094
|
10
|
-
gazpar2haws-0.1.0.dist-info/METADATA,sha256=H6EGtnQczzLQKLDwdPtAd2TwAzzVIi82AURA36Khwns,3099
|
11
|
-
gazpar2haws-0.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
12
|
-
gazpar2haws-0.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|