Skip to content

Commit 6d255b2

Browse files
johanzanderclaude
andauthored
Add state_class to Growatt power and energy sensors (#158705)
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent 5ffb39f commit 6d255b2

File tree

4 files changed

+163
-32
lines changed

4 files changed

+163
-32
lines changed

homeassistant/components/growatt_server/sensor/mix.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
api_key="eBatChargeToday",
2828
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
2929
device_class=SensorDeviceClass.ENERGY,
30+
state_class=SensorStateClass.TOTAL_INCREASING,
3031
),
3132
GrowattSensorEntityDescription(
3233
key="mix_battery_charge_lifetime",
@@ -42,6 +43,7 @@
4243
api_key="eBatDisChargeToday",
4344
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
4445
device_class=SensorDeviceClass.ENERGY,
46+
state_class=SensorStateClass.TOTAL_INCREASING,
4547
),
4648
GrowattSensorEntityDescription(
4749
key="mix_battery_discharge_lifetime",
@@ -57,6 +59,7 @@
5759
api_key="epvToday",
5860
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
5961
device_class=SensorDeviceClass.ENERGY,
62+
state_class=SensorStateClass.TOTAL_INCREASING,
6063
),
6164
GrowattSensorEntityDescription(
6265
key="mix_solar_generation_lifetime",
@@ -72,6 +75,7 @@
7275
api_key="pDischarge1",
7376
native_unit_of_measurement=UnitOfPower.WATT,
7477
device_class=SensorDeviceClass.POWER,
78+
state_class=SensorStateClass.MEASUREMENT,
7579
),
7680
GrowattSensorEntityDescription(
7781
key="mix_battery_voltage",
@@ -101,6 +105,7 @@
101105
api_key="elocalLoadToday",
102106
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
103107
device_class=SensorDeviceClass.ENERGY,
108+
state_class=SensorStateClass.TOTAL_INCREASING,
104109
),
105110
GrowattSensorEntityDescription(
106111
key="mix_load_consumption_lifetime",
@@ -116,6 +121,7 @@
116121
api_key="etoGridToday",
117122
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
118123
device_class=SensorDeviceClass.ENERGY,
124+
state_class=SensorStateClass.TOTAL_INCREASING,
119125
),
120126
GrowattSensorEntityDescription(
121127
key="mix_export_to_grid_lifetime",
@@ -132,55 +138,63 @@
132138
api_key="chargePower",
133139
native_unit_of_measurement=UnitOfPower.KILO_WATT,
134140
device_class=SensorDeviceClass.POWER,
141+
state_class=SensorStateClass.MEASUREMENT,
135142
),
136143
GrowattSensorEntityDescription(
137144
key="mix_load_consumption",
138145
translation_key="mix_load_consumption",
139146
api_key="pLocalLoad",
140147
native_unit_of_measurement=UnitOfPower.KILO_WATT,
141148
device_class=SensorDeviceClass.POWER,
149+
state_class=SensorStateClass.MEASUREMENT,
142150
),
143151
GrowattSensorEntityDescription(
144152
key="mix_wattage_pv_1",
145153
translation_key="mix_wattage_pv_1",
146154
api_key="pPv1",
147155
native_unit_of_measurement=UnitOfPower.KILO_WATT,
148156
device_class=SensorDeviceClass.POWER,
157+
state_class=SensorStateClass.MEASUREMENT,
149158
),
150159
GrowattSensorEntityDescription(
151160
key="mix_wattage_pv_2",
152161
translation_key="mix_wattage_pv_2",
153162
api_key="pPv2",
154163
native_unit_of_measurement=UnitOfPower.KILO_WATT,
155164
device_class=SensorDeviceClass.POWER,
165+
state_class=SensorStateClass.MEASUREMENT,
156166
),
157167
GrowattSensorEntityDescription(
158168
key="mix_wattage_pv_all",
159169
translation_key="mix_wattage_pv_all",
160170
api_key="ppv",
161171
native_unit_of_measurement=UnitOfPower.KILO_WATT,
162172
device_class=SensorDeviceClass.POWER,
173+
state_class=SensorStateClass.MEASUREMENT,
163174
),
164175
GrowattSensorEntityDescription(
165176
key="mix_export_to_grid",
166177
translation_key="mix_export_to_grid",
167178
api_key="pactogrid",
168179
native_unit_of_measurement=UnitOfPower.KILO_WATT,
169180
device_class=SensorDeviceClass.POWER,
181+
state_class=SensorStateClass.MEASUREMENT,
170182
),
171183
GrowattSensorEntityDescription(
172184
key="mix_import_from_grid",
173185
translation_key="mix_import_from_grid",
174186
api_key="pactouser",
175187
native_unit_of_measurement=UnitOfPower.KILO_WATT,
176188
device_class=SensorDeviceClass.POWER,
189+
state_class=SensorStateClass.MEASUREMENT,
177190
),
178191
GrowattSensorEntityDescription(
179192
key="mix_battery_discharge_kw",
180193
translation_key="mix_battery_discharge_kw",
181194
api_key="pdisCharge1",
182195
native_unit_of_measurement=UnitOfPower.KILO_WATT,
183196
device_class=SensorDeviceClass.POWER,
197+
state_class=SensorStateClass.MEASUREMENT,
184198
),
185199
GrowattSensorEntityDescription(
186200
key="mix_grid_voltage",
@@ -196,34 +210,39 @@
196210
api_key="eCharge",
197211
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
198212
device_class=SensorDeviceClass.ENERGY,
213+
state_class=SensorStateClass.TOTAL_INCREASING,
199214
),
200215
GrowattSensorEntityDescription(
201216
key="mix_load_consumption_solar_today",
202217
translation_key="mix_load_consumption_solar_today",
203218
api_key="eChargeToday",
204219
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
205220
device_class=SensorDeviceClass.ENERGY,
221+
state_class=SensorStateClass.TOTAL_INCREASING,
206222
),
207223
GrowattSensorEntityDescription(
208224
key="mix_self_consumption_today",
209225
translation_key="mix_self_consumption_today",
210226
api_key="eChargeToday1",
211227
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
212228
device_class=SensorDeviceClass.ENERGY,
229+
state_class=SensorStateClass.TOTAL_INCREASING,
213230
),
214231
GrowattSensorEntityDescription(
215232
key="mix_load_consumption_battery_today",
216233
translation_key="mix_load_consumption_battery_today",
217234
api_key="echarge1",
218235
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
219236
device_class=SensorDeviceClass.ENERGY,
237+
state_class=SensorStateClass.TOTAL_INCREASING,
220238
),
221239
GrowattSensorEntityDescription(
222240
key="mix_import_from_grid_today",
223241
translation_key="mix_import_from_grid_today",
224242
api_key="etouser",
225243
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
226244
device_class=SensorDeviceClass.ENERGY,
245+
state_class=SensorStateClass.TOTAL_INCREASING,
227246
),
228247
# This sensor is manually created using the most recent X-Axis value from the chartData
229248
GrowattSensorEntityDescription(

homeassistant/components/growatt_server/sensor/tlx.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
api_key="ppv1",
8080
native_unit_of_measurement=UnitOfPower.WATT,
8181
device_class=SensorDeviceClass.POWER,
82+
state_class=SensorStateClass.MEASUREMENT,
8283
precision=1,
8384
),
8485
GrowattSensorEntityDescription(
@@ -122,6 +123,7 @@
122123
api_key="ppv2",
123124
native_unit_of_measurement=UnitOfPower.WATT,
124125
device_class=SensorDeviceClass.POWER,
126+
state_class=SensorStateClass.MEASUREMENT,
125127
precision=1,
126128
),
127129
GrowattSensorEntityDescription(
@@ -165,6 +167,7 @@
165167
api_key="ppv3",
166168
native_unit_of_measurement=UnitOfPower.WATT,
167169
device_class=SensorDeviceClass.POWER,
170+
state_class=SensorStateClass.MEASUREMENT,
168171
precision=1,
169172
),
170173
GrowattSensorEntityDescription(
@@ -208,6 +211,7 @@
208211
api_key="ppv4",
209212
native_unit_of_measurement=UnitOfPower.WATT,
210213
device_class=SensorDeviceClass.POWER,
214+
state_class=SensorStateClass.MEASUREMENT,
211215
precision=1,
212216
),
213217
GrowattSensorEntityDescription(
@@ -234,6 +238,7 @@
234238
api_key="ppv",
235239
native_unit_of_measurement=UnitOfPower.WATT,
236240
device_class=SensorDeviceClass.POWER,
241+
state_class=SensorStateClass.MEASUREMENT,
237242
precision=1,
238243
),
239244
GrowattSensorEntityDescription(
@@ -258,6 +263,7 @@
258263
api_key="pac",
259264
native_unit_of_measurement=UnitOfPower.WATT,
260265
device_class=SensorDeviceClass.POWER,
266+
state_class=SensorStateClass.MEASUREMENT,
261267
precision=1,
262268
),
263269
GrowattSensorEntityDescription(
@@ -323,6 +329,7 @@
323329
api_key="bdc1DischargePower",
324330
native_unit_of_measurement=UnitOfPower.WATT,
325331
device_class=SensorDeviceClass.POWER,
332+
state_class=SensorStateClass.MEASUREMENT,
326333
),
327334
GrowattSensorEntityDescription(
328335
key="tlx_battery_1_discharge_total",
@@ -339,6 +346,7 @@
339346
api_key="bdc2DischargePower",
340347
native_unit_of_measurement=UnitOfPower.WATT,
341348
device_class=SensorDeviceClass.POWER,
349+
state_class=SensorStateClass.MEASUREMENT,
342350
),
343351
GrowattSensorEntityDescription(
344352
key="tlx_battery_2_discharge_total",
@@ -372,6 +380,7 @@
372380
api_key="bdc1ChargePower",
373381
native_unit_of_measurement=UnitOfPower.WATT,
374382
device_class=SensorDeviceClass.POWER,
383+
state_class=SensorStateClass.MEASUREMENT,
375384
),
376385
GrowattSensorEntityDescription(
377386
key="tlx_battery_1_charge_total",
@@ -388,6 +397,7 @@
388397
api_key="bdc2ChargePower",
389398
native_unit_of_measurement=UnitOfPower.WATT,
390399
device_class=SensorDeviceClass.POWER,
400+
state_class=SensorStateClass.MEASUREMENT,
391401
),
392402
GrowattSensorEntityDescription(
393403
key="tlx_battery_2_charge_total",
@@ -445,6 +455,7 @@
445455
api_key="pacToLocalLoad",
446456
native_unit_of_measurement=UnitOfPower.WATT,
447457
device_class=SensorDeviceClass.POWER,
458+
state_class=SensorStateClass.MEASUREMENT,
448459
precision=1,
449460
),
450461
GrowattSensorEntityDescription(
@@ -453,6 +464,7 @@
453464
api_key="pacToUserTotal",
454465
native_unit_of_measurement=UnitOfPower.WATT,
455466
device_class=SensorDeviceClass.POWER,
467+
state_class=SensorStateClass.MEASUREMENT,
456468
precision=1,
457469
),
458470
GrowattSensorEntityDescription(
@@ -461,6 +473,7 @@
461473
api_key="pacToGridTotal",
462474
native_unit_of_measurement=UnitOfPower.WATT,
463475
device_class=SensorDeviceClass.POWER,
476+
state_class=SensorStateClass.MEASUREMENT,
464477
precision=1,
465478
),
466479
GrowattSensorEntityDescription(
@@ -545,6 +558,7 @@
545558
api_key="psystem",
546559
native_unit_of_measurement=UnitOfPower.WATT,
547560
device_class=SensorDeviceClass.POWER,
561+
state_class=SensorStateClass.MEASUREMENT,
548562
precision=1,
549563
),
550564
GrowattSensorEntityDescription(
@@ -553,6 +567,7 @@
553567
api_key="pself",
554568
native_unit_of_measurement=UnitOfPower.WATT,
555569
device_class=SensorDeviceClass.POWER,
570+
state_class=SensorStateClass.MEASUREMENT,
556571
precision=1,
557572
),
558573
)

homeassistant/components/growatt_server/sensor/total.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@
5050
api_key="nominalPower",
5151
native_unit_of_measurement=UnitOfPower.WATT,
5252
device_class=SensorDeviceClass.POWER,
53+
state_class=SensorStateClass.MEASUREMENT,
5354
),
5455
)

0 commit comments

Comments
 (0)