Skip to content

Commit 7da06ee

Browse files
committed
Replace Metric enum values with plain ints
This ensures that enum values are not accidentally passed to protobuf functions without conversion. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 90f0e35 commit 7da06ee

4 files changed

Lines changed: 91 additions & 108 deletions

File tree

RELEASE_NOTES.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44

55
<!-- Here goes a general summary of what this release is about -->
66

7-
## Deprecation
7+
## Upgrading
88

9-
- Converting `Metric` enums from/to protobuf directly is deprecated and will be dropped in the next breaking release.
10-
11-
You should switch to use the new conversion functions in `frequenz.client.common.metrics.proto.v1alpha8` to convert from/to protobuf.
12-
13-
Since we can't emit deprecation messages for this (as they will trigger every time a metric value is used), please consider using the new conversion functions as soon as possible so the migration to the next breaking release is smooth.
9+
- Converting `Metric` enums from/to protobuf directly is not supported anymore, you need to use explicit conversion functions, like the ones in `frequenz.client.common.metrics.proto.v1alpha8`.
1410

1511
## New Features
1612

17-
- A new module `frequenz.client.common.metrics.proto.v1alpha8` has been added to provide conversion functions for `Metric`s from/to protobuf version `v1alpha8`.
13+
<!-- Here goes the main new features and examples or instructions on how to use them -->
1814

1915
## Bug Fixes
2016

src/frequenz/client/common/metrics/_metric.py

Lines changed: 71 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import enum
77

8-
from frequenz.api.common.v1alpha8.metrics import metrics_pb2
9-
108

119
@enum.unique
1210
class Metric(enum.Enum):
@@ -41,237 +39,215 @@ class Metric(enum.Enum):
4139
period, and therefore can be inconsistent.
4240
"""
4341

44-
UNSPECIFIED = metrics_pb2.METRIC_UNSPECIFIED
42+
UNSPECIFIED = 0
4543
"""The metric is unspecified (this should not be used)."""
4644

47-
DC_VOLTAGE = metrics_pb2.METRIC_DC_VOLTAGE
45+
DC_VOLTAGE = 1
4846
"""The DC voltage."""
4947

50-
DC_CURRENT = metrics_pb2.METRIC_DC_CURRENT
48+
DC_CURRENT = 2
5149
"""The DC current."""
5250

53-
DC_POWER = metrics_pb2.METRIC_DC_POWER
51+
DC_POWER = 3
5452
"""The DC power."""
5553

56-
AC_FREQUENCY = metrics_pb2.METRIC_AC_FREQUENCY
54+
AC_FREQUENCY = 10
5755
"""The AC frequency."""
5856

59-
AC_VOLTAGE = metrics_pb2.METRIC_AC_VOLTAGE
57+
AC_VOLTAGE = 11
6058
"""The AC electric potential difference."""
6159

62-
AC_VOLTAGE_PHASE_1_N = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_1_N
60+
AC_VOLTAGE_PHASE_1_N = 12
6361
"""The AC electric potential difference between phase 1 and neutral."""
6462

65-
AC_VOLTAGE_PHASE_2_N = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_2_N
63+
AC_VOLTAGE_PHASE_2_N = 13
6664
"""The AC electric potential difference between phase 2 and neutral."""
6765

68-
AC_VOLTAGE_PHASE_3_N = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_3_N
66+
AC_VOLTAGE_PHASE_3_N = 14
6967
"""The AC electric potential difference between phase 3 and neutral."""
7068

71-
AC_VOLTAGE_PHASE_1_PHASE_2 = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_1_PHASE_2
69+
AC_VOLTAGE_PHASE_1_PHASE_2 = 15
7270
"""The AC electric potential difference between phase 1 and phase 2."""
7371

74-
AC_VOLTAGE_PHASE_2_PHASE_3 = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_2_PHASE_3
72+
AC_VOLTAGE_PHASE_2_PHASE_3 = 16
7573
"""The AC electric potential difference between phase 2 and phase 3."""
7674

77-
AC_VOLTAGE_PHASE_3_PHASE_1 = metrics_pb2.METRIC_AC_VOLTAGE_PHASE_3_PHASE_1
75+
AC_VOLTAGE_PHASE_3_PHASE_1 = 17
7876
"""The AC electric potential difference between phase 3 and phase 1."""
7977

80-
AC_CURRENT = metrics_pb2.METRIC_AC_CURRENT
78+
AC_CURRENT = 18
8179
"""The AC current."""
8280

83-
AC_CURRENT_PHASE_1 = metrics_pb2.METRIC_AC_CURRENT_PHASE_1
81+
AC_CURRENT_PHASE_1 = 19
8482
"""The AC current in phase 1."""
8583

86-
AC_CURRENT_PHASE_2 = metrics_pb2.METRIC_AC_CURRENT_PHASE_2
84+
AC_CURRENT_PHASE_2 = 20
8785
"""The AC current in phase 2."""
8886

89-
AC_CURRENT_PHASE_3 = metrics_pb2.METRIC_AC_CURRENT_PHASE_3
87+
AC_CURRENT_PHASE_3 = 21
9088
"""The AC current in phase 3."""
9189

92-
AC_POWER_APPARENT = metrics_pb2.METRIC_AC_POWER_APPARENT
90+
AC_POWER_APPARENT = 22
9391
"""The AC apparent power."""
9492

95-
AC_POWER_APPARENT_PHASE_1 = metrics_pb2.METRIC_AC_POWER_APPARENT_PHASE_1
93+
AC_POWER_APPARENT_PHASE_1 = 23
9694
"""The AC apparent power in phase 1."""
9795

98-
AC_POWER_APPARENT_PHASE_2 = metrics_pb2.METRIC_AC_POWER_APPARENT_PHASE_2
96+
AC_POWER_APPARENT_PHASE_2 = 24
9997
"""The AC apparent power in phase 2."""
10098

101-
AC_POWER_APPARENT_PHASE_3 = metrics_pb2.METRIC_AC_POWER_APPARENT_PHASE_3
99+
AC_POWER_APPARENT_PHASE_3 = 25
102100
"""The AC apparent power in phase 3."""
103101

104-
AC_POWER_ACTIVE = metrics_pb2.METRIC_AC_POWER_ACTIVE
102+
AC_POWER_ACTIVE = 26
105103
"""The AC active power."""
106104

107-
AC_POWER_ACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_POWER_ACTIVE_PHASE_1
105+
AC_POWER_ACTIVE_PHASE_1 = 27
108106
"""The AC active power in phase 1."""
109107

110-
AC_POWER_ACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_POWER_ACTIVE_PHASE_2
108+
AC_POWER_ACTIVE_PHASE_2 = 28
111109
"""The AC active power in phase 2."""
112110

113-
AC_POWER_ACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_POWER_ACTIVE_PHASE_3
111+
AC_POWER_ACTIVE_PHASE_3 = 29
114112
"""The AC active power in phase 3."""
115113

116-
AC_POWER_REACTIVE = metrics_pb2.METRIC_AC_POWER_REACTIVE
114+
AC_POWER_REACTIVE = 30
117115
"""The AC reactive power."""
118116

119-
AC_POWER_REACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_POWER_REACTIVE_PHASE_1
117+
AC_POWER_REACTIVE_PHASE_1 = 31
120118
"""The AC reactive power in phase 1."""
121119

122-
AC_POWER_REACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_POWER_REACTIVE_PHASE_2
120+
AC_POWER_REACTIVE_PHASE_2 = 32
123121
"""The AC reactive power in phase 2."""
124122

125-
AC_POWER_REACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_POWER_REACTIVE_PHASE_3
123+
AC_POWER_REACTIVE_PHASE_3 = 33
126124
"""The AC reactive power in phase 3."""
127125

128-
AC_POWER_FACTOR = metrics_pb2.METRIC_AC_POWER_FACTOR
126+
AC_POWER_FACTOR = 40
129127
"""The AC power factor."""
130128

131-
AC_POWER_FACTOR_PHASE_1 = metrics_pb2.METRIC_AC_POWER_FACTOR_PHASE_1
129+
AC_POWER_FACTOR_PHASE_1 = 41
132130
"""The AC power factor in phase 1."""
133131

134-
AC_POWER_FACTOR_PHASE_2 = metrics_pb2.METRIC_AC_POWER_FACTOR_PHASE_2
132+
AC_POWER_FACTOR_PHASE_2 = 42
135133
"""The AC power factor in phase 2."""
136134

137-
AC_POWER_FACTOR_PHASE_3 = metrics_pb2.METRIC_AC_POWER_FACTOR_PHASE_3
135+
AC_POWER_FACTOR_PHASE_3 = 43
138136
"""The AC power factor in phase 3."""
139137

140-
AC_ENERGY_APPARENT = metrics_pb2.METRIC_AC_ENERGY_APPARENT
138+
AC_ENERGY_APPARENT = 50
141139
"""The AC apparent energy."""
142140

143-
AC_ENERGY_APPARENT_PHASE_1 = metrics_pb2.METRIC_AC_ENERGY_APPARENT_PHASE_1
141+
AC_ENERGY_APPARENT_PHASE_1 = 51
144142
"""The AC apparent energy in phase 1."""
145143

146-
AC_ENERGY_APPARENT_PHASE_2 = metrics_pb2.METRIC_AC_ENERGY_APPARENT_PHASE_2
144+
AC_ENERGY_APPARENT_PHASE_2 = 52
147145
"""The AC apparent energy in phase 2."""
148146

149-
AC_ENERGY_APPARENT_PHASE_3 = metrics_pb2.METRIC_AC_ENERGY_APPARENT_PHASE_3
147+
AC_ENERGY_APPARENT_PHASE_3 = 53
150148
"""The AC apparent energy in phase 3."""
151149

152-
AC_ENERGY_ACTIVE = metrics_pb2.METRIC_AC_ENERGY_ACTIVE
150+
AC_ENERGY_ACTIVE = 54
153151
"""The AC active energy."""
154152

155-
AC_ENERGY_ACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_PHASE_1
153+
AC_ENERGY_ACTIVE_PHASE_1 = 55
156154
"""The AC active energy in phase 1."""
157155

158-
AC_ENERGY_ACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_PHASE_2
156+
AC_ENERGY_ACTIVE_PHASE_2 = 56
159157
"""The AC active energy in phase 2."""
160158

161-
AC_ENERGY_ACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_PHASE_3
159+
AC_ENERGY_ACTIVE_PHASE_3 = 57
162160
"""The AC active energy in phase 3."""
163161

164-
AC_ENERGY_ACTIVE_CONSUMED = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED
162+
AC_ENERGY_ACTIVE_CONSUMED = 58
165163
"""The AC active energy consumed."""
166164

167-
AC_ENERGY_ACTIVE_CONSUMED_PHASE_1 = (
168-
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED_PHASE_1
169-
)
165+
AC_ENERGY_ACTIVE_CONSUMED_PHASE_1 = 59
170166
"""The AC active energy consumed in phase 1."""
171167

172-
AC_ENERGY_ACTIVE_CONSUMED_PHASE_2 = (
173-
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED_PHASE_2
174-
)
168+
AC_ENERGY_ACTIVE_CONSUMED_PHASE_2 = 60
175169
"""The AC active energy consumed in phase 2."""
176170

177-
AC_ENERGY_ACTIVE_CONSUMED_PHASE_3 = (
178-
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_CONSUMED_PHASE_3
179-
)
171+
AC_ENERGY_ACTIVE_CONSUMED_PHASE_3 = 61
180172
"""The AC active energy consumed in phase 3."""
181173

182-
AC_ENERGY_ACTIVE_DELIVERED = metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED
174+
AC_ENERGY_ACTIVE_DELIVERED = 62
183175
"""The AC active energy delivered."""
184176

185-
AC_ENERGY_ACTIVE_DELIVERED_PHASE_1 = (
186-
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED_PHASE_1
187-
)
177+
AC_ENERGY_ACTIVE_DELIVERED_PHASE_1 = 63
188178
"""The AC active energy delivered in phase 1."""
189179

190-
AC_ENERGY_ACTIVE_DELIVERED_PHASE_2 = (
191-
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED_PHASE_2
192-
)
180+
AC_ENERGY_ACTIVE_DELIVERED_PHASE_2 = 64
193181
"""The AC active energy delivered in phase 2."""
194182

195-
AC_ENERGY_ACTIVE_DELIVERED_PHASE_3 = (
196-
metrics_pb2.METRIC_AC_ENERGY_ACTIVE_DELIVERED_PHASE_3
197-
)
183+
AC_ENERGY_ACTIVE_DELIVERED_PHASE_3 = 65
198184
"""The AC active energy delivered in phase 3."""
199185

200-
AC_ENERGY_REACTIVE = metrics_pb2.METRIC_AC_ENERGY_REACTIVE
186+
AC_ENERGY_REACTIVE = 66
201187
"""The AC reactive energy."""
202188

203-
AC_ENERGY_REACTIVE_PHASE_1 = metrics_pb2.METRIC_AC_ENERGY_REACTIVE_PHASE_1
189+
AC_ENERGY_REACTIVE_PHASE_1 = 67
204190
"""The AC reactive energy in phase 1."""
205191

206-
AC_ENERGY_REACTIVE_PHASE_2 = metrics_pb2.METRIC_AC_ENERGY_REACTIVE_PHASE_2
192+
AC_ENERGY_REACTIVE_PHASE_2 = 68
207193
"""The AC reactive energy in phase 2."""
208194

209-
AC_ENERGY_REACTIVE_PHASE_3 = metrics_pb2.METRIC_AC_ENERGY_REACTIVE_PHASE_3
195+
AC_ENERGY_REACTIVE_PHASE_3 = 69
210196
"""The AC reactive energy in phase 3."""
211197

212-
AC_TOTAL_HARMONIC_DISTORTION_CURRENT = (
213-
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT
214-
)
198+
AC_TOTAL_HARMONIC_DISTORTION_CURRENT = 80
215199
"""The AC total harmonic distortion current."""
216200

217-
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_1 = (
218-
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_1
219-
)
201+
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_1 = 81
220202
"""The AC total harmonic distortion current in phase 1."""
221203

222-
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_2 = (
223-
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_2
224-
)
204+
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_2 = 82
225205
"""The AC total harmonic distortion current in phase 2."""
226206

227-
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_3 = (
228-
metrics_pb2.METRIC_AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_3
229-
)
207+
AC_TOTAL_HARMONIC_DISTORTION_CURRENT_PHASE_3 = 83
230208
"""The AC total harmonic distortion current in phase 3."""
231209

232-
BATTERY_CAPACITY = metrics_pb2.METRIC_BATTERY_CAPACITY
210+
BATTERY_CAPACITY = 100
233211
"""The capacity of the battery."""
234212

235-
BATTERY_SOC_PCT = metrics_pb2.METRIC_BATTERY_SOC_PCT
213+
BATTERY_SOC_PCT = 101
236214
"""The state of charge of the battery as a percentage."""
237215

238-
BATTERY_TEMPERATURE = metrics_pb2.METRIC_BATTERY_TEMPERATURE
216+
BATTERY_TEMPERATURE = 102
239217
"""The temperature of the battery."""
240218

241-
INVERTER_TEMPERATURE = metrics_pb2.METRIC_INVERTER_TEMPERATURE
219+
INVERTER_TEMPERATURE = 120
242220
"""The temperature of the inverter."""
243221

244-
INVERTER_TEMPERATURE_CABINET = metrics_pb2.METRIC_INVERTER_TEMPERATURE_CABINET
222+
INVERTER_TEMPERATURE_CABINET = 121
245223
"""The temperature of the inverter cabinet."""
246224

247-
INVERTER_TEMPERATURE_HEATSINK = metrics_pb2.METRIC_INVERTER_TEMPERATURE_HEATSINK
225+
INVERTER_TEMPERATURE_HEATSINK = 122
248226
"""The temperature of the inverter heatsink."""
249227

250-
INVERTER_TEMPERATURE_TRANSFORMER = (
251-
metrics_pb2.METRIC_INVERTER_TEMPERATURE_TRANSFORMER
252-
)
228+
INVERTER_TEMPERATURE_TRANSFORMER = 123
253229
"""The temperature of the inverter transformer."""
254230

255-
EV_CHARGER_TEMPERATURE = metrics_pb2.METRIC_EV_CHARGER_TEMPERATURE
231+
EV_CHARGER_TEMPERATURE = 140
256232
"""The temperature of the EV charger."""
257233

258-
SENSOR_WIND_SPEED = metrics_pb2.METRIC_SENSOR_WIND_SPEED
234+
SENSOR_WIND_SPEED = 160
259235
"""The speed of the wind measured."""
260236

261-
SENSOR_WIND_DIRECTION = metrics_pb2.METRIC_SENSOR_WIND_DIRECTION
237+
SENSOR_WIND_DIRECTION = 161
262238
"""The direction of the wind measured."""
263239

264-
SENSOR_TEMPERATURE = metrics_pb2.METRIC_SENSOR_TEMPERATURE
240+
SENSOR_TEMPERATURE = 162
265241
"""The temperature measured."""
266242

267-
SENSOR_RELATIVE_HUMIDITY = metrics_pb2.METRIC_SENSOR_RELATIVE_HUMIDITY
243+
SENSOR_RELATIVE_HUMIDITY = 163
268244
"""The relative humidity measured."""
269245

270-
SENSOR_DEW_POINT = metrics_pb2.METRIC_SENSOR_DEW_POINT
246+
SENSOR_DEW_POINT = 164
271247
"""The dew point measured."""
272248

273-
SENSOR_AIR_PRESSURE = metrics_pb2.METRIC_SENSOR_AIR_PRESSURE
249+
SENSOR_AIR_PRESSURE = 165
274250
"""The air pressure measured."""
275251

276-
SENSOR_IRRADIANCE = metrics_pb2.METRIC_SENSOR_IRRADIANCE
252+
SENSOR_IRRADIANCE = 166
277253
"""The irradiance measured."""

0 commit comments

Comments
 (0)