Skip to content

Commit 3b5acfd

Browse files
authored
Merge pull request #3794 from bramstroker/feat/group-types-analytics
Add group type counts to analytics
2 parents c4992ad + 48782f9 commit 3b5acfd

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

custom_components/powercalc/analytics/analytics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
DATA_ANALYTICS,
2424
DATA_CONFIG_TYPES,
2525
DATA_GROUP_SIZES,
26+
DATA_GROUP_TYPES,
2627
DATA_HAS_GROUP_INCLUDE,
2728
DATA_POWER_PROFILES,
2829
DATA_SENSOR_TYPES,
@@ -32,6 +33,7 @@
3233
DOMAIN_CONFIG,
3334
ENTRY_GLOBAL_CONFIG_UNIQUE_ID,
3435
CalculationStrategy,
36+
GroupType,
3537
SensorType,
3638
)
3739
from custom_components.powercalc.power_profile.library import ProfileLibrary
@@ -54,6 +56,7 @@ class RuntimeAnalyticsData(TypedDict, total=False):
5456
strategies: Counter[CalculationStrategy]
5557
power_profiles: list[PowerProfile]
5658
source_domains: Counter[str]
59+
group_types: Counter[GroupType]
5760
group_sizes: list[int]
5861
uses_include: bool
5962
_seen: dict[str, set[str]]
@@ -170,6 +173,7 @@ async def _prepare_payload(self) -> dict:
170173
"by_model": Counter(f"{profile.manufacturer}:{profile.model}" for profile in power_profiles),
171174
"by_strategy": runtime_data.setdefault(DATA_STRATEGIES, Counter()),
172175
"by_source_domain": runtime_data.setdefault(DATA_SOURCE_DOMAINS, Counter()),
176+
"by_group_type": runtime_data.setdefault(DATA_GROUP_TYPES, Counter()),
173177
},
174178
}
175179

custom_components/powercalc/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
DATA_SENSOR_TYPES: Literal["sensor_types"] = "sensor_types"
3636
DATA_CONFIG_TYPES: Literal["config_types"] = "config_types"
3737
DATA_SOURCE_DOMAINS: Literal["source_domains"] = "source_domains"
38+
DATA_GROUP_TYPES: Literal["group_types"] = "group_types"
3839
DATA_STRATEGIES: Literal["strategies"] = "strategies"
3940
DATA_GROUP_SIZES: Literal["group_sizes"] = "group_sizes"
4041
DATA_HAS_GROUP_INCLUDE: Literal["has_group_include"] = "has_group_include"

custom_components/powercalc/sensors/group/factory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from homeassistant.helpers.entity import Entity
44
from homeassistant.helpers.typing import ConfigType
55

6-
from custom_components.powercalc.const import CONF_GROUP_TYPE, GroupType
6+
from custom_components.powercalc.analytics.analytics import collect_analytics
7+
from custom_components.powercalc.const import CONF_GROUP_TYPE, DATA_GROUP_TYPES, GroupType
78
from custom_components.powercalc.errors import SensorConfigurationError
89
import custom_components.powercalc.sensors.group.custom as custom_group
910
import custom_components.powercalc.sensors.group.domain as domain_group
@@ -20,6 +21,8 @@ async def create_group_sensors(
2021
) -> list[Entity]:
2122
"""Create group sensors for a given sensor configuration."""
2223
group_type: GroupType = GroupType(sensor_config.get(CONF_GROUP_TYPE, GroupType.CUSTOM))
24+
collect_analytics(hass, config_entry).inc(DATA_GROUP_TYPES, group_type)
25+
2326
if group_type == GroupType.DOMAIN:
2427
return await domain_group.create_domain_group_sensor(
2528
hass,

docs/source/misc/analytics.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ The payload only contains **aggregated counts**, for example:
2828
- total number of Powercalc entities
2929
- counts per sensor type (e.g. virtual power, group, daily energy)
3030
- counts per manufacturer and model (aggregated)
31+
- counts per device type (e.g. light, plug)
32+
- counts per calculation strategy (e.g. lut, fixed)
33+
- counts per source domain (e.g. light, switch)
34+
- counts per group type (e.g. custom, standby)
35+
- group sizes (number of entities in each group)
36+
- whether group includes are used
3137
- Powercalc version and Home Assistant version
3238

3339
No per-device identifiers are included.
@@ -53,16 +59,35 @@ No per-device identifiers are included.
5359
"by_manufacturer": {
5460
"shelly": 1,
5561
"signify": 4
62+
},
63+
"by_device_type": {
64+
"light": 4,
65+
"plug": 1
66+
},
67+
"by_strategy": {
68+
"lut": 4,
69+
"fixed": 1
70+
},
71+
"by_source_domain": {
72+
"light": 4,
73+
"switch": 1
74+
},
75+
"by_group_type": {
76+
"custom": 1,
77+
"standby": 1
5678
}
5779
},
5880
"ha_version": "2025.10.0.dev0",
5981
"install_id": "081ac191-2667-4242-8226-ecc66b1f7e9e",
60-
"group_size_max": 2,
61-
"group_size_min": 2,
82+
"group_sizes": {
83+
"2": 1,
84+
"5": 1
85+
},
6286
"powercalc_version": "0.1.1",
6387
"config_entry_count": 8,
6488
"custom_profile_count": 12,
65-
"has_global_gui_config": true
89+
"has_global_gui_config": true,
90+
"has_group_include": false
6691
}
6792
```
6893

tests/analytics/test_analytics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
DOMAIN_CONFIG,
2424
SERVICE_RELOAD,
2525
CalculationStrategy,
26+
GroupType,
2627
SensorType,
2728
)
2829
from tests.common import get_simple_fixed_config, run_powercalc_setup, setup_config_entry
@@ -240,3 +241,4 @@ async def test_group_sizes(hass: HomeAssistant) -> None:
240241
payload = await analytics._prepare_payload() # noqa: SLF001
241242

242243
assert payload["group_sizes"] == {6: 1, 10: 1}
244+
assert payload["counts"]["by_group_type"] == {GroupType.CUSTOM: 2, GroupType.STANDBY: 1}

0 commit comments

Comments
 (0)