File tree Expand file tree Collapse file tree 4 files changed +11
-1
lines changed
custom_components/powercalc Expand file tree Collapse file tree 4 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 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 ,
3233 DOMAIN_CONFIG ,
3334 ENTRY_GLOBAL_CONFIG_UNIQUE_ID ,
3435 CalculationStrategy ,
36+ GroupType ,
3537 SensorType ,
3638)
3739from 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
Original file line number Diff line number Diff line change 3535DATA_SENSOR_TYPES : Literal ["sensor_types" ] = "sensor_types"
3636DATA_CONFIG_TYPES : Literal ["config_types" ] = "config_types"
3737DATA_SOURCE_DOMAINS : Literal ["source_domains" ] = "source_domains"
38+ DATA_GROUP_TYPES : Literal ["group_types" ] = "group_types"
3839DATA_STRATEGIES : Literal ["strategies" ] = "strategies"
3940DATA_GROUP_SIZES : Literal ["group_sizes" ] = "group_sizes"
4041DATA_HAS_GROUP_INCLUDE : Literal ["has_group_include" ] = "has_group_include"
Original file line number Diff line number Diff line change 33from homeassistant .helpers .entity import Entity
44from 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
78from custom_components .powercalc .errors import SensorConfigurationError
89import custom_components .powercalc .sensors .group .custom as custom_group
910import 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 ,
Original file line number Diff line number Diff line change 2323 DOMAIN_CONFIG ,
2424 SERVICE_RELOAD ,
2525 CalculationStrategy ,
26+ GroupType ,
2627 SensorType ,
2728)
2829from 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 }
You can’t perform that action at this time.
0 commit comments