def register_update_services(entity_cls: Type['MESEntity'], platform: EntityPlatform, log_prefix: str = '') -> None: update_function_names = get_update_function_names(entity_cls) if update_function_names: _LOGGER.debug( log_prefix + f'Registering {len(update_function_names)} update services') for update_function_name in update_function_names: service_name = update_function_name if service_name.endswith('_all'): service_name = service_name[:-4] if service_name.startswith('async_'): service_name = service_name[6:] _LOGGER.info( log_prefix + f'Registering update service "{service_name}" -> "{update_function_name}"' ) platform.async_register_entity_service( service_name, {}, update_function_name, ) else: _LOGGER.debug(log_prefix + 'No update services found')
def register_platform_services(platform: entity_platform.EntityPlatform) -> None: platform.async_register_entity_service(SERVICE_ENABLE, ENTITY_SCHEMA, async_enable) platform.async_register_entity_service( SERVICE_DISABLE, ENTITY_SCHEMA, async_disable ) platform.async_register_entity_service(SERVICE_TOGGLE, ENTITY_SCHEMA, async_toggle) platform.async_register_entity_service(SERVICE_CANCEL, ENTITY_SCHEMA, async_cancel) platform.async_register_entity_service( SERVICE_TIME_ADJUST, TIME_ADJUST_SCHEMA, async_time_adjust ) platform.async_register_entity_service( SERVICE_MANUAL_RUN, MANUAL_RUN_SCHEMA, async_manual_run ) return
async def async_discover_meters( current_entity_platform: EntityPlatform, config_entry: ConfigEntry, final_config: ConfigType, accounts: Iterable[BaseAccount], ) -> DiscoveryReturnType: """Meters discovery""" meter_lists = await asyncio.gather(*map(lambda account: account.get_meters(), accounts)) meters = [] for meter_list in meter_lists: meters.extend(meter_list) if current_entity_platform is None: current_entity_platform = entity_platform.current_platform.get() entities, tasks = await _common_discover_entities( current_entity_platform=current_entity_platform, config_entry=config_entry, final_config=final_config, source_objects=meters, object_code_getter=lambda x: x.meter_code, entity_code_getter=lambda x: x.meter.meter_code, entity_cls=MESMeterSensor, ) if entities: current_entity_platform.async_register_entity_service( SERVICE_CALCULATE_INDICATIONS, SERVICE_CALCULATE_INDICATIONS_SCHEMA, "async_calculate_indications" ) current_entity_platform.async_register_entity_service( SERVICE_PUSH_INDICATIONS, SERVICE_PUSH_INDICATIONS_PAYLOAD_SCHEMA, "async_push_indications" ) return entities, tasks
def register_platform_services(platform: entity_platform.EntityPlatform) -> None: platform.async_register_entity_service( SERVICE_ENABLE, ENTITY_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_DISABLE, ENTITY_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_TOGGLE, ENTITY_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_CANCEL, ENTITY_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_TIME_ADJUST, TIME_ADJUST_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_MANUAL_RUN, MANUAL_RUN_SCHEMA, async_entity_service_handler ) return
def register_platform_services(platform: entity_platform.EntityPlatform) -> None: """Register all the available service calls for the intities""" platform.async_register_entity_service( SERVICE_ENABLE, ENABLE_DISABLE_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_DISABLE, ENABLE_DISABLE_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_TOGGLE, ENABLE_DISABLE_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_CANCEL, ENTITY_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_TIME_ADJUST, TIME_ADJUST_SCHEMA, async_entity_service_handler ) platform.async_register_entity_service( SERVICE_MANUAL_RUN, MANUAL_RUN_SCHEMA, async_entity_service_handler )