Skip to content

Commit 1dcd490

Browse files
committed
Fix entity IDs: use unique prefixed keys per appliance type
1 parent 5562914 commit 1dcd490

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

custom_components/gridx/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "gridx",
33
"name": "gridX Energy Management",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"integration_type": "hub",
66
"config_flow": true,
77
"iot_class": "cloud_polling",

custom_components/gridx/sensor.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
218218

219219
BATTERY_SENSOR_DESCRIPTIONS: tuple[GridxApplianceSensorDescription, ...] = (
220220
GridxApplianceSensorDescription(
221-
key="state_of_charge",
221+
key="battery_state_of_charge",
222222
translation_key="battery_state_of_charge",
223223
native_unit_of_measurement=PERCENTAGE,
224224
device_class=SensorDeviceClass.BATTERY,
@@ -227,7 +227,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
227227
value_fn=lambda b: round(b.state_of_charge * 100, 10),
228228
),
229229
GridxApplianceSensorDescription(
230-
key="power",
230+
key="battery_power",
231231
translation_key="battery_power",
232232
native_unit_of_measurement=UnitOfPower.WATT,
233233
device_class=SensorDeviceClass.POWER,
@@ -236,7 +236,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
236236
value_fn=lambda b: b.power,
237237
),
238238
GridxApplianceSensorDescription(
239-
key="charge",
239+
key="battery_charge",
240240
translation_key="battery_charge",
241241
native_unit_of_measurement=UnitOfPower.WATT,
242242
device_class=SensorDeviceClass.POWER,
@@ -245,7 +245,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
245245
value_fn=lambda b: b.charge,
246246
),
247247
GridxApplianceSensorDescription(
248-
key="discharge",
248+
key="battery_discharge",
249249
translation_key="battery_discharge",
250250
native_unit_of_measurement=UnitOfPower.WATT,
251251
device_class=SensorDeviceClass.POWER,
@@ -254,7 +254,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
254254
value_fn=lambda b: b.discharge,
255255
),
256256
GridxApplianceSensorDescription(
257-
key="remaining_charge",
257+
key="battery_remaining_charge",
258258
translation_key="battery_remaining_charge",
259259
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
260260
device_class=SensorDeviceClass.ENERGY_STORAGE,
@@ -263,7 +263,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
263263
value_fn=lambda b: b.remaining_charge,
264264
),
265265
GridxApplianceSensorDescription(
266-
key="capacity",
266+
key="battery_capacity",
267267
translation_key="battery_capacity",
268268
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
269269
device_class=SensorDeviceClass.ENERGY_STORAGE,
@@ -273,7 +273,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
273273
value_fn=lambda b: b.capacity,
274274
),
275275
GridxApplianceSensorDescription(
276-
key="nominal_capacity",
276+
key="battery_nominal_capacity",
277277
translation_key="battery_nominal_capacity",
278278
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
279279
device_class=SensorDeviceClass.ENERGY_STORAGE,
@@ -290,7 +290,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
290290

291291
HEAT_PUMP_SENSOR_DESCRIPTIONS: tuple[GridxApplianceSensorDescription, ...] = (
292292
GridxApplianceSensorDescription(
293-
key="power",
293+
key="heat_pump_power",
294294
translation_key="heat_pump_power",
295295
native_unit_of_measurement=UnitOfPower.WATT,
296296
device_class=SensorDeviceClass.POWER,
@@ -299,7 +299,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
299299
value_fn=lambda hp: hp.power,
300300
),
301301
GridxApplianceSensorDescription(
302-
key="sg_ready_state",
302+
key="heat_pump_sg_ready_state",
303303
translation_key="heat_pump_sg_ready_state",
304304
native_unit_of_measurement=None,
305305
device_class=SensorDeviceClass.ENUM,
@@ -315,7 +315,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
315315

316316
EV_CHARGER_SENSOR_DESCRIPTIONS: tuple[GridxApplianceSensorDescription, ...] = (
317317
GridxApplianceSensorDescription(
318-
key="power",
318+
key="ev_charger_power",
319319
translation_key="ev_charger_power",
320320
native_unit_of_measurement=UnitOfPower.WATT,
321321
device_class=SensorDeviceClass.POWER,
@@ -324,7 +324,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
324324
value_fn=lambda ev: ev.power,
325325
),
326326
GridxApplianceSensorDescription(
327-
key="state_of_charge",
327+
key="ev_charger_state_of_charge",
328328
translation_key="ev_charger_state_of_charge",
329329
native_unit_of_measurement=PERCENTAGE,
330330
device_class=SensorDeviceClass.BATTERY,
@@ -333,7 +333,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
333333
value_fn=lambda ev: round(ev.state_of_charge * 100, 10),
334334
),
335335
GridxApplianceSensorDescription(
336-
key="current_l1",
336+
key="ev_charger_current_l1",
337337
translation_key="ev_charger_current_l1",
338338
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
339339
device_class=SensorDeviceClass.CURRENT,
@@ -342,7 +342,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
342342
value_fn=lambda ev: ev.current_l1,
343343
),
344344
GridxApplianceSensorDescription(
345-
key="current_l2",
345+
key="ev_charger_current_l2",
346346
translation_key="ev_charger_current_l2",
347347
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
348348
device_class=SensorDeviceClass.CURRENT,
@@ -351,7 +351,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
351351
value_fn=lambda ev: ev.current_l2,
352352
),
353353
GridxApplianceSensorDescription(
354-
key="current_l3",
354+
key="ev_charger_current_l3",
355355
translation_key="ev_charger_current_l3",
356356
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
357357
device_class=SensorDeviceClass.CURRENT,
@@ -360,7 +360,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
360360
value_fn=lambda ev: ev.current_l3,
361361
),
362362
GridxApplianceSensorDescription(
363-
key="reading_total",
363+
key="ev_charger_reading_total",
364364
translation_key="ev_charger_reading_total",
365365
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
366366
device_class=SensorDeviceClass.ENERGY,
@@ -376,7 +376,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
376376

377377
HEATER_SENSOR_DESCRIPTIONS: tuple[GridxApplianceSensorDescription, ...] = (
378378
GridxApplianceSensorDescription(
379-
key="power",
379+
key="heater_power",
380380
translation_key="heater_power",
381381
native_unit_of_measurement=UnitOfPower.WATT,
382382
device_class=SensorDeviceClass.POWER,
@@ -385,7 +385,7 @@ class GridxApplianceSensorDescription(SensorEntityDescription):
385385
value_fn=lambda h: h.power,
386386
),
387387
GridxApplianceSensorDescription(
388-
key="temperature",
388+
key="heater_temperature",
389389
translation_key="heater_temperature",
390390
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
391391
device_class=SensorDeviceClass.TEMPERATURE,

tests/components/gridx/test_sensor.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ def test_battery_sensor_value_extraction(self):
148148
desc_map = {d.key: d for d in BATTERY_SENSOR_DESCRIPTIONS}
149149

150150
# state_of_charge is multiplied by 100
151-
assert desc_map["state_of_charge"].value_fn(battery) == pytest.approx(75.0)
152-
assert desc_map["power"].value_fn(battery) == pytest.approx(1000.0)
153-
assert desc_map["charge"].value_fn(battery) == pytest.approx(200.0)
154-
assert desc_map["discharge"].value_fn(battery) == pytest.approx(0.0)
155-
assert desc_map["remaining_charge"].value_fn(battery) == pytest.approx(11000.0)
156-
assert desc_map["capacity"].value_fn(battery) == pytest.approx(15000.0)
157-
assert desc_map["nominal_capacity"].value_fn(battery) == pytest.approx(15000.0)
151+
assert desc_map["battery_state_of_charge"].value_fn(battery) == pytest.approx(75.0)
152+
assert desc_map["battery_power"].value_fn(battery) == pytest.approx(1000.0)
153+
assert desc_map["battery_charge"].value_fn(battery) == pytest.approx(200.0)
154+
assert desc_map["battery_discharge"].value_fn(battery) == pytest.approx(0.0)
155+
assert desc_map["battery_remaining_charge"].value_fn(battery) == pytest.approx(11000.0)
156+
assert desc_map["battery_capacity"].value_fn(battery) == pytest.approx(15000.0)
157+
assert desc_map["battery_nominal_capacity"].value_fn(battery) == pytest.approx(15000.0)
158158

159159
def test_battery_descriptions_count(self):
160160
"""There are exactly 7 battery sensor descriptions."""
@@ -175,8 +175,8 @@ def test_heat_pump_sg_ready_state(self):
175175
(_, _, HEAT_PUMP_SENSOR_DESCRIPTIONS, _, _) = _get_descriptions()
176176
desc_map = {d.key: d for d in HEAT_PUMP_SENSOR_DESCRIPTIONS}
177177

178-
assert desc_map["sg_ready_state"].value_fn(hp) == "BOOST"
179-
assert desc_map["power"].value_fn(hp) == pytest.approx(500.0)
178+
assert desc_map["heat_pump_sg_ready_state"].value_fn(hp) == "BOOST"
179+
assert desc_map["heat_pump_power"].value_fn(hp) == pytest.approx(500.0)
180180

181181
def test_heat_pump_descriptions_count(self):
182182
"""There are exactly 2 heat pump sensor descriptions."""
@@ -205,13 +205,13 @@ def test_ev_charger_sensor_value_extraction(self):
205205
(_, _, _, EV_CHARGER_SENSOR_DESCRIPTIONS, _) = _get_descriptions()
206206
desc_map = {d.key: d for d in EV_CHARGER_SENSOR_DESCRIPTIONS}
207207

208-
assert desc_map["power"].value_fn(ev) == pytest.approx(7000.0)
208+
assert desc_map["ev_charger_power"].value_fn(ev) == pytest.approx(7000.0)
209209
# state_of_charge is multiplied by 100
210-
assert desc_map["state_of_charge"].value_fn(ev) == pytest.approx(45.0)
211-
assert desc_map["current_l1"].value_fn(ev) == pytest.approx(10.5)
212-
assert desc_map["current_l2"].value_fn(ev) == pytest.approx(10.3)
213-
assert desc_map["current_l3"].value_fn(ev) == pytest.approx(10.4)
214-
assert desc_map["reading_total"].value_fn(ev) == pytest.approx(123.456)
210+
assert desc_map["ev_charger_state_of_charge"].value_fn(ev) == pytest.approx(45.0)
211+
assert desc_map["ev_charger_current_l1"].value_fn(ev) == pytest.approx(10.5)
212+
assert desc_map["ev_charger_current_l2"].value_fn(ev) == pytest.approx(10.3)
213+
assert desc_map["ev_charger_current_l3"].value_fn(ev) == pytest.approx(10.4)
214+
assert desc_map["ev_charger_reading_total"].value_fn(ev) == pytest.approx(123.456)
215215

216216
def test_ev_charger_descriptions_count(self):
217217
"""There are exactly 6 EV charger sensor descriptions."""
@@ -232,8 +232,8 @@ def test_heater_sensor_value_extraction(self):
232232
(_, _, _, _, HEATER_SENSOR_DESCRIPTIONS) = _get_descriptions()
233233
desc_map = {d.key: d for d in HEATER_SENSOR_DESCRIPTIONS}
234234

235-
assert desc_map["power"].value_fn(heater) == pytest.approx(2000.0)
236-
assert desc_map["temperature"].value_fn(heater) == pytest.approx(65.5)
235+
assert desc_map["heater_power"].value_fn(heater) == pytest.approx(2000.0)
236+
assert desc_map["heater_temperature"].value_fn(heater) == pytest.approx(65.5)
237237

238238
def test_heater_descriptions_count(self):
239239
"""There are exactly 2 heater sensor descriptions."""
@@ -280,8 +280,8 @@ def test_diagnostic_entities_have_category(self):
280280
(_, BATTERY_SENSOR_DESCRIPTIONS, _, _, _) = _get_descriptions()
281281
desc_map = {d.key: d for d in BATTERY_SENSOR_DESCRIPTIONS}
282282

283-
assert desc_map["capacity"].entity_category == EntityCategory.DIAGNOSTIC
284-
assert desc_map["nominal_capacity"].entity_category == EntityCategory.DIAGNOSTIC
283+
assert desc_map["battery_capacity"].entity_category == EntityCategory.DIAGNOSTIC
284+
assert desc_map["battery_nominal_capacity"].entity_category == EntityCategory.DIAGNOSTIC
285285

286286
def test_non_diagnostic_battery_sensors(self):
287287
"""power, charge, discharge etc. must NOT have DIAGNOSTIC category."""
@@ -291,11 +291,11 @@ def test_non_diagnostic_battery_sensors(self):
291291
desc_map = {d.key: d for d in BATTERY_SENSOR_DESCRIPTIONS}
292292

293293
for key in (
294-
"state_of_charge",
295-
"power",
296-
"charge",
297-
"discharge",
298-
"remaining_charge",
294+
"battery_state_of_charge",
295+
"battery_power",
296+
"battery_charge",
297+
"battery_discharge",
298+
"battery_remaining_charge",
299299
):
300300
assert desc_map[key].entity_category != EntityCategory.DIAGNOSTIC, (
301301
f"{key} should not be DIAGNOSTIC"

0 commit comments

Comments
 (0)