Skip to content

Commit 7744a24

Browse files
committed
0.2.1: shorten external statistic name
The full Greek address was making the Energy Dashboard 'Add consumption' dropdown unreadable. Use 'EAC <last4 of spId> <channel_type>' instead. Users who want a more memorable label can rename a statistic from Settings, Long-term statistics. Drops the address argument from import_cumulative_history; sp_id and channel_type are enough.
1 parent 2544242 commit 7744a24

4 files changed

Lines changed: 12 additions & 28 deletions

File tree

custom_components/eac_cyprus/coordinator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ async def _async_update_data(self) -> EacData:
138138
sp.id,
139139
ch.id,
140140
ch.type,
141-
sp.address,
142141
matching.readings,
143142
)
144143

custom_components/eac_cyprus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"iot_class": "cloud_polling",
1010
"issue_tracker": "https://github.com/SantaFox/ha-eac/issues",
1111
"requirements": ["eac-dso-portal==0.2.1"],
12-
"version": "0.2.0"
12+
"version": "0.2.1"
1313
}

custom_components/eac_cyprus/statistics.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def import_cumulative_history(
5959
sp_id: str,
6060
channel_id: str,
6161
channel_name: str,
62-
address: str,
6362
readings: tuple[Reading, ...],
6463
) -> None:
6564
"""Push readings for one cumulative kWh channel as hourly external stats."""
@@ -74,10 +73,12 @@ def import_cumulative_history(
7473
return
7574

7675
statistic_id = external_statistic_id(sp_id, channel_id)
77-
# Build a name the user will see in Energy Dashboard's 'Add consumption'
78-
# dropdown. Mention the address so users with multiple service points
79-
# can tell them apart.
80-
pretty_name = f"EAC {address} {channel_name}" if address else f"EAC {channel_name}"
76+
# Short name for the Energy Dashboard 'Add consumption' dropdown.
77+
# The last four digits of the service-point id disambiguate setups
78+
# with multiple service points without dragging the full address
79+
# in. The user can always rename a statistic from Settings,
80+
# Long-term statistics if they want something more memorable.
81+
pretty_name = f"EAC {sp_id[-4:]} {channel_name}"
8182

8283
metadata: StatisticMetaData = {
8384
"has_mean": False,

tests/test_statistics.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def test_no_op_when_no_cumulative_readings(hass: HomeAssistant) -> None:
5353
"custom_components.eac_cyprus.statistics.async_add_external_statistics"
5454
) as mock_add:
5555
import_cumulative_history(
56-
hass, "111", "mc-30min", "KWH-30MIN-LP-IMP", "1 Test St", interval_only
56+
hass, "111", "mc-30min", "KWH-30MIN-LP-IMP", interval_only
5757
)
5858
mock_add.assert_not_called()
5959

@@ -72,19 +72,18 @@ async def test_imports_cumulative_kwh_with_correct_metadata(
7272
"custom_components.eac_cyprus.statistics.async_add_external_statistics"
7373
) as mock_add:
7474
import_cumulative_history(
75-
hass, "111", "mc-total", "S-KWH-24H", "1 Test St", rdgs
75+
hass, "863224497404", "mc-total", "S-KWH-24H", rdgs
7676
)
7777

7878
mock_add.assert_called_once()
7979
_, metadata, stats = mock_add.call_args.args
80-
assert metadata["statistic_id"] == "eac_cyprus:111_mc-total"
80+
assert metadata["statistic_id"] == "eac_cyprus:863224497404_mc-total"
8181
assert metadata["source"] == DOMAIN
8282
assert metadata["has_sum"] is True
8383
assert metadata["has_mean"] is False
8484
assert metadata["unit_of_measurement"] == UnitOfEnergy.KILO_WATT_HOUR
85-
assert "EAC" in metadata["name"]
86-
assert "1 Test St" in metadata["name"]
87-
assert "S-KWH-24H" in metadata["name"]
85+
# Short name: integration tag, last four of sp id, channel type.
86+
assert metadata["name"] == "EAC 7404 S-KWH-24H"
8887

8988
assert len(stats) == 3
9089
for s, expected_reading in zip(stats, [2900.0, 2924.0, 2950.0], strict=True):
@@ -95,17 +94,6 @@ async def test_imports_cumulative_kwh_with_correct_metadata(
9594
assert "state" not in s
9695

9796

98-
async def test_imports_work_without_known_address(hass: HomeAssistant) -> None:
99-
"""When the service point has no address yet, the name still makes sense."""
100-
rdgs = _readings(("2026-05-01T00:00:00", 100.0, 5.0))
101-
with patch(
102-
"custom_components.eac_cyprus.statistics.async_add_external_statistics"
103-
) as mock_add:
104-
import_cumulative_history(hass, "111", "mc-x", "S-KWH-24H", "", rdgs)
105-
metadata = mock_add.call_args.args[1]
106-
assert metadata["name"] == "EAC S-KWH-24H"
107-
108-
10997
async def test_coordinator_pushes_stats_for_cumulative_channel_only(
11098
hass: HomeAssistant, mock_client
11199
) -> None:
@@ -124,7 +112,3 @@ async def test_coordinator_pushes_stats_for_cumulative_channel_only(
124112
]
125113
assert "mc-total-24h" in called_channels
126114
assert "mc-30min-imp" not in called_channels
127-
# The address is passed through so the metadata name is meaningful.
128-
for c in mock_import.call_args_list:
129-
# signature: (hass, sp_id, channel_id, channel_name, address, readings)
130-
assert c.args[4] == "1 Test St, City"

0 commit comments

Comments
 (0)