Skip to content

Commit

Permalink
HA update #14 HACS PowerCalc update #16
Browse files Browse the repository at this point in the history
  • Loading branch information
BeardedTinker committed Jan 12, 2025
1 parent aea2f27 commit 21f2502
Show file tree
Hide file tree
Showing 35 changed files with 1,433 additions and 529 deletions.
2 changes: 1 addition & 1 deletion .HA_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2025.1.1
2025.1.2
26 changes: 19 additions & 7 deletions custom_components/powercalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@
CONF_UTILITY_METER_OFFSET,
CONF_UTILITY_METER_TARIFFS,
CONF_UTILITY_METER_TYPES,
DATA_CALCULATOR_FACTORY,
DATA_CONFIGURED_ENTITIES,
DATA_DISCOVERY_MANAGER,
DATA_DOMAIN_ENTITIES,
DATA_ENTITIES,
DATA_GROUP_ENTITIES,
DATA_STANDBY_POWER_SENSORS,
DATA_USED_UNIQUE_IDS,
DEFAULT_ENERGY_INTEGRATION_METHOD,
Expand All @@ -85,6 +86,7 @@
ENTRY_GLOBAL_CONFIG_UNIQUE_ID,
MIN_HA_VERSION,
SERVICE_CHANGE_GUI_CONFIGURATION,
SERVICE_UPDATE_LIBRARY,
PowercalcDiscoveryType,
SensorType,
UnitPrefix,
Expand All @@ -97,7 +99,6 @@
remove_power_sensor_from_associated_groups,
)
from .service.gui_configuration import SERVICE_SCHEMA, change_gui_configuration
from .strategy.factory import PowerCalculatorStrategyFactory

PLATFORMS = [Platform.SENSOR]

Expand Down Expand Up @@ -213,19 +214,20 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:

discovery_manager = DiscoveryManager(hass, config)
hass.data[DOMAIN] = {
DATA_CALCULATOR_FACTORY: PowerCalculatorStrategyFactory(hass),
DATA_DISCOVERY_MANAGER: DiscoveryManager(hass, config),
DATA_DISCOVERY_MANAGER: discovery_manager,
DOMAIN_CONFIG: global_config,
DATA_CONFIGURED_ENTITIES: {},
DATA_DOMAIN_ENTITIES: {},
DATA_GROUP_ENTITIES: {},
DATA_ENTITIES: {},
DATA_USED_UNIQUE_IDS: [],
DATA_STANDBY_POWER_SENSORS: {},
}

await hass.async_add_executor_job(register_services, hass)

if global_config.get(CONF_ENABLE_AUTODISCOVERY):
await discovery_manager.start_discovery()
await discovery_manager.setup()

await setup_yaml_sensors(hass, config, global_config)

Expand Down Expand Up @@ -284,16 +286,26 @@ def get_global_gui_configuration(config_entry: ConfigEntry) -> ConfigType:
def register_services(hass: HomeAssistant) -> None:
"""Register generic services"""

async def handle_service(call: ServiceCall) -> None:
async def _handle_change_gui_service(call: ServiceCall) -> None:
await change_gui_configuration(hass, call)

hass.services.register(
DOMAIN,
SERVICE_CHANGE_GUI_CONFIGURATION,
handle_service,
_handle_change_gui_service,
schema=SERVICE_SCHEMA,
)

async def _handle_update_library_service(_: ServiceCall) -> None:
discovery_manager: DiscoveryManager = hass.data[DOMAIN][DATA_DISCOVERY_MANAGER]
await discovery_manager.update_library_and_rediscover()

hass.services.register(
DOMAIN,
SERVICE_UPDATE_LIBRARY,
_handle_update_library_service,
)


def setup_standby_group(hass: HomeAssistant, domain_config: ConfigType) -> None:
async def _create_standby_group(event: None) -> None:
Expand Down
Loading

0 comments on commit 21f2502

Please sign in to comment.